Skip to content

Commit

Permalink
Merge pull request #226 from ZdruzenieSTROM/Profile-export-serializer
Browse files Browse the repository at this point in the history
Added school info to participants
  • Loading branch information
kovacspe authored Nov 10, 2023
2 parents 1a0efb4 + 22c1706 commit dca3b43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 12 additions & 4 deletions personal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,17 @@ class Meta:


@ts_interface(context='personal')
class ProfileMailSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = ['first_name', 'last_name', 'nickname', 'email']
class ProfileExportSerializer(serializers.ModelSerializer):

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')
email = serializers.EmailField(source='user.email')

class Meta:
model = Profile
fields = ['school_name', 'school_abbreviation',
'school_street', 'school_city', 'school_zip_code',
'first_name', 'last_name', 'nickname', 'email']

0 comments on commit dca3b43

Please sign in to comment.