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