Templates can be overriden now.
parent
866adffd7b
commit
dfbe590767
|
|
@ -16,8 +16,16 @@ STATIC_URL = settings.STATIC_URL
|
|||
|
||||
|
||||
class SortableAdmin(ModelAdmin):
|
||||
"""
|
||||
|
||||
"""
|
||||
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:
|
||||
abstract = True
|
||||
|
||||
|
|
@ -118,7 +126,7 @@ class SortableAdmin(ModelAdmin):
|
|||
'sortable_by_class_is_sortable' : sortable_by_class_is_sortable,
|
||||
'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):
|
||||
"""
|
||||
|
|
@ -127,13 +135,14 @@ class SortableAdmin(ModelAdmin):
|
|||
block to take people to the view to change the sorting.
|
||||
"""
|
||||
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)
|
||||
|
||||
def change_view(self, request, object_id, extra_context=None):
|
||||
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 = {
|
||||
'sortable_javascript_includes_template': self.sortable_javascript_includes_template,
|
||||
'has_sortable_tabular_inlines' : self.has_sortable_tabular_inlines,
|
||||
'has_sortable_stacked_inlines' : self.has_sortable_stacked_inlines
|
||||
}
|
||||
|
|
@ -170,8 +179,7 @@ class SortableAdmin(ModelAdmin):
|
|||
pass
|
||||
else:
|
||||
response = {'objects_sorted' : False}
|
||||
return HttpResponse(json.dumps(response, ensure_ascii=False),
|
||||
mimetype='application/json')
|
||||
return HttpResponse(json.dumps(response, ensure_ascii=False), mimetype='application/json')
|
||||
|
||||
|
||||
class SortableInlineBase(InlineModelAdmin):
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
{% url 'admin:jsi18n' as jsi18nurl %}
|
||||
|
||||
{% if has_sortable_tabular_inlines or has_sortable_stacked_inlines %}
|
||||
{% include 'adminsortable/shared/javascript_includes.html' %}
|
||||
{% include sortable_javascript_includes_template %}
|
||||
{% endif %}
|
||||
{% if has_sortable_tabular_inlines %}
|
||||
<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.inclusion_tag('adminsortable/shared/objects.html', takes_context=True)
|
||||
def render_sortable_objects(context, objects):
|
||||
return {'objects' : objects}
|
||||
@register.simple_tag(takes_context=True)
|
||||
def render_sortable_objects(context, 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)
|
||||
def render_nested_sortable_objects(context, objects, group_expression):
|
||||
group_expression = context.get('group_expression')
|
||||
sortable_on_class = context.get('sortable_on_class')
|
||||
return {'objects' : objects, 'group_expression' : group_expression,
|
||||
'sortable_on_class' : sortable_on_class,
|
||||
'sortable_by_class_is_sortable' : context.get('sortable_by_class_is_sortable')}
|
||||
@register.simple_tag(takes_context=True)
|
||||
def render_nested_sortable_objects(context, objects, group_expression,
|
||||
sortable_nested_objects_template = 'adminsortable/shared/nested_objects.html'):
|
||||
context.update({'objects': objects, 'group_expression': group_expression})
|
||||
tmpl = template.loader.get_template(sortable_nested_objects_template)
|
||||
return tmpl.render(context)
|
||||
|
||||
|
||||
@register.inclusion_tag('adminsortable/shared/list_items.html', takes_context=True)
|
||||
def render_list_items(context, list_objects):
|
||||
return {'list_objects' : list_objects}
|
||||
@register.simple_tag(takes_context=True)
|
||||
def render_list_items(context, 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)
|
||||
def render_object_rep(context, object):
|
||||
return {'object' : object}
|
||||
@register.simple_tag(takes_context=True)
|
||||
def render_object_rep(context, obj, sortable_object_rep_template='adminsortable/shared/object_rep.html'):
|
||||
context.update({'object': obj})
|
||||
tmpl = template.loader.get_template(sortable_object_rep_template)
|
||||
return tmpl.render(context)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue