PageRenderTime 162ms CodeModel.GetById 14ms RepoModel.GetById 2ms app.codeStats 0ms

/django/contrib/admin/templates/mako/admin/edit_inline/tabular.html

https://code.google.com/p/mango-py/
HTML | 149 lines | 141 code | 8 blank | 0 comment | 0 complexity | bcadb38ce75dcc7b14dbffe2e4ef9bd2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <%def name="inline_edit(inline_admin_formset, formset_count)">
  2. <%namespace name="admin" module="django.contrib.admin.templatetags.adminmedia" />
  3. <div class="inline-group" id="${ inline_admin_formset.formset.prefix }-group">
  4. <div class="tabular inline-related${' last-related' if formset_count==0 else ''}">
  5. <%!
  6. # filter to titlecase text
  7. def title(text):
  8. return text.title()
  9. %>
  10. ${inline_admin_formset.formset.management_form}
  11. <fieldset class="module">
  12. <h2>${ inline_admin_formset.opts.verbose_name_plural|title,h }</h2>
  13. ${inline_admin_formset.formset.non_form_errors()}
  14. <table>
  15. <thead><tr>
  16. % for i, field in enumerate(inline_admin_formset.fields()):
  17. % if not field.widget.is_hidden:
  18. <th ${ 'colspan="2"' if i==0 else '' }${' class="required"' if field.required else '' }>${ capfirst(field.label) if field.label else "" }</th>
  19. % endif
  20. % endfor
  21. % if inline_admin_formset.formset.can_delete:
  22. <th>${trans("Delete?")}</th>
  23. % endif
  24. </tr></thead>
  25. <tbody>
  26. <%
  27. inline_admin_formset_list = [X for X in inline_admin_formset]
  28. %>
  29. % for row,inline_admin_form in enumerate(inline_admin_formset_list):
  30. % if inline_admin_form.form.non_field_errors():
  31. <tr><td colspan="${ inline_admin_form.field_count() }">${ inline_admin_form.form.non_field_errors() }</td></tr>
  32. % endif
  33. <tr class="${ "row1" if row % 2 == 0 else "row2" } ${'has_original' if inline_admin_form.original or inline_admin_form.show_url else ''} ${'empty-form' if row==len(inline_admin_formset_list)-1 else ''}"
  34. id="${ inline_admin_formset.formset.prefix }-${ row if row!=len(inline_admin_formset_list)-1 else 'empty'}">
  35. <td class="original">
  36. % if inline_admin_form.show_url:
  37. <p>
  38. <a href="../../../r/${inline_admin_form.original.content_type_id}/${inline_admin_form.original.id}/">${trans("View on site")}</a>
  39. </p>
  40. % endif
  41. ${inline_admin_form.pk_field().field}
  42. % for fieldset in inline_admin_form:
  43. % for line in fieldset:
  44. % for field in line:
  45. % if hasattr(field.field, "is_hidden") and field.field.is_hidden:
  46. ${field.field}
  47. % endif
  48. % endfor
  49. % endfor
  50. % endfor
  51. </td>
  52. % for fieldset in inline_admin_form:
  53. % for line in fieldset:
  54. % for field in line:
  55. <td class="${field.field.name}">
  56. % if hasattr(field,'is_readonly') and field.is_readonly:
  57. <p>${ field.contents }</p>
  58. % else:
  59. ${ field.field.errors.as_ul() }
  60. ${ field.field }
  61. % endif
  62. </td>
  63. % endfor
  64. % endfor
  65. % endfor
  66. % if inline_admin_formset.formset.can_delete:
  67. <td class="delete">
  68. % if inline_admin_form.original:
  69. ${inline_admin_form.deletion_field().field.as_widget()}
  70. % endif
  71. </td>
  72. % endif
  73. </tr>
  74. % endfor
  75. </tbody>
  76. </table>
  77. </fieldset>
  78. </div>
  79. </div>
  80. <script type="text/javascript">
  81. (function($) {
  82. $(document).ready(function($) {
  83. var rows = "#${ inline_admin_formset.formset.prefix }-group .tabular.inline-related tbody tr";
  84. var alternatingRows = function(row) {
  85. $(rows).not(".add-row").removeClass("row1 row2")
  86. .filter(":even").addClass("row1").end()
  87. .filter(rows + ":odd").addClass("row2");
  88. }
  89. var reinitDateTimeShortCuts = function() {
  90. // Reinitialize the calendar and clock widgets by force
  91. if (typeof DateTimeShortcuts != "undefined") {
  92. $(".datetimeshortcuts").remove();
  93. DateTimeShortcuts.init();
  94. }
  95. }
  96. var updateSelectFilter = function() {
  97. // If any SelectFilter widgets are a part of the new form,
  98. // instantiate a new SelectFilter instance for it.
  99. if (typeof SelectFilter != "undefined"){
  100. $(".selectfilter").each(function(index, value){
  101. var namearr = value.name.split('-');
  102. SelectFilter.init(value.id, namearr[namearr.length-1], false, "${ admin_media_prefix() }");
  103. })
  104. $(".selectfilterstacked").each(function(index, value){
  105. var namearr = value.name.split('-');
  106. SelectFilter.init(value.id, namearr[namearr.length-1], true, "${ admin_media_prefix() }");
  107. })
  108. }
  109. }
  110. var initPrepopulatedFields = function(row) {
  111. return;
  112. row.find('.prepopulated_field').each(function() {
  113. var field = $(this);
  114. var input = field.find('input, select, textarea');
  115. var dependency_list = input.data('dependency_list') || [];
  116. var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
  117. if (dependencies.length) {
  118. input.prepopulate(dependencies, input.attr('maxlength'));
  119. }
  120. });
  121. }
  122. $(rows).formset({
  123. prefix: "${ inline_admin_formset.formset.prefix }",
  124. addText: "Add another ${ title(inline_admin_formset.opts.verbose_name) }",
  125. numCols: "${inline_admin_form.field_count()}",
  126. formCssClass: "dynamic-${ inline_admin_formset.formset.prefix }",
  127. deleteCssClass: "inline-deletelink",
  128. deleteText: "${ trans('Remove') }",
  129. emptyCssClass: "empty-form",
  130. removed: alternatingRows,
  131. added: (function(row) {
  132. initPrepopulatedFields(row);
  133. reinitDateTimeShortCuts();
  134. updateSelectFilter();
  135. alternatingRows(row);
  136. })
  137. });
  138. });
  139. })(django.jQuery);
  140. </script>
  141. </%def>