Skip to content

Commit

Permalink
fix for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Jan 4, 2021
1 parent 9865609 commit d2f3b98
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
31 changes: 24 additions & 7 deletions vocabs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
from mptt.models import MPTTModel, TreeForeignKey


try:
notation_for_uri = settings.VOCABS_SETTINGS['notation_for_uri']
except KeyError:
notation_for_uri = False


DEFAULT_URI = "https://vocabs.acdh.oeaw.ac.at/"

try:
Expand Down Expand Up @@ -208,7 +214,7 @@ def __str__(self):
class ConceptSchemeTitle(models.Model):
"""
A Class for ConceptScheme titles in other languages.
"""
concept_scheme = models.ForeignKey(
SkosConceptScheme,
Expand All @@ -233,7 +239,7 @@ def __str__(self):
class ConceptSchemeDescription(models.Model):
"""
A Class for ConceptScheme descriptions in other languages.
"""
concept_scheme = models.ForeignKey(
SkosConceptScheme,
Expand All @@ -258,7 +264,7 @@ def __str__(self):
class ConceptSchemeSource(models.Model):
"""
A Class for ConceptScheme source information.
"""
concept_scheme = models.ForeignKey(
SkosConceptScheme,
Expand Down Expand Up @@ -392,7 +398,7 @@ def contributor_as_list(self):
class CollectionLabel(models.Model):
"""
A Class for Collection labels/names in other languages.
"""
collection = models.ForeignKey(
SkosCollection,
Expand Down Expand Up @@ -453,7 +459,7 @@ def __str__(self):
class CollectionSource(models.Model):
"""
A Class for Collection source information.
"""
collection = models.ForeignKey(
SkosCollection,
Expand Down Expand Up @@ -616,6 +622,17 @@ def save(self, *args, **kwargs):
self.date_modified = timezone.now()
super(SkosConcept, self).save(*args, **kwargs)

def create_uri(self):
mcs = self.scheme.identifier
if self.legacy_id:
concept_uri = f"{self.legacy_id}"
else:
if notation_for_uri:
concept_uri = f"{mcs}#concept__{slugify(self.notation, allow_unicode=False)}__{self.id}"
else:
concept_uri = f"{mcs}#concept{self.id}"
return concept_uri

# change for template tag
def creator_as_list(self):
return self.creator.split(';')
Expand Down Expand Up @@ -664,7 +681,7 @@ def __str__(self):
class ConceptLabel(models.Model):
"""
A Class for Concept labels of any type.
"""
concept = models.ForeignKey(
SkosConcept,
Expand Down Expand Up @@ -725,7 +742,7 @@ def __str__(self):
class ConceptSource(models.Model):
"""
A Class for Concept source information.
"""
concept = models.ForeignKey(
SkosConcept,
Expand Down
9 changes: 5 additions & 4 deletions vocabs/rdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ def graph_construct_qs(results):
g.add((main_concept_scheme, RDF.type, SKOS.ConceptScheme))
# Concept properties
# TODO user entered URI
if obj.legacy_id:
concept = URIRef(obj.legacy_id)
else:
concept = URIRef(main_concept_scheme + "#concept" + str(obj.id))
# if obj.legacy_id:
# concept = URIRef(obj.legacy_id)
# else:
# concept = URIRef(main_concept_scheme + "#concept" + str(obj.id))
concept = URIRef(obj.create_uri())
g.add((concept, RDF.type, SKOS.Concept))
g.add((concept, SKOS.prefLabel, Literal(obj.pref_label, lang=obj.pref_label_lang)))
g.add((concept, SKOS.notation, Literal(obj.notation)))
Expand Down
1 change: 1 addition & 0 deletions vocabseditor/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
'default_lang': "en"
}


# Django guardian settings

#ANONYMOUS_USER_NAME = 'public'
Expand Down

0 comments on commit d2f3b98

Please sign in to comment.