mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
@@ -7,16 +7,6 @@ from people import models
|
||||
from . import base
|
||||
|
||||
|
||||
class SimplePersonSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Person
|
||||
fields = [
|
||||
'id',
|
||||
# Name is excluded from exports
|
||||
# See https://github.com/Southampton-RSG/breccia-mapper/issues/35
|
||||
]
|
||||
|
||||
|
||||
class PersonSerializer(base.FlattenedModelSerializer):
|
||||
class Meta:
|
||||
model = models.Person
|
||||
@@ -24,18 +14,57 @@ class PersonSerializer(base.FlattenedModelSerializer):
|
||||
'id',
|
||||
# Name is excluded from exports
|
||||
# See https://github.com/Southampton-RSG/breccia-mapper/issues/35
|
||||
'gender',
|
||||
'age_group',
|
||||
]
|
||||
|
||||
|
||||
class PersonAnswerSetSerializer(base.FlattenedModelSerializer):
|
||||
person = PersonSerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.PersonAnswerSet
|
||||
fields = [
|
||||
'id',
|
||||
'person',
|
||||
'timestamp',
|
||||
'replaced_timestamp',
|
||||
'nationality',
|
||||
'country_of_residence',
|
||||
'organisation',
|
||||
'organisation_started_date',
|
||||
'job_title',
|
||||
'disciplines',
|
||||
'themes',
|
||||
'latitude',
|
||||
'longitude',
|
||||
]
|
||||
|
||||
@property
|
||||
def column_headers(self) -> typing.List[str]:
|
||||
headers = super().column_headers
|
||||
|
||||
# Add questions to columns
|
||||
for question in models.PersonQuestion.objects.all():
|
||||
headers.append(underscore(question.slug))
|
||||
|
||||
return headers
|
||||
|
||||
def to_representation(self, instance):
|
||||
rep = super().to_representation(instance)
|
||||
|
||||
try:
|
||||
# Add relationship question answers to data
|
||||
for answer in instance.question_answers.all():
|
||||
rep[underscore(answer.question.slug)] = underscore(answer.slug)
|
||||
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return rep
|
||||
|
||||
|
||||
class RelationshipSerializer(base.FlattenedModelSerializer):
|
||||
source = SimplePersonSerializer()
|
||||
target = SimplePersonSerializer()
|
||||
source = PersonSerializer()
|
||||
target = PersonSerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.Relationship
|
||||
|
||||
Reference in New Issue
Block a user