Refactored admin url patterns to be compatible with Django 1.8 or higher.

Refactored sample_project imports to be compatible with Django 1.9
Updated unit tests for get_next/previous.
Version bump to 2.0.8.
Fixed typo in docs.
This commit is contained in:
Brandon Taylor
2015-12-21 14:11:13 -05:00
parent ba9e477f2f
commit 698ca136d5
5 changed files with 41 additions and 20 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
VERSION = (2, 0, 7) # following PEP 386
VERSION = (2, 0, 8) # following PEP 386
DEV_N = None
+24 -12
View File
@@ -4,10 +4,12 @@ from django import VERSION
from django.conf import settings
if VERSION < (1, 5):
from django.conf.urls.defaults import patterns, url
else:
if VERSION > (1, 7):
from django.conf.urls import url
elif VERSION > (1, 5):
from django.conf.urls import patterns, url
else:
from django.conf.urls.defaults import patterns, url
from django.contrib.admin import ModelAdmin, TabularInline, StackedInline
from django.contrib.admin.options import InlineModelAdmin
@@ -80,17 +82,27 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
def get_urls(self):
urls = super(SortableAdmin, self).get_urls()
admin_urls = patterns('',
# this ajax view changes the order
url(r'^sorting/do-sorting/(?P<model_type_id>\d+)/$',
self.admin_site.admin_view(self.do_sorting_view),
name='admin_do_sorting'),
# this ajax view changes the order
admin_do_sorting_url = url(r'^sorting/do-sorting/(?P<model_type_id>\d+)/$',
self.admin_site.admin_view(self.do_sorting_view),
name='admin_do_sorting')
# this view displays the sortable objects
admin_sort_url = url(r'^sort/$',
self.admin_site.admin_view(self.sort_view),
name='admin_sort')
if VERSION > (1, 7):
admin_urls = [
admin_do_sorting_url,
admin_sort_url
]
else:
admin_urls = patterns('',
admin_do_sorting_url,
admin_sort_url,)
# this view displays the sortable objects
url(r'^sort/$', self.admin_site.admin_view(self.sort_view),
name='admin_sort'),
)
return admin_urls + urls
def sort_view(self, request):
+2 -2
View File
@@ -121,12 +121,12 @@ class SortableMixin(models.Model):
def get_next(self, extra_filters={}, filter_on_sortable_fk=True):
return self._filter_objects(
{'{0}__gt'.format(self.order_field_name): self._get_order_field_value},
{'{0}__gt'.format(self.order_field_name): self._get_order_field_value()},
extra_filters, filter_on_sortable_fk)
def get_previous(self, extra_filters={}, filter_on_sortable_fk=True):
return self._filter_objects(
{'{0}__lt'.format(self.order_field_name): self._get_order_field_value},
{'{0}__lt'.format(self.order_field_name): self._get_order_field_value()},
extra_filters, filter_on_sortable_fk)