Hello site
[auf_framonde.git] / eggs / Django-1.4.5-py2.7.egg / django / contrib / admin / templatetags / admin_modify.py
1 from django import template
2
3 register = template.Library()
4
5 @register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)
6 def prepopulated_fields_js(context):
7 """
8 Creates a list of prepopulated_fields that should render Javascript for
9 the prepopulated fields for both the admin form and inlines.
10 """
11 prepopulated_fields = []
12 if context['add'] and 'adminform' in context:
13 prepopulated_fields.extend(context['adminform'].prepopulated_fields)
14 if 'inline_admin_formsets' in context:
15 for inline_admin_formset in context['inline_admin_formsets']:
16 for inline_admin_form in inline_admin_formset:
17 if inline_admin_form.original is None:
18 prepopulated_fields.extend(inline_admin_form.prepopulated_fields)
19 context.update({'prepopulated_fields': prepopulated_fields})
20 return context
21
22 @register.inclusion_tag('admin/submit_line.html', takes_context=True)
23 def submit_row(context):
24 """
25 Displays the row of buttons for delete and save.
26 """
27 opts = context['opts']
28 change = context['change']
29 is_popup = context['is_popup']
30 save_as = context['save_as']
31 return {
32 'onclick_attrib': (opts.get_ordered_objects() and change
33 and 'onclick="submitOrderForm();"' or ''),
34 'show_delete_link': (not is_popup and context['has_delete_permission']
35 and (change or context['show_delete'])),
36 'show_save_as_new': not is_popup and change and save_as,
37 'show_save_and_add_another': context['has_add_permission'] and
38 not is_popup and (not save_as or context['add']),
39 'show_save_and_continue': not is_popup and context['has_change_permission'],
40 'is_popup': is_popup,
41 'show_save': True
42 }
43
44 @register.filter
45 def cell_count(inline_admin_form):
46 """Returns the number of cells used in a tabular inline"""
47 count = 1 # Hidden cell with hidden 'id' field
48 for fieldset in inline_admin_form:
49 # Loop through all the fields (one per cell)
50 for line in fieldset:
51 for field in line:
52 count += 1
53 if inline_admin_form.formset.can_delete:
54 # Delete checkbox
55 count += 1
56 return count