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.
master
Brandon Taylor 2015-12-21 14:11:13 -05:00
parent ba9e477f2f
commit 698ca136d5
5 changed files with 41 additions and 20 deletions

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/iambrandontaylor/django-admin-sortable.svg?branch=master)](https://travis-ci.org/iambrandontaylor/django-admin-sortable)
Current version: 2.0.7
Current version: 2.0.8
This project makes it easy to add drag-and-drop ordering to any model in
Django admin. Inlines for a sortable model may also be made sortable,
@ -457,8 +457,11 @@ ordering on top of that just seemed a little much in my opinion.
django-admin-sortable is currently used in production.
### What's new in 2.0.7?
- Minor enhancement to determine which element to highlight on sortable stacked inlines when all fieldsets are set to collapse.
### What's new in 2.0.8?
- Refactored admin url patterns to be compatible with Django 1.8 or higher.
- Refactored import paths on generics in `sample_project` to be compatible with Django 1.9.
- Fixed typo in documentation.
- Updated unit tests for get_next/previous.
### Future

View File

@ -1,4 +1,4 @@
VERSION = (2, 0, 7) # following PEP 386
VERSION = (2, 0, 8) # following PEP 386
DEV_N = None

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):

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)

View File

@ -1,4 +1,10 @@
from django.contrib.contenttypes import generic
from django import VERSION
if VERSION < (1, 9):
from django.contrib.contenttypes.generic import GenericForeignKey
else:
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@ -109,7 +115,7 @@ class GenericNote(SimpleModel, SortableMixin):
content_type = models.ForeignKey(ContentType,
verbose_name=u"Content type", related_name="generic_notes")
object_id = models.PositiveIntegerField(u"Content id")
content_object = generic.GenericForeignKey(ct_field='content_type',
content_object = GenericForeignKey(ct_field='content_type',
fk_field='object_id')
order = models.PositiveIntegerField(default=0, editable=False)