mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Backwards incompatible: django-mptt removal.
Removal of django-mptt and therefor the removal of a tree based snippet list, due to performance reasons with large snippet counts. Snippets still have a 'parent' relation if it's an answer of another snippet, however this is no longer a Nested Set. The UI is simplified too and the user can now only compare an answer to it's parent snippet. I believe this is the major use case anyway.
This commit is contained in:
parent
a6982b7414
commit
ae27acf1f9
8 changed files with 52 additions and 69 deletions
31
dpaste/migrations/0002_auto_20170119_1038.py
Normal file
31
dpaste/migrations/0002_auto_20170119_1038.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.5 on 2017-01-19 10:38
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dpaste', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='snippet',
|
||||||
|
name='level',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='snippet',
|
||||||
|
name='lft',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='snippet',
|
||||||
|
name='rght',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='snippet',
|
||||||
|
name='tree_id',
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,6 +1,5 @@
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
|
|
||||||
import mptt
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -62,10 +61,6 @@ class Snippet(models.Model):
|
||||||
return remaining > 0 and remaining or 0
|
return remaining > 0 and remaining or 0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def is_single(self):
|
|
||||||
return self.is_root_node() and not self.get_children()
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.secret_id:
|
if not self.secret_id:
|
||||||
self.secret_id = generate_secret_id()
|
self.secret_id = generate_secret_id()
|
||||||
|
@ -76,5 +71,3 @@ class Snippet(models.Model):
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.secret_id
|
return self.secret_id
|
||||||
|
|
||||||
mptt.register(Snippet, order_insertion_by=['content'])
|
|
||||||
|
|
|
@ -114,7 +114,6 @@ TEMPLATES = [
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'mptt',
|
|
||||||
'gunicorn',
|
'gunicorn',
|
||||||
'dpaste',
|
'dpaste',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% extends "dpaste/base.html" %}
|
{% extends "dpaste/base.html" %}
|
||||||
|
|
||||||
{% load mptt_tags %}
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load dpaste_tags %}
|
{% load dpaste_tags %}
|
||||||
|
|
||||||
|
@ -21,34 +20,9 @@
|
||||||
======================================================================= -->
|
======================================================================= -->
|
||||||
<div id="snippet-diff" class="snippet-diff container-fluid">
|
<div id="snippet-diff" class="snippet-diff container-fluid">
|
||||||
<div class="row-fluid" style="width: auto; padding: 30px 0">
|
<div class="row-fluid" style="width: auto; padding: 30px 0">
|
||||||
<div class="span9">
|
<div class="span12">
|
||||||
<div id="diff" style="display:none;"></div>
|
<div id="diff" style="display:none;"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span3">
|
|
||||||
<form method="get" id="diffform" action="{% url "snippet_diff" %}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="tree">
|
|
||||||
{% for tree_item,structure in tree|tree_info %}
|
|
||||||
{% if structure.new_level %}<ul><li>{% else %}</li><li>{% endif %}
|
|
||||||
<div>
|
|
||||||
<span class="diff">
|
|
||||||
<input type="radio" name="a" value="{{ tree_item.id }}" {% ifequal tree_item.id snippet.parent_id %}checked="checked"{% endifequal %}>
|
|
||||||
<input type="radio" name="b" value="{{ tree_item.id }}" {% ifequal snippet tree_item %}checked="checked"{% endifequal %}>
|
|
||||||
</span>
|
|
||||||
{% ifequal snippet tree_item %}
|
|
||||||
<strong>#{{ tree_item.id }}</strong>
|
|
||||||
{% else %}
|
|
||||||
<a href="{{ tree_item.get_absolute_url }}">#{{ tree_item.id }}</a>
|
|
||||||
{% endifequal %}
|
|
||||||
</div>
|
|
||||||
{% for level in structure.closed_levels %}</li></ul>{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
<div class="submit">
|
|
||||||
<input type="submit" value="{% trans "Compare" %}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -68,8 +42,8 @@
|
||||||
{% if snippet.pk|in_list:request.session.snippet_list %}
|
{% if snippet.pk|in_list:request.session.snippet_list %}
|
||||||
<a class="btn" href="{% url "snippet_delete" snippet.secret_id %}" onclick="return confirm('{% trans "Really delete this snippet?" %}');"><i class="icon-trash"></i> {% trans "Delete Now" %}</a>
|
<a class="btn" href="{% url "snippet_delete" snippet.secret_id %}" onclick="return confirm('{% trans "Really delete this snippet?" %}');"><i class="icon-trash"></i> {% trans "Delete Now" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not snippet.is_single %}
|
{% if snippet.parent %}
|
||||||
<a class="btn snippet-diff-trigger" href="#snippet-diff"><i class="icon-search"></i> {% trans "Compare Snippets" %}</a>
|
<a class="btn snippet-diff-trigger" href="#snippet-diff"><i class="icon-search"></i> {% trans "Compare this Answer" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if snippet.expire_type != 3 %}
|
{% if snippet.expire_type != 3 %}
|
||||||
<a class="btn" href="{% url "snippet_details_raw" snippet.secret_id %}"><i class="icon-align-left"></i> {% trans "View Raw" %}</a>
|
<a class="btn" href="{% url "snippet_details_raw" snippet.secret_id %}"><i class="icon-align-left"></i> {% trans "View Raw" %}</a>
|
||||||
|
@ -125,21 +99,15 @@ jQuery(function($) {
|
||||||
$(this).removeClass('snippet-reply-hidden');
|
$(this).removeClass('snippet-reply-hidden');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var curLine = document.location.hash;
|
||||||
|
|
||||||
|
{% if snippet.parent %}
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
Diff Ajax Call
|
Diff Ajax Call
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
var diffReq;
|
function fetchDiff() {
|
||||||
|
var a = {{ snippet.parent.pk }},
|
||||||
$('.snippet-diff-trigger').click(function(e) {
|
b = {{ snippet.pk }};
|
||||||
e.preventDefault();
|
|
||||||
$('#snippet-diff').slideDown('fast');
|
|
||||||
$('#snippet-diff form').submit();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('#diffform').submit(function() {
|
|
||||||
var a = $('input[name="a"]:checked').val(),
|
|
||||||
b = $('input[name="b"]:checked').val();
|
|
||||||
|
|
||||||
window.location.hash = 'D' + a + ',' + b;
|
window.location.hash = 'D' + a + ',' + b;
|
||||||
|
|
||||||
|
@ -156,23 +124,20 @@ jQuery(function($) {
|
||||||
}).complete(function() {
|
}).complete(function() {
|
||||||
diffReq = null;
|
diffReq = null;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
var diffReq;
|
||||||
|
$('.snippet-diff-trigger').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
fetchDiff();
|
||||||
|
$('#snippet-diff').slideDown('fast');
|
||||||
});
|
});
|
||||||
|
|
||||||
var curLine = document.location.hash,
|
|
||||||
hashlist;
|
|
||||||
|
|
||||||
if (curLine.substring(0, 2) === '#D') {
|
if (curLine.substring(0, 2) === '#D') {
|
||||||
hashlist = curLine.substring(2).split(',');
|
fetchDiff();
|
||||||
if (hashlist.length === 2) {
|
|
||||||
console.log(hashlist);
|
|
||||||
$('#diffform input[name="a"][value="' + hashlist[0] + '"]').prop('checked', true);
|
|
||||||
$('#diffform input[name="b"][value="' + hashlist[1] + '"]').prop('checked', true);
|
|
||||||
$('#snippet-diff').slideDown('fast');
|
$('#snippet-diff').slideDown('fast');
|
||||||
$('#snippet-diff form').submit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
Line Highlighting
|
Line Highlighting
|
||||||
|
@ -201,7 +166,7 @@ jQuery(function($) {
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
Line Highlighting
|
Wordwrap
|
||||||
------------------------------------------------------------------------ */
|
------------------------------------------------------------------------ */
|
||||||
$('#toggleWordwrap').click(function(e){
|
$('#toggleWordwrap').click(function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
<h4>
|
<h4>
|
||||||
{% blocktrans with fileA.get_absolute_url as filea_url and fileB.get_absolute_url as fileb_url and fileA.id as filea_id and fileB.id as fileb_id %}
|
{% blocktrans with fileA.get_absolute_url as filea_url and fileB.get_absolute_url as fileb_url and fileA.id as filea_id and fileB.id as fileb_id %}
|
||||||
Diff between <a href="{{ filea_url }}">#{{ filea_id }}</a> and <a href="{{ fileb_url }}">#{{ fileb_id }}</a>
|
Difference between this answer <a href="{{ fileb_url }}">#{{ fileb_id }}</a>
|
||||||
|
and the parent snippet <a href="{{ filea_url }}">#{{ filea_id }}</a>
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,6 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
|
||||||
snippet.view_count += 1
|
snippet.view_count += 1
|
||||||
snippet.save()
|
snippet.save()
|
||||||
|
|
||||||
tree = snippet.get_root()
|
|
||||||
tree = tree.get_descendants(include_self=True)
|
|
||||||
|
|
||||||
new_snippet_initial = {
|
new_snippet_initial = {
|
||||||
'content': snippet.content,
|
'content': snippet.content,
|
||||||
'lexer': snippet.lexer,
|
'lexer': snippet.lexer,
|
||||||
|
@ -92,7 +89,6 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
|
||||||
'snippet': snippet,
|
'snippet': snippet,
|
||||||
'lexers': LEXER_LIST,
|
'lexers': LEXER_LIST,
|
||||||
'lines': range(snippet.get_linecount()),
|
'lines': range(snippet.get_linecount()),
|
||||||
'tree': tree,
|
|
||||||
'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
|
'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
|
||||||
'gist': getattr(settings, 'DPASTE_ENABLE_GIST', True),
|
'gist': getattr(settings, 'DPASTE_ENABLE_GIST', True),
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ SETTINGS = {
|
||||||
'INSTALLED_APPS': [
|
'INSTALLED_APPS': [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'mptt',
|
|
||||||
'dpaste',
|
'dpaste',
|
||||||
],
|
],
|
||||||
'MIDDLEWARE_CLASSES': (
|
'MIDDLEWARE_CLASSES': (
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -50,7 +50,6 @@ setup(
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'django>=1.8',
|
'django>=1.8',
|
||||||
'django-mptt>=0.8.3',
|
|
||||||
'pygments>=1.6',
|
'pygments>=1.6',
|
||||||
'requests>=2.0.0',
|
'requests>=2.0.0',
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue