From b77bfc74eae6f08110e3b43d096496f40d4ded19 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 7 Jul 2019 09:50:59 +1000 Subject: [PATCH] Pass column and index data through to each cell in the template Allows for much more intelligent template rendering --- .gitignore | 3 ++- .../part/bom_upload/select_fields.html | 4 +-- .../part/bom_upload/select_parts.html | 14 ++++++++--- InvenTree/part/views.py | 25 ++++++++++++++++++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bfbaf7c285..25ae56db0a 100644 --- a/.gitignore +++ b/.gitignore @@ -37,8 +37,9 @@ InvenTree/media # Key file secret_key.txt -# Ignore python IDE project configuration +# IDE / development files .idea/ +*.code-workspace # Coverage reports .coverage diff --git a/InvenTree/part/templates/part/bom_upload/select_fields.html b/InvenTree/part/templates/part/bom_upload/select_fields.html index 45f2b8c3a3..6b3fe4e178 100644 --- a/InvenTree/part/templates/part/bom_upload/select_fields.html +++ b/InvenTree/part/templates/part/bom_upload/select_fields.html @@ -76,8 +76,8 @@ {{ forloop.counter }} {% for item in row.data %} - - {{ item }} + + {{ item.cell }} {% endfor %} diff --git a/InvenTree/part/templates/part/bom_upload/select_parts.html b/InvenTree/part/templates/part/bom_upload/select_parts.html index 80545ddf62..28a64628c6 100644 --- a/InvenTree/part/templates/part/bom_upload/select_parts.html +++ b/InvenTree/part/templates/part/bom_upload/select_parts.html @@ -1,5 +1,6 @@ {% extends "part/part_base.html" %} {% load static %} +{% load inventree_extras %} {% block details %} {% include "part/tabs.html" with tab="bom" %} @@ -23,7 +24,11 @@ Row {% for col in bom_columns %} + {% if col.guess %} + {{ col.guess }} + {% else %} {{ col.name }} + {% endif %} {% endfor %} @@ -37,12 +42,15 @@ - - {{ forloop.counter }} + {% add row.index 1 %} {% for item in row.data %} - {{ item }} + {% if item.column.guess == 'Quantity' %} + + {% else %} + {{ item.cell }} + {% endif %} {% endfor %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 04c947c0dc..0efeef42ed 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -674,10 +674,33 @@ class BomUpload(FormView): ctx = super().get_context_data(*args, **kwargs) + # Give each row item access to the column it is in + # This provides for much simpler template rendering + + rows = [] + for row in self.bom_rows: + row_data = row['data'] + + data = [] + + for idx, item in enumerate(row_data): + + data.append({ + 'cell': item, + 'idx': idx, + 'column': self.bom_columns[idx] + }) + + rows.append({ + 'index': row.get('index', -1), + 'data': data, + 'quantity': row.get('quantity', None), + }) + ctx['part'] = self.part ctx['bom_headers'] = BomUploadManager.HEADERS ctx['bom_columns'] = self.bom_columns - ctx['bom_rows'] = self.bom_rows + ctx['bom_rows'] = rows ctx['missing_columns'] = self.missing_columns return ctx