Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added data in myprofile endpoint #223

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading