object_list.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {% extends 'base/layout.html' %}
  2. {% load buttons %}
  3. {% load helpers %}
  4. {% load render_table from django_tables2 %}
  5. {% load static %}
  6. {% comment %}
  7. Blocks:
  8. extra_controls: Additional action buttons
  9. bulk_buttons: Additional bulk action buttons to display beneath the objects
  10. list
  11. Context:
  12. model: The model class being listed
  13. table: The table class used for rendering the list of objects
  14. actions: A list of buttons to display. This template checks for add, import,
  15. export, bulk_edit, and bulk_delete.
  16. filter_form: The bound filterset form for filtering the objects list (optional)
  17. return_url: Return URL to use for bulk actions (optional)
  18. {% endcomment %}
  19. {% block title %}{{ model|meta:"verbose_name_plural"|bettertitle }}{% endblock %}
  20. {% block controls %}
  21. <div class="controls">
  22. <div class="control-group">
  23. {% block extra_controls %}{% endblock %}
  24. {% if 'add' in actions %}
  25. {% add_button model %}
  26. {% endif %}
  27. {% if 'import' in actions %}
  28. {% import_button model %}
  29. {% endif %}
  30. {% if 'export' in actions %}
  31. {% export_button model %}
  32. {% endif %}
  33. </div>
  34. </div>
  35. {% endblock controls %}
  36. {% block tabs %}
  37. <ul class="nav nav-tabs px-3">
  38. <li class="nav-item" role="presentation">
  39. <button 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">
  40. Results {% badge table.page.paginator.count %}
  41. </button>
  42. </li>
  43. {% if filter_form %}
  44. <li class="nav-item" role="presentation">
  45. <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">
  46. Filters
  47. {% if filter_form %}{% badge filter_form.changed_data|length bg_color="primary" %}{% endif %}
  48. </button>
  49. </li>
  50. {% endif %}
  51. </ul>
  52. {% endblock tabs %}
  53. {% block content-wrapper %}
  54. <div class="tab-content">
  55. {# Object list #}
  56. <div class="tab-pane show active" id="object-list" role="tabpanel" aria-labelledby="object-list-tab">
  57. {# Applied filters #}
  58. {% if filter_form %}
  59. {% applied_filters filter_form request.GET %}
  60. {% endif %}
  61. {# "Select all" form #}
  62. {% if table.paginator.num_pages > 1 %}
  63. <div id="select-all-box" class="d-none card noprint">
  64. <form method="post" class="form col-md-12">
  65. {% csrf_token %}
  66. <div class="card-body">
  67. <div class="float-end">
  68. {% if 'bulk_edit' in actions %}
  69. {% bulk_edit_button model query_params=request.GET %}
  70. {% endif %}
  71. {% if 'bulk_delete' in actions %}
  72. {% bulk_delete_button model query_params=request.GET %}
  73. {% endif %}
  74. </div>
  75. <div class="form-check">
  76. <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
  77. <label for="select-all" class="form-check-label">
  78. Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query
  79. </label>
  80. </div>
  81. </div>
  82. </form>
  83. </div>
  84. {% endif %}
  85. {# Object table controls #}
  86. {% include 'inc/table_controls_htmx.html' with table_modal="ObjectTable_config" %}
  87. <form method="post" class="form form-horizontal">
  88. {% csrf_token %}
  89. <input type="hidden" name="return_url" value="{% if return_url %}{{ return_url }}{% else %}{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}{% endif %}" />
  90. {# Object table #}
  91. {% if required_model %}
  92. {% include 'inc/missing_prerequisites.html' %}
  93. {% endif %}
  94. <div class="card">
  95. <div class="card-body" id="object_list">
  96. {% include 'htmx/table.html' %}
  97. </div>
  98. </div>
  99. {# Form buttons #}
  100. <div class="noprint bulk-buttons">
  101. <div class="bulk-button-group">
  102. {% block bulk_buttons %}
  103. {% if 'bulk_edit' in actions %}
  104. {% bulk_edit_button model query_params=request.GET %}
  105. {% endif %}
  106. {% if 'bulk_delete' in actions %}
  107. {% bulk_delete_button model query_params=request.GET %}
  108. {% endif %}
  109. {% endblock %}
  110. </div>
  111. </div>
  112. </form>
  113. </div>
  114. {# Filter form #}
  115. {% if filter_form %}
  116. <div class="tab-pane show" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
  117. {% include 'inc/filter_list.html' %}
  118. </div>
  119. {% endif %}
  120. </div>
  121. {% endblock content-wrapper %}
  122. {% block modals %}
  123. {% table_config_form table table_name="ObjectTable" %}
  124. {% endblock modals %}