Merge branch 'master' into develop

master
Brandon Taylor 2016-06-23 21:48:45 -04:00
commit 54482b3bb3
5 changed files with 36 additions and 34 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.15
Current version: 2.0.16
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,
@ -496,8 +496,11 @@ ordering on top of that just seemed a little much in my opinion.
### Status
django-admin-sortable is currently used in production.
### What's new in 2.0.15?
- Refactored exception handling when determining `order_field_name`
### What's new in 2.0.16?
- Simplification of admin url patterns
- Fixes for sortable lists when using Django CMS
Thanks to [@vstoykov](https://github.com/vstoykov) for both contributions.
### Future
- Better template support for foreign keys that are self referential. If someone would like to take on rendering recursive sortables, that would be super.

View File

@ -3,7 +3,7 @@ Django Admin Sortable
|Build Status|
Current version: 2.0.15
Current version: 2.0.16
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,
@ -50,7 +50,7 @@ Download django-admin-sortable from
`source <https://github.com/iambrandontaylor/django-admin-sortable/archive/master.zip>`__
1. Unzip the directory and cd into the uncompressed project directory
2.
2.
- Optional: Enable your virtualenv
@ -611,11 +611,14 @@ Status
django-admin-sortable is currently used in production.
What's new in 2.0.15?
What's new in 2.0.16?
~~~~~~~~~~~~~~~~~~~~~
- Refactored exception handling when determining ``order_field_name``
- Simplification of admin url patterns
- Fixes for sortable lists when using Django CMS
Thanks to [@vstoykov](https://github.com/vstoykov) for both
contributions.
Future
~~~~~~

View File

@ -1,6 +1,6 @@
VERSION = (2, 0, 15)
DEV_N = None
VERSION = (2, 0, 16)
DEV_N = None
def get_version():
version = '{0}.{1}'.format(VERSION[0], VERSION[1])

View File

@ -80,6 +80,22 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
class Meta:
abstract = True
@property
def has_sortable_tabular_inlines(self):
base_classes = (SortableTabularInline, SortableGenericTabularInline)
return any(issubclass(klass, base_classes) for klass in self.inlines)
@property
def has_sortable_stacked_inlines(self):
base_classes = (SortableStackedInline, SortableGenericStackedInline)
return any(issubclass(klass, base_classes) for klass in self.inlines)
@property
def change_form_template(self):
if self.has_sortable_tabular_inlines or self.has_sortable_stacked_inlines:
return self.sortable_change_form_template
return super(SortableAdmin, self).change_form_template
def get_urls(self):
urls = super(SortableAdmin, self).get_urls()
@ -224,37 +240,17 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
extra_context=extra_context)
def change_view(self, request, object_id, form_url='', extra_context=None):
self.has_sortable_tabular_inlines = False
self.has_sortable_stacked_inlines = False
if extra_context is None:
extra_context = {}
extra_context.update({
'change_form_template_extends': self.change_form_template_extends,
'has_sortable_tabular_inlines': self.has_sortable_tabular_inlines,
'has_sortable_stacked_inlines': self.has_sortable_stacked_inlines,
'csrf_cookie_name': getattr(settings, 'CSRF_COOKIE_NAME', 'csrftoken')
})
for klass in self.inlines:
if issubclass(klass, SortableTabularInline) or issubclass(klass,
SortableGenericTabularInline):
self.has_sortable_tabular_inlines = True
if issubclass(klass, SortableStackedInline) or issubclass(klass,
SortableGenericStackedInline):
self.has_sortable_stacked_inlines = True
if self.has_sortable_tabular_inlines or \
self.has_sortable_stacked_inlines:
self.change_form_template = self.sortable_change_form_template
extra_context.update({
'has_sortable_tabular_inlines':
self.has_sortable_tabular_inlines,
'has_sortable_stacked_inlines':
self.has_sortable_stacked_inlines
})
return super(SortableAdmin, self).change_view(request, object_id,
form_url='', extra_context=extra_context)

View File

@ -10,7 +10,7 @@
{% for field in line %}
<div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
{% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
{% if forloop.first %}
{% if forloop.parentloop.first %}
{% if inline_admin_form_forloop.counter <= initial_forms_count %}
<i class="fa fa-{% if inline_admin_form_forloop.first %}sort-desc{% elif inline_admin_form_forloop.counter == initial_forms_count %}sort-asc{% else %}sort{% endif %}"></i>
{% endif %}