object_list.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {% extends 'generic/_base.html' %}
  2. {% load buttons %}
  3. {% load helpers %}
  4. {% load plugins %}
  5. {% load render_table from django_tables2 %}
  6. {% load static %}
  7. {% load i18n %}
  8. {% comment %}
  9. Blocks:
  10. - title: Page title
  11. - controls: Control elements displayed between the header and content
  12. - extra_controls: Any additional action buttons to display
  13. - tabs: Page tabs
  14. - content: Primary page content
  15. - bulk_buttons: Additional bulk action buttons to display beneath the objects list
  16. - modals: Any pre-loaded modals
  17. Context:
  18. - model: The model class being listed
  19. - table: The table class used for rendering the list of objects
  20. - actions: A list of buttons to display. This template checks for add, import, export,
  21. bulk_edit, and bulk_delete.
  22. - filter_form: The bound filterset form for filtering the objects list (optional)
  23. - return_url: Return URL to use for bulk actions (optional)
  24. {% endcomment %}
  25. {% block title %}{{ model|meta:"verbose_name_plural"|bettertitle }}{% endblock %}
  26. {% block controls %}
  27. <div class="btn-list">
  28. {% plugin_list_buttons model %}
  29. {% block extra_controls %}{% endblock %}
  30. {% if 'add' in actions %}
  31. {% add_button model %}
  32. {% endif %}
  33. {% if 'import' in actions %}
  34. {% import_button model %}
  35. {% endif %}
  36. {% if 'export' in actions %}
  37. {% export_button model %}
  38. {% endif %}
  39. </div>
  40. {% endblock controls %}
  41. {% block tabs %}
  42. <ul class="nav nav-tabs" role="tablist">
  43. <li class="nav-item" role="presentation">
  44. <a class="nav-link active" id="object-list-tab" data-bs-toggle="tab" data-bs-target="#object-list" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
  45. {% trans "Results" %}
  46. <span class="badge text-bg-secondary total-object-count">{% if table.page.paginator.count %}{{ table.page.paginator.count }}{% else %}{{ total_count|default:"0" }}{% endif %}</span>
  47. </a>
  48. </li>
  49. {% if filter_form %}
  50. <li class="nav-item" role="presentation">
  51. <button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="object-list" aria-selected="false">
  52. {% trans "Filters" %}
  53. {% if filter_form %}{% badge filter_form.changed_data|length bg_color="primary" %}{% endif %}
  54. </button>
  55. </li>
  56. {% endif %}
  57. </ul>
  58. {% endblock tabs %}
  59. {% block content %}
  60. {# Object list tab #}
  61. <div class="tab-pane show active" id="object-list" role="tabpanel" aria-labelledby="object-list-tab">
  62. {# Applied filters #}
  63. {% if filter_form %}
  64. {% applied_filters model filter_form request.GET %}
  65. {% endif %}
  66. {# Object table controls #}
  67. {% include 'inc/table_controls_htmx.html' with table_modal="ObjectTable_config" %}
  68. <form method="post" class="form form-horizontal">
  69. {% csrf_token %}
  70. {# "Select all" form #}
  71. {% if table.paginator.num_pages > 1 %}
  72. <div id="select-all-box" class="d-none card d-print-none">
  73. <div class="form col-md-12">
  74. <div class="card-body">
  75. <div class="float-end">
  76. {% if 'bulk_edit' in actions %}
  77. {% bulk_edit_button model query_params=request.GET %}
  78. {% endif %}
  79. {% if 'bulk_delete' in actions %}
  80. {% bulk_delete_button model query_params=request.GET %}
  81. {% endif %}
  82. </div>
  83. <div class="form-check">
  84. <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
  85. <label for="select-all" class="form-check-label">
  86. {% blocktrans trimmed with count=table.page.paginator.count object_type_plural=table.data.verbose_name_plural %}
  87. Select <strong>all <span class="total-object-count">{{ count }}</span> {{ object_type_plural }}</strong> matching query
  88. {% endblocktrans %}
  89. </label>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. {% endif %}
  95. <div class="form form-horizontal">
  96. {% csrf_token %}
  97. <input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />
  98. {# Warn of any missing prerequisite objects #}
  99. {% if prerequisite_model %}
  100. {% include 'inc/missing_prerequisites.html' %}
  101. {% endif %}
  102. {# Objects table #}
  103. <div class="card">
  104. <div class="htmx-container table-responsive" id="object_list">
  105. {% include 'htmx/table.html' %}
  106. </div>
  107. </div>
  108. {# /Objects table #}
  109. {# Form buttons #}
  110. <div class="btn-list d-print-none mt-2">
  111. {% block bulk_buttons %}
  112. {% if 'bulk_edit' in actions %}
  113. {% bulk_edit_button model query_params=request.GET %}
  114. {% endif %}
  115. {% if 'bulk_delete' in actions %}
  116. {% bulk_delete_button model query_params=request.GET %}
  117. {% endif %}
  118. {% endblock %}
  119. </div>
  120. {# /Form buttons #}
  121. </div>
  122. </form>
  123. </div>
  124. {# /Object list tab #}
  125. {# Filters tab #}
  126. {% if filter_form %}
  127. <div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
  128. {% include 'inc/filter_list.html' %}
  129. </div>
  130. {% endif %}
  131. {# /Filters tab #}
  132. {% endblock content %}
  133. {% block modals %}
  134. {% table_config_form table table_name="ObjectTable" %}
  135. {% endblock modals %}