show the correct row of excel in exception
This commit is contained in:
parent
f5486c8df1
commit
7ed2798993
|
@ -165,7 +165,8 @@ class ImportForm(forms.Form):
|
||||||
self.fields['did'].choices = [
|
self.fields['did'].choices = [
|
||||||
(x.did, x.label) for x in dids.filter(eidas1=False)
|
(x.did, x.label) for x in dids.filter(eidas1=False)
|
||||||
]
|
]
|
||||||
self.fields['schema'].choices = [(0, _('Select one'))] + [
|
txt_select_one = _("Please choose a data schema ...")
|
||||||
|
self.fields['schema'].choices = [(0,txt_select_one)] + [
|
||||||
(x.id, x.name) for x in Schemas.objects.filter()
|
(x.id, x.name) for x in Schemas.objects.filter()
|
||||||
]
|
]
|
||||||
if dids.filter(eidas1=True).exists():
|
if dids.filter(eidas1=True).exists():
|
||||||
|
@ -185,7 +186,7 @@ class ImportForm(forms.Form):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not did.exists():
|
if not did.exists():
|
||||||
raise ValidationError("Did is not valid!")
|
raise ValidationError(_("Did not valid!"))
|
||||||
|
|
||||||
self._did = did.first()
|
self._did = did.first()
|
||||||
|
|
||||||
|
@ -205,13 +206,13 @@ class ImportForm(forms.Form):
|
||||||
id=data
|
id=data
|
||||||
)
|
)
|
||||||
if not schema.exists():
|
if not schema.exists():
|
||||||
raise ValidationError("Schema is not valid!")
|
raise ValidationError(_("Schema is not valid!"))
|
||||||
|
|
||||||
self._schema = schema.first()
|
self._schema = schema.first()
|
||||||
try:
|
try:
|
||||||
self.json_schema = self._schema.get_credential_subject_schema()
|
self.json_schema = self._schema.get_credential_subject_schema()
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValidationError("Schema is not valid!")
|
raise ValidationError(_("Schema not valid!"))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -230,9 +231,9 @@ class ImportForm(forms.Form):
|
||||||
# if no there are schema meen than is a excel costum and you
|
# if no there are schema meen than is a excel costum and you
|
||||||
# don't have control abour that
|
# don't have control abour that
|
||||||
if 'Schema' in workbook.custom_doc_props.names:
|
if 'Schema' in workbook.custom_doc_props.names:
|
||||||
excel_schema = workbook.custom_doc_props['Schema'].value.split("/")
|
excel_schema = workbook.custom_doc_props['Schema'].value
|
||||||
file_schema = self._schema.file_schema.split('.json')
|
file_schema = self._schema.file_schema.split('.json')[0]
|
||||||
assert file_schema[0] == excel_schema[-1]
|
assert file_schema in excel_schema
|
||||||
except Exception:
|
except Exception:
|
||||||
txt = _("This File does not correspond to this scheme!")
|
txt = _("This File does not correspond to this scheme!")
|
||||||
raise ValidationError(txt)
|
raise ValidationError(txt)
|
||||||
|
@ -250,18 +251,21 @@ class ImportForm(forms.Form):
|
||||||
if type_col and "string" in type_col:
|
if type_col and "string" in type_col:
|
||||||
df[col] = df[col].astype(str)
|
df[col] = df[col].astype(str)
|
||||||
|
|
||||||
data_pd = df.to_dict()
|
data_pd = df.to_dict(orient='index')
|
||||||
|
|
||||||
if not data_pd or df.last_valid_index() is None:
|
if not data_pd or df.last_valid_index() is None:
|
||||||
self.exception("The file you try to import is empty!")
|
self.exception(_("The file you try to import is empty!"))
|
||||||
|
|
||||||
for n in range(df.last_valid_index()+1):
|
for n in data_pd.keys():
|
||||||
row = {}
|
row = {}
|
||||||
for k in data_pd.keys():
|
d = data_pd[n]
|
||||||
if data_pd[k][n] or data_pd[k][n] == 0:
|
for k, v in d.items():
|
||||||
row[k] = data_pd[k][n]
|
if d[k] or d[k] == 0:
|
||||||
|
row[k] = d[k]
|
||||||
|
|
||||||
user = self.validate_jsonld(n, row)
|
if row:
|
||||||
|
user = self.validate_jsonld(n+2, row)
|
||||||
|
if user:
|
||||||
self.rows[user] = row
|
self.rows[user] = row
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -287,7 +291,7 @@ class ImportForm(forms.Form):
|
||||||
format_checker=jsonschema.Draft202012Validator.FORMAT_CHECKER
|
format_checker=jsonschema.Draft202012Validator.FORMAT_CHECKER
|
||||||
)
|
)
|
||||||
except jsonschema.exceptions.ValidationError as err:
|
except jsonschema.exceptions.ValidationError as err:
|
||||||
msg = "line {}: {}".format(line+1, err.message)
|
msg = "line {}: {}".format(line, err.message)
|
||||||
return self.exception(msg)
|
return self.exception(msg)
|
||||||
|
|
||||||
user, new = User.objects.get_or_create(email=row.get('email'))
|
user, new = User.objects.get_or_create(email=row.get('email'))
|
||||||
|
|
Loading…
Reference in New Issue