bulk_edit.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {% extends 'generic/_base.html' %}
  2. {% load helpers %}
  3. {% load form_helpers %}
  4. {% load render_table from django_tables2 %}
  5. {% load i18n %}
  6. {% comment %}
  7. Blocks:
  8. - title: Page title
  9. - tabs: Page tabs
  10. - content: Primary page content
  11. Context:
  12. - model: The model class of the objects being modified
  13. - form: The bulk edit form class
  14. - table: The table class for rendering list of objects being modified
  15. - return_url: The URL to which the user is redirected after submitting the form
  16. {% endcomment %}
  17. {% block title %}
  18. {% trans "Editing" %} {{ table.rows|length }} {{ model|meta:"verbose_name_plural"|bettertitle }}
  19. {% endblock %}
  20. {% block tabs %}
  21. <ul class="nav nav-tabs">
  22. <li class="nav-item" role="presentation">
  23. <button class="nav-link active" id="edit-form-tab" data-bs-toggle="tab" data-bs-target="#edit-form" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
  24. {% trans "Bulk Edit" %}
  25. </button>
  26. </li>
  27. <li class="nav-item" role="presentation">
  28. <button class="nav-link" id="object-list-tab" data-bs-toggle="tab" data-bs-target="#object-list" type="button" role="tab" aria-controls="object-list" aria-selected="false">
  29. {% trans "Selected Objects" %}
  30. {% badge table.rows|length %}
  31. </button>
  32. </li>
  33. </ul>
  34. {% endblock tabs %}
  35. {% block content %}
  36. {# Edit form #}
  37. <div class="tab-pane show active" id="edit-form" role="tabpanel" aria-labelledby="edit-form-tab">
  38. <form action="" method="post" class="form form-horizontal mt-5">
  39. <div id="form_fields" hx-disinherit="hx-select hx-swap">
  40. {% csrf_token %}
  41. {% if request.POST.return_url %}
  42. <input type="hidden" name="return_url" value="{{ request.POST.return_url }}" />
  43. {% endif %}
  44. {% for field in form.hidden_fields %}
  45. {{ field }}
  46. {% endfor %}
  47. {% if form.fieldsets %}
  48. {# Render grouped fields according to declared fieldsets #}
  49. {% for fieldset in form.fieldsets %}
  50. {% render_fieldset form fieldset %}
  51. {% endfor %}
  52. {# Render tag add/remove fields #}
  53. {% if form.add_tags and form.remove_tags %}
  54. <div class="field-group mb-5">
  55. <div class="row">
  56. <h2 class="col-9 offset-3">{% trans "Tags" %}</h2>
  57. </div>
  58. {% render_field form.add_tags %}
  59. {% render_field form.remove_tags %}
  60. </div>
  61. {% endif %}
  62. {# Render custom fields #}
  63. {% if form.custom_fields %}
  64. <div class="field-group mb-5">
  65. <div class="row">
  66. <h2 class="col-9 offset-3">{% trans "Custom Fields" %}</h2>
  67. </div>
  68. {% render_custom_fields form %}
  69. </div>
  70. {% endif %}
  71. {# Render comments #}
  72. {% if form.comments %}
  73. <div class="field-group mb-5">
  74. <div class="row">
  75. <h2 class="col-9 offset-3">{% trans "Comments" %}</h2>
  76. </div>
  77. {% render_field form.comments bulk_nullable=True %}
  78. </div>
  79. {% endif %}
  80. {% else %}
  81. {# Render all fields #}
  82. {% for field in form.visible_fields %}
  83. {% if field.name in form.nullable_fields %}
  84. {% render_field field bulk_nullable=True %}
  85. {% else %}
  86. {% render_field field %}
  87. {% endif %}
  88. {% endfor %}
  89. {% endif %}
  90. <div class="btn-float-group-right">
  91. <a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
  92. <button type="submit" name="_apply" class="btn btn-primary">{% trans "Apply" %}</button>
  93. </div>
  94. </div>
  95. </form>
  96. </div>
  97. {# Selected objects list #}
  98. <div class="tab-pane" id="object-list" role="tabpanel" aria-labelledby="object-list-tab">
  99. <div class="card">
  100. <div class="card-body table-responsive">
  101. {% render_table table 'inc/table.html' %}
  102. </div>
  103. </div>
  104. </div>
  105. {% endblock content %}