object_edit.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {% extends 'generic/_base.html' %}
  2. {% load i18n %}
  3. {% comment %}
  4. Blocks:
  5. - title: Page title
  6. - controls: Control elements displayed between the header and content
  7. - tabs: Page tabs
  8. - content: Primary page content
  9. - form: Content within the <form> element
  10. - buttons: Form submission buttons
  11. - modals: Any pre-loaded modals
  12. Context:
  13. - object: Python instance of the object being edited
  14. - form: The edit form
  15. - return_url: The URL to which the user is redirected after submitting the form
  16. {% endcomment %}
  17. {% block title %}
  18. {% if object.pk %}
  19. {% trans "Editing" %} {{ object|meta:"verbose_name" }} {{ object }}
  20. {% else %}
  21. {% blocktrans trimmed with object_type=object|meta:"verbose_name" %}
  22. Add a new {{ object_type }}
  23. {% endblocktrans %}
  24. {% endif %}
  25. {% endblock title %}
  26. {% block controls %}
  27. <div class="btn-list">
  28. {# Link to model documentation #}
  29. {% if settings.DOCS_ROOT and object.docs_url %}
  30. <a href="{{ object.docs_url }}" target="_blank" class="btn btn-outline-secondary" title="{% trans "View model documentation" %}">
  31. <i class="mdi mdi-help-circle"></i> {% trans "Help" %}
  32. </a>
  33. {% endif %}
  34. </div>
  35. {% endblock controls %}
  36. {% block tabs %}
  37. <ul class="nav nav-tabs">
  38. <li class="nav-item" role="presentation">
  39. <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">
  40. {% if object.pk %}{% trans "Edit" %}{% else %}{% trans "Create" %}{% endif %}
  41. </button>
  42. </li>
  43. </ul>
  44. {% endblock tabs %}
  45. {% block content %}
  46. <div class="tab-pane show active" id="edit-form" role="tabpanel" aria-labelledby="object-list-tab">
  47. {# Warn about missing prerequisite objects #}
  48. {% if prerequisite_model %}
  49. {% include 'inc/missing_prerequisites.html' %}
  50. {% endif %}
  51. <form action="" method="post" enctype="multipart/form-data" class="object-edit mt-5">
  52. {% csrf_token %}
  53. {% block pre_form_fields %}{% endblock pre_form_fields %}
  54. <div id="form_fields" hx-disinherit="hx-select hx-swap">
  55. {% block form %}
  56. {% include 'htmx/form.html' %}
  57. {% endblock form %}
  58. </div>
  59. <div class="btn-float-group-right">
  60. {% block buttons %}
  61. <a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
  62. {% if object.pk %}
  63. <button type="submit" name="_update" class="btn btn-primary">
  64. {% trans "Save" %}
  65. </button>
  66. {% else %}
  67. <div class="btn-group" role="group" aria-label="{% trans "Actions" %}">
  68. <button type="submit" name="_create" class="btn btn-primary">
  69. {% trans "Create" %}
  70. </button>
  71. <button type="submit" name="_addanother" class="btn btn-outline-primary btn-float">
  72. {% trans "Create & Add Another" %}
  73. </button>
  74. </div>
  75. {% endif %}
  76. {% endblock buttons %}
  77. </div>
  78. </form>
  79. </div>
  80. {% endblock content %}
  81. {% block modals %}
  82. {% include 'inc/htmx_modal.html' with size='lg' %}
  83. {% endblock %}