From 1f13567222375594c1b2b8441199f545788209be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjam=C3=ADn=20Mravec?= Date: Fri, 10 Nov 2023 18:26:36 +0100 Subject: [PATCH 1/2] Added school info to participants --- competition/views.py | 4 ++-- personal/serializers.py | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/competition/views.py b/competition/views.py index 81e0b662..676d8d41 100644 --- a/competition/views.py +++ b/competition/views.py @@ -32,7 +32,7 @@ SeriesWithProblemsSerializer, SolutionSerializer) from personal.models import Profile, School -from personal.serializers import ProfileMailSerializer, SchoolSerializer +from personal.serializers import ProfileExportSerializer, SchoolSerializer from webstrom.settings import EMAIL_ALERT, EMAIL_NO_REPLY # pylint: disable=unused-argument @@ -687,7 +687,7 @@ def participants(self, request, pk=None): solution.semester_registration.profile.pk) profiles = Profile.objects.only("user").filter(pk__in=participants_id) - serializer = ProfileMailSerializer(profiles, many=True) + serializer = ProfileExportSerializer(profiles, many=True) return Response(serializer.data) def post(self, request, format_post): diff --git a/personal/serializers.py b/personal/serializers.py index 3fec5b52..e1f88509 100644 --- a/personal/serializers.py +++ b/personal/serializers.py @@ -152,11 +152,25 @@ class Meta: model = Profile fields = ['first_name', 'last_name', 'nickname'] - @ts_interface(context='personal') -class ProfileMailSerializer(serializers.ModelSerializer): +class ProfileExportSerializer(serializers.ModelSerializer): + school_code = serializers.CharField(source='school.code') + school_name = serializers.CharField(source='school.name') + school_abbreviation = serializers.CharField(source='school.abbreviation') + + school_street = serializers.CharField(source='school.street') + school_city = serializers.CharField(source='school.city') + school_zip_code = serializers.CharField(source='school.zip_code') + school_email = serializers.CharField(source='school.email') + + school_district = serializers.CharField(source='school.district') + + email = serializers.EmailField(source='user.email') + class Meta: model = Profile - fields = ['first_name', 'last_name', 'nickname', 'email'] + fields = ['school_code', 'school_name', 'school_abbreviation', + 'school_street', 'school_city', 'school_zip_code', 'school_email', + 'school_district', 'first_name', 'last_name', 'nickname', 'email'] + - email = serializers.EmailField(source='user.email') From 22c1706f13dbcbff80e4094d29a851b8f6dae087 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Fri, 10 Nov 2023 18:32:52 +0100 Subject: [PATCH 2/2] Remove school detailed fields --- personal/serializers.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/personal/serializers.py b/personal/serializers.py index 88cd8298..f0c7b0fd 100644 --- a/personal/serializers.py +++ b/personal/serializers.py @@ -155,25 +155,19 @@ class Meta: model = Profile fields = ['first_name', 'last_name', 'nickname'] + @ts_interface(context='personal') class ProfileExportSerializer(serializers.ModelSerializer): - school_code = serializers.CharField(source='school.code') + school_name = serializers.CharField(source='school.name') school_abbreviation = serializers.CharField(source='school.abbreviation') - school_street = serializers.CharField(source='school.street') school_city = serializers.CharField(source='school.city') school_zip_code = serializers.CharField(source='school.zip_code') - school_email = serializers.CharField(source='school.email') - - school_district = serializers.CharField(source='school.district') - email = serializers.EmailField(source='user.email') class Meta: model = Profile - fields = ['school_code', 'school_name', 'school_abbreviation', - 'school_street', 'school_city', 'school_zip_code', 'school_email', - 'school_district', 'first_name', 'last_name', 'nickname', 'email'] - - + fields = ['school_name', 'school_abbreviation', + 'school_street', 'school_city', 'school_zip_code', + 'first_name', 'last_name', 'nickname', 'email']