object_edit.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. <div id="form_fields" hx-disinherit="hx-select hx-swap">
  54. {% block form %}
  55. {% include 'htmx/form.html' %}
  56. {% endblock form %}
  57. </div>
  58. <div class="btn-float-group-right">
  59. {% block buttons %}
  60. <a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
  61. {% if object.pk %}
  62. <button type="submit" name="_update" class="btn btn-primary">
  63. {% trans "Save" %}
  64. </button>
  65. {% else %}
  66. <div class="btn-group" role="group" aria-label="{% trans "Actions" %}">
  67. <button type="submit" name="_create" class="btn btn-primary">
  68. {% trans "Create" %}
  69. </button>
  70. <button type="submit" name="_addanother" class="btn btn-outline-primary btn-float">
  71. {% trans "Create & Add Another" %}
  72. </button>
  73. </div>
  74. {% endif %}
  75. {% endblock buttons %}
  76. </div>
  77. </form>
  78. </div>
  79. {% endblock content %}
  80. {% block modals %}
  81. {% include 'inc/htmx_modal.html' with size='lg' %}
  82. {% endblock %}