bulk_import.html 10 KB

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