spaces cleanup

This commit is contained in:
Matthias 2021-06-02 00:26:30 +02:00
parent ee582a5490
commit 3c384947b2
3 changed files with 22 additions and 22 deletions

View File

@ -22,7 +22,7 @@ class FileManager:
# Fields which are used for item matching (only one of them is needed) # Fields which are used for item matching (only one of them is needed)
ITEM_MATCH_HEADERS = [] ITEM_MATCH_HEADERS = []
# Fields which would be helpful but are not required # Fields which would be helpful but are not required
OPTIONAL_HEADERS = [] OPTIONAL_HEADERS = []
@ -34,7 +34,7 @@ class FileManager:
def __init__(self, file, name=None): def __init__(self, file, name=None):
""" Initialize the FileManager class with a user-uploaded file object """ """ Initialize the FileManager class with a user-uploaded file object """
# Set name # Set name
if name: if name:
self.name = name self.name = name
@ -73,14 +73,14 @@ class FileManager:
raise ValidationError(_('Error reading file (incorrect dimension)')) raise ValidationError(_('Error reading file (incorrect dimension)'))
except KeyError: except KeyError:
raise ValidationError(_('Error reading file (data could be corrupted)')) raise ValidationError(_('Error reading file (data could be corrupted)'))
return cleaned_data return cleaned_data
def process(self, file): def process(self, file):
""" Process file """ """ Process file """
self.data = self.__class__.validate(file) self.data = self.__class__.validate(file)
def update_headers(self): def update_headers(self):
""" Update headers """ """ Update headers """
@ -100,7 +100,7 @@ class FileManager:
def guess_header(self, header, threshold=80): def guess_header(self, header, threshold=80):
""" Try to match a header (from the file) to a list of known headers """ Try to match a header (from the file) to a list of known headers
Args: Args:
header - Header name to look for header - Header name to look for
threshold - Match threshold for fuzzy search threshold - Match threshold for fuzzy search
@ -134,7 +134,7 @@ class FileManager:
return matches[0]['header'] return matches[0]['header']
return None return None
def columns(self): def columns(self):
""" Return a list of headers for the thingy """ """ Return a list of headers for the thingy """
headers = [] headers = []

View File

@ -69,7 +69,7 @@ class UploadFile(forms.Form):
class MatchField(forms.Form): class MatchField(forms.Form):
""" Step 2 of FileManagementFormView """ """ Step 2 of FileManagementFormView """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Get FileManager # Get FileManager
@ -85,7 +85,7 @@ class MatchField(forms.Form):
columns = file_manager.columns() columns = file_manager.columns()
# Get headers choices # Get headers choices
headers_choices = [(header, header) for header in file_manager.HEADERS] headers_choices = [(header, header) for header in file_manager.HEADERS]
# Create column fields # Create column fields
for col in columns: for col in columns:
field_name = col['name'] field_name = col['name']
@ -102,7 +102,7 @@ class MatchField(forms.Form):
class MatchItem(forms.Form): class MatchItem(forms.Form):
""" Step 3 of FileManagementFormView """ """ Step 3 of FileManagementFormView """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Get FileManager # Get FileManager
@ -145,7 +145,7 @@ class MatchItem(forms.Form):
required=True, required=True,
initial=value, initial=value,
) )
# Create item selection box # Create item selection box
elif col_guess in file_manager.ITEM_MATCH_HEADERS: elif col_guess in file_manager.ITEM_MATCH_HEADERS:
# Get item options # Get item options

View File

@ -130,7 +130,7 @@ class MultiStepFormView(SessionWizardView):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.process_media_folder() self.process_media_folder()
def process_media_folder(self): def process_media_folder(self):
""" Process media folder """ """ Process media folder """
@ -142,7 +142,7 @@ class MultiStepFormView(SessionWizardView):
def get_template_names(self): def get_template_names(self):
""" Select template """ """ Select template """
try: try:
# Get template # Get template
template = self.form_steps_template[self.steps.index] template = self.form_steps_template[self.steps.index]
@ -153,7 +153,7 @@ class MultiStepFormView(SessionWizardView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
""" Update context data """ """ Update context data """
# Retrieve current context # Retrieve current context
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -222,7 +222,7 @@ class FileManagementFormView(MultiStepFormView):
context = super().get_context_data(form=form, **kwargs) context = super().get_context_data(form=form, **kwargs)
if self.steps.current in ('fields', 'items'): if self.steps.current in ('fields', 'items'):
# Get columns and row data # Get columns and row data
self.columns = self.file_manager.columns() self.columns = self.file_manager.columns()
self.rows = self.file_manager.rows() self.rows = self.file_manager.rows()
@ -233,7 +233,7 @@ class FileManagementFormView(MultiStepFormView):
elif self.steps.current == 'items': elif self.steps.current == 'items':
# Set form table data # Set form table data
self.set_form_table_data(form=form) self.set_form_table_data(form=form)
# Update context # Update context
context.update({'rows': self.rows}) context.update({'rows': self.rows})
context.update({'columns': self.columns}) context.update({'columns': self.columns})
@ -292,11 +292,11 @@ class FileManagementFormView(MultiStepFormView):
self.get_form_table_data(data) self.get_form_table_data(data)
self.set_form_table_data() self.set_form_table_data()
self.get_field_selection() self.get_field_selection()
kwargs['row_data'] = self.rows kwargs['row_data'] = self.rows
return kwargs return kwargs
return super().get_form_kwargs() return super().get_form_kwargs()
def get_form(self, step=None, data=None, files=None): def get_form(self, step=None, data=None, files=None):
@ -366,7 +366,7 @@ class FileManagementFormView(MultiStepFormView):
col_id = int(s[3]) col_id = int(s[3])
except ValueError: except ValueError:
continue continue
if row_id not in self.row_data: if row_id not in self.row_data:
self.row_data[row_id] = {} self.row_data[row_id] = {}
@ -401,14 +401,14 @@ class FileManagementFormView(MultiStepFormView):
'name': self.column_names[idx], 'name': self.column_names[idx],
'guess': self.column_selections[idx], 'guess': self.column_selections[idx],
} }
cell_data = { cell_data = {
'cell': item, 'cell': item,
'idx': idx, 'idx': idx,
'column': column_data, 'column': column_data,
} }
data.append(cell_data) data.append(cell_data)
row = { row = {
'index': row_idx, 'index': row_idx,
'data': data, 'data': data,
@ -501,7 +501,7 @@ class FileManagementFormView(MultiStepFormView):
if col in self.column_selections.values(): if col in self.column_selections.values():
part_match_found = True part_match_found = True
break break
# If not, notify user # If not, notify user
if not part_match_found: if not part_match_found:
for col in self.file_manager.ITEM_MATCH_HEADERS: 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]) n = list(self.column_selections.values()).count(self.column_selections[col])
if n > 1 and self.column_selections[col] not in duplicates: if n > 1 and self.column_selections[col] not in duplicates:
duplicates.append(self.column_selections[col]) duplicates.append(self.column_selections[col])
# Store extra context data # Store extra context data
self.extra_context_data = { self.extra_context_data = {
'missing_columns': missing_columns, 'missing_columns': missing_columns,