fix descriptions, names and jsons
This commit is contained in:
parent
76fe838c92
commit
19fa84e45e
|
@ -928,10 +928,17 @@ class SchemasImportAddView(SchemasMix):
|
|||
except Exception:
|
||||
messages.error(self.request, _('This is not a valid schema!'))
|
||||
return
|
||||
|
||||
_name = json.dumps(ldata.get('name', ''))
|
||||
_description = json.dumps(ldata.get('description', ''))
|
||||
|
||||
schema = Schemas.objects.create(
|
||||
file_schema=file_name,
|
||||
data=data,
|
||||
type=name,
|
||||
type=title,
|
||||
_name=_name,
|
||||
_description=_description,
|
||||
# template_description=_description
|
||||
template_description=self.get_description()
|
||||
)
|
||||
schema.save()
|
||||
|
@ -946,7 +953,7 @@ class SchemasImportAddView(SchemasMix):
|
|||
return data
|
||||
|
||||
def get_template_description(self):
|
||||
context = self.get_context()
|
||||
context = {}
|
||||
template_name = 'credentials/{}'.format(
|
||||
self.schema.file_schema
|
||||
)
|
||||
|
@ -954,7 +961,7 @@ class SchemasImportAddView(SchemasMix):
|
|||
return tmpl.render(context)
|
||||
|
||||
def get_description(self):
|
||||
for des in json.loads(self.render()).get('description', []):
|
||||
for des in json.loads(self.get_template_description()).get('description', []):
|
||||
if settings.LANGUAGE_CODE == des.get('lang'):
|
||||
return des.get('value', '')
|
||||
return ''
|
||||
|
|
|
@ -95,16 +95,18 @@ class Command(BaseCommand):
|
|||
assert title
|
||||
except Exception:
|
||||
title = ''
|
||||
return
|
||||
name = ''
|
||||
try:
|
||||
for x in dname:
|
||||
if settings.LANGUAGE_CODE in x['lang']:
|
||||
name = x.get('value', '')
|
||||
except Exception:
|
||||
return
|
||||
_name = ''
|
||||
|
||||
Schemas.objects.create(file_schema=file_name, data=data, type=title)
|
||||
_name = json.dumps(ldata.get('name', ''))
|
||||
_description = json.dumps(ldata.get('description', ''))
|
||||
|
||||
Schemas.objects.create(
|
||||
file_schema=file_name,
|
||||
data=data,
|
||||
type=title,
|
||||
_name=_name,
|
||||
_description=_description
|
||||
)
|
||||
|
||||
def open_file(self, file_name):
|
||||
data = ''
|
||||
|
|
|
@ -473,7 +473,7 @@ class Schemas(models.Model):
|
|||
file_schema = models.CharField(max_length=250)
|
||||
data = models.TextField()
|
||||
created_at = models.DateTimeField(auto_now=True)
|
||||
_name = models.CharField(max_length=250, null=True, db_column='name')
|
||||
_name = models.TextField(null=True, db_column='name')
|
||||
_description = models.CharField(max_length=250, null=True, db_column='description')
|
||||
template_description = models.TextField(null=True)
|
||||
|
||||
|
@ -488,7 +488,12 @@ class Schemas(models.Model):
|
|||
if not field_value:
|
||||
field_value = self.get_schema.get(schema_key, [] if is_json else '')
|
||||
self._update_model_field(field_attr, field_value)
|
||||
return json.loads(field_value) if is_json else field_value
|
||||
try:
|
||||
if is_json:
|
||||
return json.loads(field_value)
|
||||
except json.decoder.JSONDecodeError:
|
||||
return field_value
|
||||
return field_value
|
||||
|
||||
def _update_model_field(self, field_attr, field_value):
|
||||
if field_value:
|
||||
|
@ -597,16 +602,14 @@ class VerificableCredential(models.Model):
|
|||
def type(self):
|
||||
return self.schema.type
|
||||
|
||||
#<<<<<<< HEAD
|
||||
def get_description(self):
|
||||
return self.schema.template_description
|
||||
#=======
|
||||
return self.schema._description or ''
|
||||
|
||||
def description(self):
|
||||
for des in json.loads(self.render("")).get('description', []):
|
||||
if settings.LANGUAGE_CODE in des.get('lang'):
|
||||
return des.get('value', '')
|
||||
return ''
|
||||
#>>>>>>> main
|
||||
|
||||
def get_type(self, lang=None):
|
||||
schema = json.loads(self.schema.data)
|
||||
|
|
Loading…
Reference in a new issue