Skip to content

Commit

Permalink
Merge pull request #223 from ZdruzenieSTROM/myprofile-222
Browse files Browse the repository at this point in the history
Added data in myprofile endpoint
  • Loading branch information
kovacspe authored Nov 10, 2023
2 parents 2b7da9a + 9375766 commit 1a0efb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ node_modules

# Generovane TypeScript typy pre FE
*.ts

StromBackend/
.venv
15 changes: 9 additions & 6 deletions personal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from competition.models import Grade
from personal.models import County, District, Profile, School

#from competition.serializers import GradeSerializer


@ts_interface(context='personal')
class CountySerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -50,20 +48,20 @@ def get_verbose_name(self, obj):

@ts_interface(context='personal')
class ProfileSerializer(serializers.ModelSerializer):
#grade_info = GradeSerializer(many=True)
grade = serializers.IntegerField()
grade_name = serializers.SerializerMethodField('get_grade_name')
school = SchoolProfileSerializer(many=False, read_only=True)
is_student = serializers.SerializerMethodField('get_is_student')
has_school = serializers.SerializerMethodField('get_has_school')
school_id = serializers.IntegerField()
email = serializers.EmailField(source='user.email')

class Meta:
model = Profile
fields = ['first_name', 'last_name', 'nickname', 'school',
fields = ['grade_name', 'id', 'email', 'first_name', 'last_name', 'nickname', 'school',
'phone', 'parent_phone', 'gdpr', 'grade', 'is_student', 'has_school', 'school_id']
read_only_fields = ['first_name', 'last_name',
read_only_fields = ['grade_name', 'id', 'first_name', 'last_name',
'email', 'is_student', 'has_school', 'school'] # 'year_of_graduation',
email = serializers.EmailField(source='user.email')

extra_kwargs = {
'grade': {
Expand All @@ -80,6 +78,11 @@ def get_is_student(self, obj):
def get_has_school(self, obj):
return obj.school != School.objects.get(pk=0) and obj.school != School.objects.get(pk=1)

def get_grade_name(self, obj):
return Grade.get_grade_by_year_of_graduation(
year_of_graduation=obj.year_of_graduation
).name

def update(self, instance, validated_data):
grade = Grade.objects.get(pk=validated_data.pop('grade'))
school = School.objects.get(pk=validated_data.pop('school_id'))
Expand Down

0 comments on commit 1a0efb4

Please sign in to comment.