Skip to content

Commit

Permalink
Cope with serializer format change
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Feb 13, 2025
1 parent 02e1f9d commit 886ad4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
19 changes: 14 additions & 5 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from arches.app.models.models import ResourceInstance, TileModel
from arches.app.models.serializers import ArchesModelSerializer, ArchesTileSerializer

from arches_controlled_lists.datatypes.datatypes import ReferenceDataType
from arches_controlled_lists.datatypes.datatypes import Reference, ReferenceDataType
from arches_controlled_lists.models import ListItem


# Generic serializers for Lingo.
class LingoResourceSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = None # generic
graph_slug = None
nodegroups = "__all__"
fields = "__all__"

Expand All @@ -26,12 +26,13 @@ class Meta:

def validate_appellative_status(self, data):
if data:
# TODO: consider having serializer run to_python().
if new_label_languages := ReferenceDataType().to_python(
new_label_lang = None
new_label_type = None
if new_label_languages := self.get_reference_object(
data.get("appellative_status_ascribed_name_language")
):
new_label_lang = new_label_languages[0]
if new_label_types := ReferenceDataType().to_python(
if new_label_types := self.get_reference_object(
data.get("appellative_status_ascribed_relation")
):
new_label_type = new_label_types[0]
Expand All @@ -41,6 +42,14 @@ def validate_appellative_status(self, data):

return data

@staticmethod
def get_reference_object(data) -> Reference:
# TODO: serializer should just do this itself, only waiting to tackle:
# https://github.com/archesproject/arches/issues/10851#issuecomment-2427305853
datatype_instance = ReferenceDataType()
transformed = datatype_instance.transform_value_for_tile(data)
return datatype_instance.to_python(transformed)

@staticmethod
def _check_pref_label_uniqueness(data, new_label_language, new_label_type):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ withDefaults(
<span v-if="value instanceof Array">
<span
v-for="val in value"
:key="val.list_id"
:key="val.list_item_id"
>
<span>{{ val.labels[0].value }}</span>
<span>{{ val.display_value }}</span>
</span>
</span>
<span v-else-if="value">
<span>{{ (value as ControlledListItem).labels[0].value }}</span>
<span>{{ value.display_value }}</span>
</span>
<span v-else>
<span>{{ $gettext("None") }}</span>
Expand Down
8 changes: 2 additions & 6 deletions arches_lingo/src/arches_lingo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export interface ControlledListItemLabelValue {
}

export interface ControlledListItem {
item_id?: string;
list_id: string;
uri: string;
sortorder?: number;
guide?: boolean;
labels: ControlledListItemLabelValue[];
list_item_id: string;
display_value: string;
}

export interface ControlledListItemResult {
Expand Down

0 comments on commit 886ad4c

Please sign in to comment.