Skip to content

Commit

Permalink
Deduplicate routes and views #198
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jan 31, 2025
1 parent 9668167 commit befa36b
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 608 deletions.
121 changes: 22 additions & 99 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
from django.utils.translation import gettext as _
from rest_framework.exceptions import ValidationError

from arches_references.models import ListItem

from arches.app.models.models import ResourceInstance, TileModel
from arches.app.models.serializers import ArchesModelSerializer, ArchesTileSerializer


class SchemeStatementSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
graph_slug = "scheme"
root_node = "statement"
fields = "__all__"


class SchemeSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = "__all__"
fields = "__all__"


class SchemeNamespaceSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["namespace"]
fields = "__all__"


class SchemeCreationSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["creation"]
fields = "__all__"
from arches_references.models import ListItem


class SchemeRightsSerializer(ArchesModelSerializer):
Expand All @@ -62,14 +29,7 @@ def repair_right_statement(self, instance):
return instance


class SchemeLabelSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["appellative_status"]
fields = "__all__"


### Custom serializers for implementing business logic.
class SchemeLabelTileSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
Expand All @@ -80,15 +40,12 @@ class Meta:
def validate(self, data):
data = super().validate(data)
try:
PREF_LABEL_LIST_ITEM = ListItem.objects.get(
list_item_values__value="prefLabel",
)
PREF_LABEL = ListItem.objects.get(list_item_values__value="prefLabel")
except ListItem.MultipleObjectsReturned:
raise RuntimeError(
_(
"Ask your system administrator to deduplicate the prefLabel list items."
)
msg = _(
"Ask your system administrator to deduplicate the prefLabel list items."
)
raise ValidationError(msg)

if data:
# TODO: reduce nested-fallback awkwardness by returning a dataclass from
Expand All @@ -111,68 +68,34 @@ def validate(self, data):
)
if (
data.get("tileid", None) not in (None, label.tileid)
and new_label_type.get("uri", "") == PREF_LABEL_LIST_ITEM.uri
and label_type.get("uri", "") == PREF_LABEL_LIST_ITEM.uri
and new_label_type.get("uri", "") == PREF_LABEL.uri
and label_type.get("uri", "") == PREF_LABEL.uri
and label_language.get("uri", "")
== new_label_language.get("uri", "")
):
raise ValidationError(
_("Only one preferred label per language is permitted.")
)
msg = _("Only one preferred label per language is permitted.")
raise ValidationError(msg)
return data

class LingoResourceSerializer(ArchesModelSerializer):
# Link any custom serializers here.
# TODO: put these back in, need some sort of check/wrapper
# appellative_status = SchemeLabelTileSerializer(
# many=True, required=False, allow_null=True
# )

class SchemeNoteSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["statement"]
fields = "__all__"


class SchemeNoteTileSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
graph_slug = "scheme"
root_node = "statement"
fields = "__all__"


class TextualWorkRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "textual_work"
graph_slug = None # generic
read_only_graphs = ["group", "person", "textual_work"] # optional attribute
nodegroups = "__all__"
fields = "__all__"


class ConceptStatementSerializer(ArchesTileSerializer):
class LingoTileSerializer(ArchesTileSerializer):
# Link any custom serializers here.
class Meta:
model = TileModel
graph_slug = "concept"
root_node = "statement"
fields = "__all__"


class ConceptSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "concept"
nodegroups = "__all__"
fields = "__all__"


class PersonRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "person"
nodegroups = "__all__"
fields = "__all__"


class GroupRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "group"
nodegroups = "__all__"
graph_slug = None # generic
root_node = None # generic
fields = "__all__"
Loading

0 comments on commit befa36b

Please sign in to comment.