PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

/django/contrib/admin/templatetags/mako/admin_modify.py

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