fix some things

This commit is contained in:
Cayo Puigdefabregas 2023-11-22 11:18:47 +01:00
parent 5ac3790588
commit 6bf642c720
4 changed files with 17 additions and 8 deletions

View File

@ -27,6 +27,7 @@ class ImportForm(forms.Form):
self._schema = None self._schema = None
self._did = None self._did = None
self.rows = {} self.rows = {}
self.properties = {}
self.user = kwargs.pop('user', None) self.user = kwargs.pop('user', None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields['did'].choices = [ self.fields['did'].choices = [
@ -59,6 +60,16 @@ class ImportForm(forms.Form):
raise ValidationError("Schema is not valid!") raise ValidationError("Schema is not valid!")
self._schema = schema.first() self._schema = schema.first()
try:
self.json_schema = json.loads(self._schema.data)
prop = self.json_schema['properties']
self.properties = prop['credentialSubject']['properties']
except Exception:
raise ValidationError("Schema is not valid!")
if not self.properties:
raise ValidationError("Schema is not valid!")
return data return data
@ -68,15 +79,13 @@ class ImportForm(forms.Form):
if File_datas.objects.filter(file_name=self.file_name, success=True).exists(): if File_datas.objects.filter(file_name=self.file_name, success=True).exists():
raise ValidationError("This file already exists!") raise ValidationError("This file already exists!")
self.json_schema = json.loads(self._schema.data)
df = pd.read_csv (data, delimiter="\t", quotechar='"', quoting=csv.QUOTE_ALL) df = pd.read_csv (data, delimiter="\t", quotechar='"', quoting=csv.QUOTE_ALL)
data_pd = df.fillna('').to_dict() data_pd = df.fillna('').to_dict()
if not data_pd: if not data_pd:
self.exception("This file is empty!") self.exception("This file is empty!")
properties = self.json_schema['properties']['credentialSubject']['properties'] head_row = {x: '' for x in self.properties.keys()}
head_row = {x: '' for x in properties.keys()}
for n in range(df.last_valid_index()+1): for n in range(df.last_valid_index()+1):
row = head_row.copy() row = head_row.copy()
for k in data_pd.keys(): for k in data_pd.keys():

View File

@ -35,7 +35,7 @@
{% endfor %} {% endfor %}
<div class="row mt-3"> <div class="row mt-3">
<div class="col-3 text-end"> <div class="col-3 text-end">
<strong>Date of Issue:</strong> <strong>{% trand 'Issuance date' %}:</strong>
</div> </div>
<div class="col bg-light text-secondary"> <div class="col bg-light text-secondary">
{{ object.issuer_on|default_if_none:"" }} {{ object.issuer_on|default_if_none:"" }}
@ -43,7 +43,7 @@
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col-3 text-end"> <div class="col-3 text-end">
<strong>Status:</strong> <strong>{% trand 'Status' %}:</strong>
</div> </div>
<div class="col bg-light text-secondary"> <div class="col bg-light text-secondary">
{{ object.get_status}} {{ object.get_status}}

View File

@ -22,7 +22,7 @@
{% endfor %} {% endfor %}
<div class="row mt-3"> <div class="row mt-3">
<div class="col-3 text-end"> <div class="col-3 text-end">
<strong>Date of Issue:</strong> <strong>{% trand 'Issuance date' %}:</strong>
</div> </div>
<div class="col bg-light text-secondary"> <div class="col bg-light text-secondary">
{{ object.issuer_on|default_if_none:"" }} {{ object.issuer_on|default_if_none:"" }}
@ -30,7 +30,7 @@
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col-3 text-end"> <div class="col-3 text-end">
<strong>Status:</strong> <strong>{% trand 'Status' %}:</strong>
</div> </div>
<div class="col bg-light text-secondary"> <div class="col bg-light text-secondary">
{{ object.get_status}} {{ object.get_status}}

View File

@ -18,7 +18,7 @@
<tbody> <tbody>
{% for ev in user.events.all %} {% for ev in user.events.all %}
<tr> <tr>
<td>{{ ev.get_type }}</td> <td>{{ ev.get_type_name }}</td>
<td>{{ ev.message }}</td> <td>{{ ev.message }}</td>
<td>{{ ev.created }}</td> <td>{{ ev.created }}</td>
</tr> </tr>