1 from django
import template
3 register
= template
.Library()
5 def prepopulated_fields_js(context
):
7 Creates a list of prepopulated_fields that should render Javascript for
8 the prepopulated fields for both the admin form and inlines.
10 prepopulated_fields
= []
11 if context
['add'] and 'adminform' in context
:
12 prepopulated_fields
.extend(context
['adminform'].prepopulated_fields
)
13 if 'inline_admin_formsets' in context
:
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 context
.update({'prepopulated_fields': prepopulated_fields
})
20 prepopulated_fields_js
= register
.inclusion_tag('admin/prepopulated_fields_js.html', takes_context
=True)(prepopulated_fields_js
)
22 def submit_row(context
):
24 Displays the row of buttons for delete and save.
26 opts
= context
['opts']
27 change
= context
['change']
28 is_popup
= context
['is_popup']
29 save_as
= context
['save_as']
31 'onclick_attrib': (opts
.get_ordered_objects() and change
32 and 'onclick="submitOrderForm();"' or ''),
33 'show_delete_link': (not is_popup
and context
['has_delete_permission']
34 and (change
or context
['show_delete'])),
35 'show_save_as_new': not is_popup
and change
and save_as
,
36 'show_save_and_add_another': context
['has_add_permission'] and
37 not is_popup
and (not save_as
or context
['add']),
38 'show_save_and_continue': not is_popup
and context
['has_change_permission'],
42 submit_row
= register
.inclusion_tag('admin/submit_line.html', takes_context
=True)(submit_row
)