From 857a214e7df3b90d4c4929f179622b0856ea4d67 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 28 Jun 2019 19:58:56 +1000 Subject: [PATCH] Pass the form field data back to the server --- .../part/bom_upload/select_fields.html | 4 +- InvenTree/part/views.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/templates/part/bom_upload/select_fields.html b/InvenTree/part/templates/part/bom_upload/select_fields.html index db09b2a3fb..d06846b33d 100644 --- a/InvenTree/part/templates/part/bom_upload/select_fields.html +++ b/InvenTree/part/templates/part/bom_upload/select_fields.html @@ -19,13 +19,13 @@ Row {% for col in bom_cols %} - {% for req in req_cols %} {% endfor %} - + {{ col.name }} {% endfor %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 6858e3e179..abd787bc5c 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -744,6 +744,49 @@ class BomUpload(AjaxView, FormMixin): 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__col_ + 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 = { # The headers that we know about 'known_headers': BomUploadManager.HEADERS,