Modified classmethod queries that determine if a Model is sortable to only retieve one record and not use count.

Fixed jQueryUI highlight method call in success handler of ajax function when dragging stops.
Fixed missing script resource for jquery.effects.core.js
This commit is contained in:
Brandon Taylor
2011-11-16 00:48:14 -06:00
committed by Brandon Taylor
parent 638f26df27
commit 8365043e0e
77 changed files with 10917 additions and 10892 deletions
Regular → Executable
+1
View File
@@ -4,3 +4,4 @@ django_admin_sortable.egg-info
.pydevproject
*.pyc
*.pyo
.idea
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
View File
View File
View File
Regular → Executable
+23 -3
View File
@@ -3,15 +3,30 @@ from django.db import models
class Sortable(models.Model):
"""
Unfortunately, Django doesn't support using more than one AutoField in a model
or this class could be simplified.
`is_sortable` determines whether or not the Model is sortable by determining
if the last value of `order` is greater than the default of 1, which should be
present if there is only one object.
`model_type_id` returns the ContentType.id for the Model that inherits Sortable
`save` the override of save increments the last/highest value of order by 1
"""
order = models.PositiveIntegerField(editable=False, default=1, db_index=True)
class Meta:
abstract = True
ordering = ['order', 'id']
ordering = ['order']
@classmethod
def is_sortable(cls):
return True if cls.objects.count() > 1 else False
try:
return True if cls.objects.order_by('-order')[:1][0].order > 1 else False
except IndexError:
return False
@classmethod
def model_type_id(cls):
@@ -19,5 +34,10 @@ class Sortable(models.Model):
def save(self, *args, **kwargs):
if not self.id:
self.order = self.__class__.objects.count() + 1
try:
#increment the order field by adding one to the last value of order
self.order = self.__class__.objects.order_by('-order')[:1][0].order + 1
except IndexError:
#order defaults to 1
pass
super(Sortable, self).save(*args, **kwargs)
View File
View File
+1 -1
View File
@@ -22,7 +22,7 @@ jQuery(function($){
data: { indexes : indexes.join(',') },
success: function()
{
ui.effect('highlight');
ui.item.effect('highlight', {}, 1000);
}
});
}
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File
BIN
View File
Binary file not shown.
Regular → Executable
View File
Regular → Executable
View File
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
+1 -1
View File
@@ -34,7 +34,7 @@ class SortableTestCase(TestCase):
self.user.save()
def create_category(self, title='Category 1'):
category = Category.objects.create(title=title)
category, _ = Category.objects.get_or_create(title=title)
return category
def test_new_user_is_authenticated(self):
View File
View File
Regular → Executable
View File
View File
View File
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+1
View File
@@ -102,6 +102,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
View File
+4 -1
View File
@@ -14,7 +14,10 @@ jQuery(function($){
$.ajax({
url: ui.item.find('a.admin_sorting_url').attr('href'),
type: 'POST',
data: { indexes: indexes.join(',') }
data: { indexes: indexes.join(',') },
success: function(){
ui.item.effect('highlight', {}, 1000);
}
});
}
});
View File
View File
View File
View File
View File
View File
View File
View File
View File
Regular → Executable
View File
Regular → Executable
View File