mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
@@ -65,7 +65,7 @@ class SimpleActivitySerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class ActivityAttendanceSerializer(base.FlattenedModelSerializer):
|
class ActivityAttendanceSerializer(base.FlattenedModelSerializer):
|
||||||
activity = SimpleActivitySerializer()
|
activity = SimpleActivitySerializer()
|
||||||
person = people_serializers.SimplePersonSerializer()
|
person = people_serializers.PersonSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Activity.attendance_list.through
|
model = models.Activity.attendance_list.through
|
||||||
|
|||||||
@@ -7,16 +7,6 @@ from people import models
|
|||||||
from . import base
|
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 PersonSerializer(base.FlattenedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Person
|
model = models.Person
|
||||||
@@ -24,18 +14,57 @@ class PersonSerializer(base.FlattenedModelSerializer):
|
|||||||
'id',
|
'id',
|
||||||
# Name is excluded from exports
|
# Name is excluded from exports
|
||||||
# See https://github.com/Southampton-RSG/breccia-mapper/issues/35
|
# 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',
|
'nationality',
|
||||||
'country_of_residence',
|
'country_of_residence',
|
||||||
'organisation',
|
'organisation',
|
||||||
'organisation_started_date',
|
'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):
|
class RelationshipSerializer(base.FlattenedModelSerializer):
|
||||||
source = SimplePersonSerializer()
|
source = PersonSerializer()
|
||||||
target = SimplePersonSerializer()
|
target = PersonSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Relationship
|
model = models.Relationship
|
||||||
|
|||||||
@@ -30,6 +30,15 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Person Answer Sets</td>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-info"
|
||||||
|
href="{% url 'export:person-answer-set' %}">Export</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Relationships</td>
|
<td>Relationships</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ urlpatterns = [
|
|||||||
views.people.PersonExportView.as_view(),
|
views.people.PersonExportView.as_view(),
|
||||||
name='person'),
|
name='person'),
|
||||||
|
|
||||||
|
path('export/person-answer-sets',
|
||||||
|
views.people.PersonAnswerSetExportView.as_view(),
|
||||||
|
name='person-answer-set'),
|
||||||
|
|
||||||
path('export/relationships',
|
path('export/relationships',
|
||||||
views.people.RelationshipExportView.as_view(),
|
views.people.RelationshipExportView.as_view(),
|
||||||
name='relationship'),
|
name='relationship'),
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ class PersonExportView(base.CsvExportView):
|
|||||||
model = models.person.Person
|
model = models.person.Person
|
||||||
serializer_class = serializers.people.PersonSerializer
|
serializer_class = serializers.people.PersonSerializer
|
||||||
|
|
||||||
|
class PersonAnswerSetExportView(base.CsvExportView):
|
||||||
|
model = models.person.PersonAnswerSet
|
||||||
|
serializer_class = serializers.people.PersonAnswerSetSerializer
|
||||||
|
|
||||||
|
|
||||||
class RelationshipExportView(base.CsvExportView):
|
class RelationshipExportView(base.CsvExportView):
|
||||||
model = models.relationship.Relationship
|
model = models.relationship.Relationship
|
||||||
|
|||||||
Reference in New Issue
Block a user