Templates can be overriden now.
parent
866adffd7b
commit
dfbe590767
|
|
@ -16,8 +16,16 @@ STATIC_URL = settings.STATIC_URL
|
||||||
|
|
||||||
|
|
||||||
class SortableAdmin(ModelAdmin):
|
class SortableAdmin(ModelAdmin):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
ordering = ('order', 'id')
|
ordering = ('order', 'id')
|
||||||
|
|
||||||
|
sortable_change_list_with_sort_link_template = 'adminsortable/change_list_with_sort_link.html'
|
||||||
|
sortable_change_form_template = 'adminsortable/change_form.html'
|
||||||
|
sortable_change_list_template = 'adminsortable/change_list.html'
|
||||||
|
sortable_javascript_includes_template = 'adminsortable/shared/javascript_includes.html'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
@ -118,7 +126,7 @@ class SortableAdmin(ModelAdmin):
|
||||||
'sortable_by_class_is_sortable' : sortable_by_class_is_sortable,
|
'sortable_by_class_is_sortable' : sortable_by_class_is_sortable,
|
||||||
'sortable_by_class_display_name' : sortable_by_class_display_name
|
'sortable_by_class_display_name' : sortable_by_class_display_name
|
||||||
}
|
}
|
||||||
return render(request, 'adminsortable/change_list.html', context)
|
return render(request, self.sortable_change_list_template, context)
|
||||||
|
|
||||||
def changelist_view(self, request, extra_context=None):
|
def changelist_view(self, request, extra_context=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -127,13 +135,14 @@ class SortableAdmin(ModelAdmin):
|
||||||
block to take people to the view to change the sorting.
|
block to take people to the view to change the sorting.
|
||||||
"""
|
"""
|
||||||
if self.model.is_sortable():
|
if self.model.is_sortable():
|
||||||
self.change_list_template = 'adminsortable/change_list_with_sort_link.html'
|
self.change_list_template = self.sortable_change_list_with_sort_link_template
|
||||||
return super(SortableAdmin, self).changelist_view(request, extra_context=extra_context)
|
return super(SortableAdmin, self).changelist_view(request, extra_context=extra_context)
|
||||||
|
|
||||||
def change_view(self, request, object_id, extra_context=None):
|
def change_view(self, request, object_id, extra_context=None):
|
||||||
if self.has_sortable_tabular_inlines or self.has_sortable_stacked_inlines:
|
if self.has_sortable_tabular_inlines or self.has_sortable_stacked_inlines:
|
||||||
self.change_form_template = 'adminsortable/change_form.html'
|
self.change_form_template = self.sortable_change_form_template
|
||||||
extra_context = {
|
extra_context = {
|
||||||
|
'sortable_javascript_includes_template': self.sortable_javascript_includes_template,
|
||||||
'has_sortable_tabular_inlines' : self.has_sortable_tabular_inlines,
|
'has_sortable_tabular_inlines' : self.has_sortable_tabular_inlines,
|
||||||
'has_sortable_stacked_inlines' : self.has_sortable_stacked_inlines
|
'has_sortable_stacked_inlines' : self.has_sortable_stacked_inlines
|
||||||
}
|
}
|
||||||
|
|
@ -170,8 +179,7 @@ class SortableAdmin(ModelAdmin):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
response = {'objects_sorted' : False}
|
response = {'objects_sorted' : False}
|
||||||
return HttpResponse(json.dumps(response, ensure_ascii=False),
|
return HttpResponse(json.dumps(response, ensure_ascii=False), mimetype='application/json')
|
||||||
mimetype='application/json')
|
|
||||||
|
|
||||||
|
|
||||||
class SortableInlineBase(InlineModelAdmin):
|
class SortableInlineBase(InlineModelAdmin):
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
{% url 'admin:jsi18n' as jsi18nurl %}
|
{% url 'admin:jsi18n' as jsi18nurl %}
|
||||||
|
|
||||||
{% if has_sortable_tabular_inlines or has_sortable_stacked_inlines %}
|
{% if has_sortable_tabular_inlines or has_sortable_stacked_inlines %}
|
||||||
{% include 'adminsortable/shared/javascript_includes.html' %}
|
{% include sortable_javascript_includes_template %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if has_sortable_tabular_inlines %}
|
{% if has_sortable_tabular_inlines %}
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}adminsortable/js/admin.sortable.tabular.inlines.js"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}adminsortable/js/admin.sortable.tabular.inlines.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,33 @@ from django import template
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('adminsortable/shared/objects.html', takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def render_sortable_objects(context, objects):
|
def render_sortable_objects(context, objects,
|
||||||
return {'objects' : objects}
|
sortable_objects_template='adminsortable/shared/objects.html'):
|
||||||
|
context.update({'objects': objects})
|
||||||
|
tmpl = template.loader.get_template(sortable_objects_template)
|
||||||
|
return tmpl.render(context)
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('adminsortable/shared/nested_objects.html', takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def render_nested_sortable_objects(context, objects, group_expression):
|
def render_nested_sortable_objects(context, objects, group_expression,
|
||||||
group_expression = context.get('group_expression')
|
sortable_nested_objects_template = 'adminsortable/shared/nested_objects.html'):
|
||||||
sortable_on_class = context.get('sortable_on_class')
|
context.update({'objects': objects, 'group_expression': group_expression})
|
||||||
return {'objects' : objects, 'group_expression' : group_expression,
|
tmpl = template.loader.get_template(sortable_nested_objects_template)
|
||||||
'sortable_on_class' : sortable_on_class,
|
return tmpl.render(context)
|
||||||
'sortable_by_class_is_sortable' : context.get('sortable_by_class_is_sortable')}
|
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('adminsortable/shared/list_items.html', takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def render_list_items(context, list_objects):
|
def render_list_items(context, list_objects,
|
||||||
return {'list_objects' : list_objects}
|
sortable_list_items_template='adminsortable/shared/list_items.html'):
|
||||||
|
context.update({'list_objects': list_objects})
|
||||||
|
tmpl = template.loader.get_template(sortable_list_items_template)
|
||||||
|
return tmpl.render(context)
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('adminsortable/shared/object_rep.html', takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def render_object_rep(context, object):
|
def render_object_rep(context, obj, sortable_object_rep_template='adminsortable/shared/object_rep.html'):
|
||||||
return {'object' : object}
|
context.update({'object': obj})
|
||||||
|
tmpl = template.loader.get_template(sortable_object_rep_template)
|
||||||
|
return tmpl.render(context)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue