/
import.html
205 lines (183 loc) · 6.47 KB
/
import.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{% extends "admin/import_export/base.html" %}
{% load i18n %}
{% load admin_urls %}
{% load import_export_tags %}
{% load static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "import_export/import.css" %}" />{% endblock %}
{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% if confirm_form %}
{{ confirm_form.media }}
{% else %}
{{ form.media }}
{% endif %}
{% endblock %}
{% block breadcrumbs_last %}
{% translate "Import" %}
{% endblock %}
{% block content %}
{% if confirm_form %}
{% block confirm_import_form %}
<form action="{% url opts|admin_urlname:"process_import" %}" method="POST">
{% csrf_token %}
{{ confirm_form.as_p }}
<p>
{% translate "Below is a preview of data to be imported. If you are satisfied with the results, click 'Confirm import'" %}
</p>
<div class="submit-row">
<input type="submit" class="default" name="confirm" value="{% translate "Confirm import" %}">
</div>
</form>
{% endblock %}
{% else %}
{% block import_form %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{% include "admin/import_export/resource_fields_list.html" with import_or_export="import" %}
{% block form_detail %}
<fieldset class="module aligned">
{% for field in form %}
<div class="form-row">
{{ field.errors }}
{{ field.label_tag }}
{% if field.field.widget.attrs.readonly %}
{{ field.field.value }}
{{ field.as_hidden }}
{% else %}
{{ field }}
{% endif %}
{% if field.field.help_text %}
<p class="help">{{ field.field.help_text|safe }}</p>
{% endif %}
</div>
{% endfor %}
</fieldset>
{% endblock %}
{% block form_submit_button %}
<div class="submit-row">
<input type="submit" class="default" value="{% translate "Submit" %}">
</div>
{% endblock %}
</form>
{% endblock %}
{% endif %}
{% if result %}
{% if result.has_errors %}
{% block errors %}
<h2>{% translate "Errors" %}</h2>
<ul>
{% for error in result.base_errors %}
<li>
{{ error.error }}
<div class="traceback">{{ error.traceback|linebreaks }}</div>
</li>
{% endfor %}
{% block import_error_list %}
{% for line, errors in result.row_errors %}
{% for error in errors %}
{% block import_error_list_item %}
<li class="import-error-li">
{% if "message" in import_error_display %}
<div class="import-error-display-message">{% translate "Line number" %}: {{ line }} - {{ error.error }}</div>
{% endif %}
{% if "row" in import_error_display %}
<div class="import-error-display-row">{{ error.row.values|join:", " }}</div>
{% endif %}
{% if "traceback" in import_error_display %}
<div class="import-error-display-traceback">{{ error.traceback|linebreaks }}</div>
{% endif %}
</li>
{% endblock %}
{% endfor %}
{% endfor %}
{% endblock %}
</ul>
{% endblock %}
{% elif result.has_validation_errors %}
{% block validation_errors %}
<h2>{% translate "Some rows failed to validate" %}</h2>
<p>{% translate "Please correct these errors in your data where possible, then reupload it using the form above." %}</p>
<table class="import-preview">
<thead>
<tr>
<th>{% translate "Row" %}</th>
<th>{% translate "Errors" %}</th>
{% for field in result.diff_headers %}
<th>{{ field }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in result.invalid_rows %}
<tr>
<td>{{ row.number }} </td>
<td class="errors">
<span class="validation-error-count">{{ row.error_count }}</span>
<div class="validation-error-container">
<ul class="validation-error-list">
{% for field_name, error_list in row.field_specific_errors.items %}
<li>
<span class="validation-error-field-label">{{ field_name }}</span>
<ul>
{% for error in error_list %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
{% if row.non_field_specific_errors %}
<li>
<span class="validation-error-field-label">{% translate "Non field specific" %}</span>
<ul>
{% for error in row.non_field_specific_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
</div>
</td>
{% for field in row.values %}
<td>{{ field }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% else %}
{% block preview %}
<h2>{% translate "Preview" %}</h2>
<table class="import-preview">
<thead>
<tr>
<th></th>
{% for field in result.diff_headers %}
<th>{{ field }}</th>
{% endfor %}
</tr>
</thead>
{% for row in result.valid_rows %}
<tr class="{{ row.import_type }}">
<td class="import-type">
{% if row.import_type == 'new' %}
{% translate "New" %}
{% elif row.import_type == 'skip' %}
{% translate "Skipped" %}
{% elif row.import_type == 'delete' %}
{% translate "Delete" %}
{% elif row.import_type == 'update' %}
{% translate "Update" %}
{% endif %}
</td>
{% for field in row.diff %}
<td>{{ field }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endblock %}
{% endif %}
{% endif %}
{% endblock %}