Skip to content

Commit

Permalink
Merge pull request #164 from BuildingSync/validator-bug
Browse files Browse the repository at this point in the history
workaround for example files dropdown by version
  • Loading branch information
nllong committed Feb 21, 2022
2 parents 50c70ce + a097f03 commit 0d643a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions bsyncviewer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ class LoadXMLExample(forms.Form):

form_type = forms.CharField(widget=forms.HiddenInput(), initial='example')

def clean(self):

super(LoadXMLExample, self).clean()

# remove file_name error
if 'file_name' in self._errors:
for idx, i in enumerate(self._errors['file_name']):
if 'Select a valid choice. bsyncviewer/lib/validator/examples/' in i:
del self._errors['file_name'][idx]
print("file_name errors now: {}".format(self._errors['file_name']))

return self.cleaned_data


class UpdateUserForm(forms.Form):
first_name = forms.CharField(max_length=30, required=False)
Expand Down
14 changes: 13 additions & 1 deletion bsyncviewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,19 @@ def validator(request):
else:
return render(request, 'validator.html', context)

if form.is_valid():
validated = False
if form_type == 'example':
# workaround for files list by schema_version
errors = form.errors
file_errs = errors['file_name']
if len(file_errs) == 0:
# no errors - validated
validated = True

elif form.is_valid():
validated = True

if validated:
if form_type == 'file':
f = request.FILES['file']
filename = f.name
Expand Down

0 comments on commit 0d643a7

Please sign in to comment.