mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve rendering for field selection form
This commit is contained in:
parent
c419207420
commit
29a27ce598
@ -55,13 +55,11 @@ class BomUploadSelectFields(HelperForm):
|
|||||||
""" Form for selecting BOM fields """
|
""" Form for selecting BOM fields """
|
||||||
|
|
||||||
starting_row = forms.IntegerField(required=True, initial=2, help_text='Index of starting row', validators=[MinValueValidator(1)])
|
starting_row = forms.IntegerField(required=True, initial=2, help_text='Index of starting row', validators=[MinValueValidator(1)])
|
||||||
row_count = forms.IntegerField(required=True, help_text='Number of rows to process', validators=[MinValueValidator(0)])
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
fields = [
|
fields = [
|
||||||
'starting_row',
|
'starting_row',
|
||||||
'row_count',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -675,7 +675,7 @@ class BomUpload(FormView):
|
|||||||
ctx = super().get_context_data(*args, **kwargs)
|
ctx = super().get_context_data(*args, **kwargs)
|
||||||
|
|
||||||
ctx['part'] = self.part
|
ctx['part'] = self.part
|
||||||
ctx['bom_headers'] = self.bom_headers
|
ctx['bom_headers'] = BomUploadManager.HEADERS
|
||||||
ctx['bom_columns'] = self.bom_columns
|
ctx['bom_columns'] = self.bom_columns
|
||||||
ctx['bom_rows'] = self.bom_rows
|
ctx['bom_rows'] = self.bom_rows
|
||||||
ctx['missing_columns'] = self.missing_columns
|
ctx['missing_columns'] = self.missing_columns
|
||||||
@ -741,7 +741,6 @@ class BomUpload(FormView):
|
|||||||
def extractDataFromFile(self, bom):
|
def extractDataFromFile(self, bom):
|
||||||
""" Read data from the BOM file """
|
""" Read data from the BOM file """
|
||||||
|
|
||||||
self.bom_headers = bom.HEADERS
|
|
||||||
self.bom_columns = bom.columns()
|
self.bom_columns = bom.columns()
|
||||||
self.bom_rows = bom.rows()
|
self.bom_rows = bom.rows()
|
||||||
|
|
||||||
@ -752,12 +751,6 @@ class BomUpload(FormView):
|
|||||||
column names and which rows to process.
|
column names and which rows to process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = {
|
|
||||||
'form_valid': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.ajax_template_name = 'part/bom_upload/select_fields.html'
|
|
||||||
|
|
||||||
# Map the columns
|
# Map the columns
|
||||||
column_names = {}
|
column_names = {}
|
||||||
column_selections = {}
|
column_selections = {}
|
||||||
@ -801,7 +794,7 @@ class BomUpload(FormView):
|
|||||||
|
|
||||||
col_ids = sorted(column_names.keys())
|
col_ids = sorted(column_names.keys())
|
||||||
|
|
||||||
headers = []
|
self.bom_columns = []
|
||||||
|
|
||||||
for col in col_ids:
|
for col in col_ids:
|
||||||
if col not in column_selections:
|
if col not in column_selections:
|
||||||
@ -820,17 +813,17 @@ class BomUpload(FormView):
|
|||||||
if n > 1:
|
if n > 1:
|
||||||
header['duplicate'] = True
|
header['duplicate'] = True
|
||||||
|
|
||||||
headers.append(header)
|
self.bom_columns.append(header)
|
||||||
|
|
||||||
# Are there any missing columns?
|
# Are there any missing columns?
|
||||||
missing = []
|
self.missing_columns = []
|
||||||
|
|
||||||
for col in BomUploadManager.REQUIRED_HEADERS:
|
for col in BomUploadManager.REQUIRED_HEADERS:
|
||||||
if col not in column_selections.values():
|
if col not in column_selections.values():
|
||||||
missing.append(col)
|
self.missing_columns.append(col)
|
||||||
|
|
||||||
# Re-construct the data table
|
# Re-construct the data table
|
||||||
rows = []
|
self.bom_rows = []
|
||||||
|
|
||||||
for row_idx in sorted(row_data.keys()):
|
for row_idx in sorted(row_data.keys()):
|
||||||
row = row_data[row_idx]
|
row = row_data[row_idx]
|
||||||
@ -843,19 +836,12 @@ class BomUpload(FormView):
|
|||||||
value = row[col_idx]
|
value = row[col_idx]
|
||||||
items.append(value)
|
items.append(value)
|
||||||
|
|
||||||
rows.append({'index': row_idx, 'data': items})
|
self.bom_rows.append({'index': row_idx, 'data': items})
|
||||||
|
|
||||||
ctx = {
|
form = part_forms.BomUploadSelectFields
|
||||||
# The headers that we know about
|
self.template_name = 'part/bom_upload/select_fields.html'
|
||||||
'req_cols': BomUploadManager.HEADERS,
|
|
||||||
'bom_cols': headers,
|
|
||||||
'missing': missing,
|
|
||||||
'bom_rows': rows,
|
|
||||||
}
|
|
||||||
|
|
||||||
print(ctx)
|
return self.render_to_response(self.get_context_data(form=form))
|
||||||
|
|
||||||
return self.renderJsonResponse(self.request, form=self.get_form(), data=data, context=ctx)
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
""" Perform the various 'POST' requests required.
|
""" Perform the various 'POST' requests required.
|
||||||
|
Loading…
Reference in New Issue
Block a user