mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
spaces cleanup
This commit is contained in:
parent
ee582a5490
commit
3c384947b2
@ -22,7 +22,7 @@ class FileManager:
|
||||
|
||||
# Fields which are used for item matching (only one of them is needed)
|
||||
ITEM_MATCH_HEADERS = []
|
||||
|
||||
|
||||
# Fields which would be helpful but are not required
|
||||
OPTIONAL_HEADERS = []
|
||||
|
||||
@ -34,7 +34,7 @@ class FileManager:
|
||||
|
||||
def __init__(self, file, name=None):
|
||||
""" Initialize the FileManager class with a user-uploaded file object """
|
||||
|
||||
|
||||
# Set name
|
||||
if name:
|
||||
self.name = name
|
||||
@ -73,14 +73,14 @@ class FileManager:
|
||||
raise ValidationError(_('Error reading file (incorrect dimension)'))
|
||||
except KeyError:
|
||||
raise ValidationError(_('Error reading file (data could be corrupted)'))
|
||||
|
||||
|
||||
return cleaned_data
|
||||
|
||||
def process(self, file):
|
||||
""" Process file """
|
||||
|
||||
self.data = self.__class__.validate(file)
|
||||
|
||||
|
||||
def update_headers(self):
|
||||
""" Update headers """
|
||||
|
||||
@ -100,7 +100,7 @@ class FileManager:
|
||||
|
||||
def guess_header(self, header, threshold=80):
|
||||
""" Try to match a header (from the file) to a list of known headers
|
||||
|
||||
|
||||
Args:
|
||||
header - Header name to look for
|
||||
threshold - Match threshold for fuzzy search
|
||||
@ -134,7 +134,7 @@ class FileManager:
|
||||
return matches[0]['header']
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def columns(self):
|
||||
""" Return a list of headers for the thingy """
|
||||
headers = []
|
||||
|
@ -69,7 +69,7 @@ class UploadFile(forms.Form):
|
||||
|
||||
class MatchField(forms.Form):
|
||||
""" Step 2 of FileManagementFormView """
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
# Get FileManager
|
||||
@ -85,7 +85,7 @@ class MatchField(forms.Form):
|
||||
columns = file_manager.columns()
|
||||
# Get headers choices
|
||||
headers_choices = [(header, header) for header in file_manager.HEADERS]
|
||||
|
||||
|
||||
# Create column fields
|
||||
for col in columns:
|
||||
field_name = col['name']
|
||||
@ -102,7 +102,7 @@ class MatchField(forms.Form):
|
||||
|
||||
class MatchItem(forms.Form):
|
||||
""" Step 3 of FileManagementFormView """
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
# Get FileManager
|
||||
@ -145,7 +145,7 @@ class MatchItem(forms.Form):
|
||||
required=True,
|
||||
initial=value,
|
||||
)
|
||||
|
||||
|
||||
# Create item selection box
|
||||
elif col_guess in file_manager.ITEM_MATCH_HEADERS:
|
||||
# Get item options
|
||||
|
@ -130,7 +130,7 @@ class MultiStepFormView(SessionWizardView):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.process_media_folder()
|
||||
|
||||
|
||||
def process_media_folder(self):
|
||||
""" Process media folder """
|
||||
|
||||
@ -142,7 +142,7 @@ class MultiStepFormView(SessionWizardView):
|
||||
|
||||
def get_template_names(self):
|
||||
""" Select template """
|
||||
|
||||
|
||||
try:
|
||||
# Get template
|
||||
template = self.form_steps_template[self.steps.index]
|
||||
@ -153,7 +153,7 @@ class MultiStepFormView(SessionWizardView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Update context data """
|
||||
|
||||
|
||||
# Retrieve current context
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
@ -222,7 +222,7 @@ class FileManagementFormView(MultiStepFormView):
|
||||
context = super().get_context_data(form=form, **kwargs)
|
||||
|
||||
if self.steps.current in ('fields', 'items'):
|
||||
|
||||
|
||||
# Get columns and row data
|
||||
self.columns = self.file_manager.columns()
|
||||
self.rows = self.file_manager.rows()
|
||||
@ -233,7 +233,7 @@ class FileManagementFormView(MultiStepFormView):
|
||||
elif self.steps.current == 'items':
|
||||
# Set form table data
|
||||
self.set_form_table_data(form=form)
|
||||
|
||||
|
||||
# Update context
|
||||
context.update({'rows': self.rows})
|
||||
context.update({'columns': self.columns})
|
||||
@ -292,11 +292,11 @@ class FileManagementFormView(MultiStepFormView):
|
||||
self.get_form_table_data(data)
|
||||
self.set_form_table_data()
|
||||
self.get_field_selection()
|
||||
|
||||
|
||||
kwargs['row_data'] = self.rows
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
return super().get_form_kwargs()
|
||||
|
||||
def get_form(self, step=None, data=None, files=None):
|
||||
@ -366,7 +366,7 @@ class FileManagementFormView(MultiStepFormView):
|
||||
col_id = int(s[3])
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
|
||||
if row_id not in self.row_data:
|
||||
self.row_data[row_id] = {}
|
||||
|
||||
@ -401,14 +401,14 @@ class FileManagementFormView(MultiStepFormView):
|
||||
'name': self.column_names[idx],
|
||||
'guess': self.column_selections[idx],
|
||||
}
|
||||
|
||||
|
||||
cell_data = {
|
||||
'cell': item,
|
||||
'idx': idx,
|
||||
'column': column_data,
|
||||
}
|
||||
data.append(cell_data)
|
||||
|
||||
|
||||
row = {
|
||||
'index': row_idx,
|
||||
'data': data,
|
||||
@ -501,7 +501,7 @@ class FileManagementFormView(MultiStepFormView):
|
||||
if col in self.column_selections.values():
|
||||
part_match_found = True
|
||||
break
|
||||
|
||||
|
||||
# If not, notify user
|
||||
if not part_match_found:
|
||||
for col in self.file_manager.ITEM_MATCH_HEADERS:
|
||||
@ -521,7 +521,7 @@ class FileManagementFormView(MultiStepFormView):
|
||||
n = list(self.column_selections.values()).count(self.column_selections[col])
|
||||
if n > 1 and self.column_selections[col] not in duplicates:
|
||||
duplicates.append(self.column_selections[col])
|
||||
|
||||
|
||||
# Store extra context data
|
||||
self.extra_context_data = {
|
||||
'missing_columns': missing_columns,
|
||||
|
Loading…
Reference in New Issue
Block a user