Skip to content

Commit

Permalink
style(api): update formatting
Browse files Browse the repository at this point in the history
Reformat lists, dicts, attributes for readability/
consistency; add whitespace.
  • Loading branch information
koeaw committed Sep 10, 2024
1 parent 7411591 commit 16133fd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 15 deletions.
57 changes: 46 additions & 11 deletions apis_ontology/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class PlaceDataSerializerMin(serializers.ModelSerializer):

class Meta:
model = Place
exclude = ["self_contenttype", "data_source"]
exclude = [
"self_contenttype",
"data_source",
]


class PlaceDataSerializer(PlaceDataSerializerMin):
Expand Down Expand Up @@ -145,21 +148,30 @@ class ArchiveDataSerializer(serializers.ModelSerializer):

class Meta:
model = Archive
exclude = ["self_contenttype", "data_source"]
exclude = [
"self_contenttype",
"data_source",
]


class PhysicalObjectDataSerializer(serializers.ModelSerializer):
archive = ArchiveDataSerializer(required=False, allow_null=True)

class Meta:
model = PhysicalObject
exclude = ["self_contenttype", "data_source"]
exclude = [
"self_contenttype",
"data_source",
]


class TopicDataSerializer(serializers.ModelSerializer):
class Meta:
model = Topic
exclude = ["self_contenttype", "data_source"]
exclude = [
"self_contenttype",
"data_source",
]


class PersonDataSerializer(serializers.ModelSerializer):
Expand All @@ -170,7 +182,10 @@ class PersonDataSerializer(serializers.ModelSerializer):

class Meta:
model = Person
exclude = ["self_contenttype", "data_source"]
exclude = [
"self_contenttype",
"data_source",
]


class WorkDetailSerializer(serializers.ModelSerializer):
Expand All @@ -180,24 +195,44 @@ class WorkDetailSerializer(serializers.ModelSerializer):
)
related_works = serializers.SerializerMethodField()
characters = CharacterDataSerializer(
required=False, allow_empty=True, many=True, source="character_data"
source="character_data",
required=False,
allow_empty=True,
many=True,
)
physical_objects = PhysicalObjectDataSerializer(
required=False, allow_empty=True, many=True, source="related_physical_objects"
source="related_physical_objects",
required=False,
allow_empty=True,
many=True,
)
topics = TopicDataSerializer(
required=False, allow_empty=True, many=True, source="related_topics"
source="related_topics",
required=False,
allow_empty=True,
many=True,
)
persons = PersonDataSerializer(
required=False, allow_empty=True, many=True, source="related_persons"
source="related_persons",
required=False,
allow_empty=True,
many=True,
)
places = PlaceDataSerializer(
required=False, allow_empty=True, many=True, source="related_places"
source="related_places",
required=False,
allow_empty=True,
many=True,
)

class Meta:
model = Work
exclude = ["self_contenttype", "data_source", "notes", "progress_status"]
exclude = [
"self_contenttype",
"data_source",
"notes",
"progress_status",
]

def get_related_works(self, obj) -> list[RelatedWorksDict]:
return list(obj.forward_work_relations) + list(obj.reverse_work_relations)
28 changes: 24 additions & 4 deletions apis_ontology/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def get_schema_operation_parameters(self, view):
"in": "query",
"description": "The initial index from which to return the results.",
"required": False,
"schema": {"type": "integer", "default": 0, "minimum": 0},
"schema": {
"type": "integer",
"default": 0,
"minimum": 0,
},
},
]
return params
Expand Down Expand Up @@ -137,7 +141,12 @@ def get_paginated_response_schema(self, schema):
},
},
},
"example": [{"key": "eng", "count": 100}],
"example": [
{
"key": "eng",
"count": 100,
}
],
},
"topic": {
"type": "array",
Expand All @@ -155,7 +164,12 @@ def get_paginated_response_schema(self, schema):
},
},
},
"example": [{"key": "Traum", "count": 3}],
"example": [
{
"key": "Traum",
"count": 3,
}
],
},
},
"type": "object",
Expand Down Expand Up @@ -272,6 +286,7 @@ def get_queryset(self):
Q(root_object_id=OuterRef("pk")),
~Q(uri__startswith="https://frischmuth-dev.acdh-dev.oeaw.ac.at"),
).values_list("uri", flat=True)

work_types = WorkType.objects.filter(
triple_set_from_obj__subj_id=OuterRef("pk"),
triple_set_from_obj__prop__name_forward__in=["has type"],
Expand All @@ -285,7 +300,12 @@ def get_queryset(self):
expression_publisher = Organisation.objects.filter(
triple_set_from_subj__obj_id=OuterRef("pk"),
triple_set_from_subj__prop__name_reverse__in=["has publisher"],
).values(json=JSONObject(id="id", name="name"))
).values(
json=JSONObject(
id="id",
name="name",
)
)

related_places = (
Place.objects.all()
Expand Down

0 comments on commit 16133fd

Please sign in to comment.