bulk_import.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {% extends 'generic/_base.html' %}
  2. {% load helpers %}
  3. {% load form_helpers %}
  4. {% load i18n %}
  5. {% comment %}
  6. Blocks:
  7. - title: Page title
  8. - tabs: Page tabs
  9. - content: Primary page content
  10. Context:
  11. - model: The model class being imported
  12. - form: The bulk import form
  13. - fields: A dictionary of form fields, to display import options (optional)
  14. - return_url: The URL to which the user is redirected after submitting the form
  15. {% endcomment %}
  16. {% block title %}{{ model|meta:"verbose_name"|bettertitle }} {% trans "Bulk Import" %}{% endblock %}
  17. {% block tabs %}
  18. <ul class="nav nav-tabs">
  19. <li class="nav-item" role="presentation">
  20. <button class="nav-link active" id="import-form-tab" data-bs-toggle="tab" data-bs-target="#import-form" data-href="#tab_import-form" type="button" role="tab" aria-controls="import-form" aria-selected="true">
  21. {% trans "Direct Import" %}
  22. </button>
  23. </li>
  24. <li class="nav-item" role="presentation">
  25. <button class="nav-link" id="upload-form-tab" data-bs-toggle="tab" data-bs-target="#upload-form" data-href="#tab_upload-form" type="button" role="tab" aria-controls="upload-form" aria-selected="false">
  26. {% trans "Upload File" %}
  27. </button>
  28. </li>
  29. <li class="nav-item" role="presentation">
  30. <button class="nav-link" id="datafile-form-tab" data-bs-toggle="tab" data-bs-target="#datafile-form" data-href="#tab_datafile-form" type="button" role="tab" aria-controls="datafile-form" aria-selected="false">
  31. {% trans "Data File" %}
  32. </button>
  33. </li>
  34. </ul>
  35. {% endblock tabs %}
  36. {% block content %}
  37. {# Data Import Form #}
  38. <div class="tab-pane show active" id="import-form" role="tabpanel" aria-labelledby="import-form-tab">
  39. <div class="row">
  40. <div class="col col-md-12 col-lg-10 offset-lg-1">
  41. <form action="" method="post" enctype="multipart/form-data" class="form">
  42. {% csrf_token %}
  43. <input type="hidden" name="import_method" value="direct" />
  44. {% render_field form.data %}
  45. {% render_field form.format %}
  46. {% render_field form.csv_delimiter %}
  47. {% render_field form.background_job %}
  48. <div class="form-group">
  49. <div class="col col-md-12 text-end">
  50. {% if return_url %}
  51. <a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
  52. {% endif %}
  53. <button type="submit" name="data_submit" class="btn btn-primary">{% trans "Submit" %}</button>
  54. </div>
  55. </div>
  56. </form>
  57. </div>
  58. </div>
  59. </div>
  60. {# File Upload Form #}
  61. <div class="tab-pane show" id="upload-form" role="tabpanel" aria-labelledby="upload-form-tab">
  62. <div class="col col-md-12 col-lg-10 offset-lg-1">
  63. <form action="" method="post" enctype="multipart/form-data" class="form">
  64. {% csrf_token %}
  65. <input type="hidden" name="import_method" value="upload" />
  66. {% render_field form.upload_file %}
  67. {% render_field form.format %}
  68. {% render_field form.csv_delimiter %}
  69. <div class="form-group">
  70. <div class="col col-md-12 text-end">
  71. {% if return_url %}
  72. <a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
  73. {% endif %}
  74. <button type="submit" name="file_submit" class="btn btn-primary">{% trans "Submit" %}</button>
  75. </div>
  76. </div>
  77. </form>
  78. </div>
  79. </div>
  80. {# DataFile Form #}
  81. <div class="tab-pane show" id="datafile-form" role="tabpanel" aria-labelledby="datafile-form-tab">
  82. <div class="col col-md-12 col-lg-10 offset-lg-1">
  83. <form action="" method="post" enctype="multipart/form-data" class="form">
  84. {% csrf_token %}
  85. <input type="hidden" name="import_method" value="datafile" />
  86. {% render_field form.data_source %}
  87. {% render_field form.data_file %}
  88. {% render_field form.format %}
  89. {% render_field form.csv_delimiter %}
  90. {% render_field form.background_job %}
  91. <div class="form-group">
  92. <div class="col col-md-12 text-end">
  93. {% if return_url %}
  94. <a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
  95. {% endif %}
  96. <button type="submit" name="file_submit" class="btn btn-primary">{% trans "Submit" %}</button>
  97. </div>
  98. </div>
  99. </form>
  100. </div>
  101. </div>
  102. {% if fields %}
  103. <div class="row my-3">
  104. <div class="col col-md-12">
  105. <div class="card">
  106. <h2 class="card-header">{% trans "Field Options" %}</h2>
  107. <table class="table">
  108. <thead>
  109. <tr>
  110. <th>{% trans "Field" %}</th>
  111. <th>{% trans "Required" %}</th>
  112. <th>{% trans "Accessor" %}</th>
  113. <th>{% trans "Description" %}</th>
  114. </tr>
  115. </thead>
  116. <tbody>
  117. {% for name, field in fields.items %}
  118. <tr>
  119. <td class="font-monospace{% if field.required %} fw-bold{% endif %}">
  120. {{ name }}
  121. </td>
  122. <td>
  123. {% if field.required %}
  124. {% checkmark True true="Required" %}
  125. {% else %}
  126. {{ ''|placeholder }}
  127. {% endif %}
  128. </td>
  129. {% if field.to_field_name %}
  130. <td class="font-monospace">{{ field.to_field_name }}</td>
  131. {% else %}
  132. <td>{{ ''|placeholder }}</td>
  133. {% endif %}
  134. <td>
  135. {% if field.help_text %}
  136. {{ field.help_text }}
  137. {% elif field.label %}
  138. {{ field.label }}
  139. {% endif %}
  140. {% if field.STATIC_CHOICES %}
  141. <a href="#" data-bs-toggle="modal" data-bs-target="#{{ name }}_choices" aria-label="{{ name }} {% trans "choices" %}"><i class="mdi mdi-help-circle"></i></a>
  142. <div class="modal fade" id="{{ name }}_choices" tabindex="-1" role="dialog">
  143. <div class="modal-dialog" role="document">
  144. <div class="modal-content">
  145. <div class="modal-header">
  146. <h5 class="modal-title">
  147. <span class="font-monospace">{{ name }}</span> {% trans "Choices" %}
  148. </h5>
  149. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  150. </div>
  151. <table class="table table-striped modal-body">
  152. <thead>
  153. <tr>
  154. <th>{% trans "Import Value" %}</th>
  155. <th>{% trans "Label" %}</th>
  156. </tr>
  157. </thead>
  158. <tbody>
  159. {% for value, label in field.choices %}
  160. {% if value %}
  161. <tr>
  162. <td><samp>{{ value }}</samp></td>
  163. <td>{{ label }}</td>
  164. </tr>
  165. {% endif %}
  166. {% endfor %}
  167. </tbody>
  168. </table>
  169. </div>
  170. </div>
  171. </div>
  172. {% endif %}
  173. {% if field|widget_type == 'dateinput' %}
  174. <br /><small class="text-muted">{% trans "Format: YYYY-MM-DD" %}</small>
  175. {% elif field|widget_type == 'checkboxinput' %}
  176. <br /><small class="text-muted">{% trans "Specify true or false" %}</small>
  177. {% endif %}
  178. </td>
  179. </tr>
  180. {% endfor %}
  181. </tbody>
  182. </table>
  183. </div>
  184. </div>
  185. </div>
  186. <p class="small text-muted">
  187. <i class="mdi mdi-check-bold text-success"></i>
  188. {% blocktrans trimmed %}
  189. Required fields <strong>must</strong> be specified for all objects.
  190. {% endblocktrans %}
  191. </p>
  192. <p class="small text-muted">
  193. <i class="mdi mdi-information-outline"></i>
  194. {% blocktrans trimmed with example="vrf.rd" %}
  195. Related objects may be referenced by any unique attribute. For example, <code>{{ example }}</code> would identify a VRF by its route distinguisher.
  196. {% endblocktrans %}
  197. </p>
  198. {% endif %}
  199. {% endblock content %}