Pass the form field data back to the server

This commit is contained in:
Oliver Walters 2019-06-28 19:58:56 +10:00
parent 58336482fe
commit 857a214e7d
2 changed files with 45 additions and 2 deletions

View File

@ -19,13 +19,13 @@
<th>Row</th> <th>Row</th>
{% for col in bom_cols %} {% for col in bom_cols %}
<th> <th>
<select class='select' id='id_col_{{ forloop.counter0 }}' name='col_{{ forloop.counter0 }}'> <select class='select' id='id_col_{{ forloop.counter0 }}' name='col_select_{{ forloop.counter0 }}'>
<option value=''>---------</option> <option value=''>---------</option>
{% for req in req_cols %} {% for req in req_cols %}
<option value='{{ req }}'{% if req == col.guess %}selected='selected'{% endif %}>{{ req }}</option> <option value='{{ req }}'{% if req == col.guess %}selected='selected'{% endif %}>{{ req }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type='hidden' name='col_{{ forloop.counter0 }}' value='{{ col.name }}'/> <input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
{{ col.name }} {{ col.name }}
</th> </th>
{% endfor %} {% endfor %}

View File

@ -744,6 +744,49 @@ class BomUpload(AjaxView, FormMixin):
self.ajax_template_name = 'part/bom_upload/select_fields.html' self.ajax_template_name = 'part/bom_upload/select_fields.html'
# Map the columns
column_names = {}
column_selections = {}
row_data = {}
for item in self.request.POST:
print(item)
value = self.request.POST[item]
# Extract the column names
if item.startswith('col_name_'):
col_id = item.replace('col_name_', '')
col_name = value
column_names[col_id] = col_name
# Extract the column selections
if item.startswith('col_select_'):
col_id = item.replace('col_select_', '')
col_name = value
column_selections[col_id] = value
# Extract the row data
if item.startswith('row_'):
# Item should be of the format row_<r>_col_<c>
s = item.split('_')
if len(s) < 4:
continue
row_id = s[1]
col_id = s[3]
if not row_id in row_data:
row_data[row_id] = {}
row_data[row_id][col_id] = value
ctx = { ctx = {
# The headers that we know about # The headers that we know about
'known_headers': BomUploadManager.HEADERS, 'known_headers': BomUploadManager.HEADERS,