Skip to content

Commit

Permalink
EmailField na Profile zmeneny na readonly (#448)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Masrna <[email protected]>
  • Loading branch information
kovacspe and michalmasrna1 authored Nov 23, 2024
1 parent b1c9959 commit 940118b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 4.2.15 on 2024-11-23 19:43

import base.models
import competition.models
import django.core.files.storage
from django.db import migrations

import base.models
import competition.models


class Migration(migrations.Migration):

Expand All @@ -16,11 +17,13 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='solution',
name='corrected_solution',
field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(base_url='/protected/', location='C:\\Users\\petko\\Documents\\GitHub\\webstrom\\webstrom-backend\\protected_media/'), upload_to=competition.models.get_corrected_solution_path, verbose_name='opravené riešenie'),
field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(
base_url='/protected/', location='C:\\Users\\petko\\Documents\\GitHub\\webstrom\\webstrom-backend\\protected_media/'), upload_to=competition.models.get_corrected_solution_path, verbose_name='opravené riešenie'),
),
migrations.AlterField(
model_name='solution',
name='solution',
field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(base_url='/protected/', location='C:\\Users\\petko\\Documents\\GitHub\\webstrom\\webstrom-backend\\protected_media/'), upload_to=competition.models.get_solution_path, verbose_name='účastnícke riešenie'),
field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(
base_url='/protected/', location='C:\\Users\\petko\\Documents\\GitHub\\webstrom\\webstrom-backend\\protected_media/'), upload_to=competition.models.get_solution_path, verbose_name='účastnícke riešenie'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.15 on 2024-11-23 23:11

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('personal', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='parent_phone',
field=models.CharField(blank=True, help_text='Telefonné číslo v medzinárodnom formáte (napr. +421 123 456 789).', max_length=32, null=True, validators=[django.core.validators.RegexValidator(message='Zadaj telefónne číslo vo formáte +421 123 456 789 alebo 0912 345 678.', regex='^(\\+\\d{1,3}\\d{9})$')], verbose_name='telefónne číslo na rodiča'),
),
migrations.AlterField(
model_name='profile',
name='phone',
field=models.CharField(blank=True, help_text='Telefonné číslo v medzinárodnom formáte (napr. +421 123 456 789).', max_length=32, null=True, validators=[django.core.validators.RegexValidator(message='Zadaj telefónne číslo vo formáte +421 123 456 789 alebo 0912 345 678.', regex='^(\\+\\d{1,3}\\d{9})$')], verbose_name='telefónne číslo'),
),
]
4 changes: 2 additions & 2 deletions personal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ class Meta:
verbose_name='rok maturity')

phone = models.CharField(
verbose_name='telefónne číslo', max_length=32, blank=True,
verbose_name='telefónne číslo', max_length=32, blank=True, null=True,
validators=[phone_number_validator],
help_text='Telefonné číslo v medzinárodnom formáte (napr. +421 123 456 789).')

parent_phone = models.CharField(
verbose_name='telefónne číslo na rodiča', max_length=32, blank=True,
verbose_name='telefónne číslo na rodiča', max_length=32, blank=True, null=True,
validators=[phone_number_validator],
help_text='Telefonné číslo v medzinárodnom formáte (napr. +421 123 456 789).')

Expand Down
13 changes: 7 additions & 6 deletions personal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class ProfileSerializer(serializers.ModelSerializer):
is_student = serializers.SerializerMethodField('get_is_student')
has_school = serializers.SerializerMethodField('get_has_school')
school_id = serializers.IntegerField()
email = serializers.EmailField(source='user.email')
email = serializers.EmailField(source='user.email', read_only=True)
verbose_name = serializers.SerializerMethodField('get_verbose_name')

class Meta:
model = Profile
fields = ['grade_name', 'id', 'email', 'first_name', 'last_name', 'school',
'phone', 'parent_phone', 'grade', 'is_student', 'has_school',
'school_id', 'verbose_name']
read_only_fields = ['grade_name', 'id', 'first_name', 'last_name',
'email', 'is_student', 'has_school', 'school', 'verbose_name']
read_only_fields = ['grade_name', 'id', 'email',
'is_student', 'has_school', 'school', 'verbose_name']

extra_kwargs = {
'grade': {
Expand Down Expand Up @@ -118,13 +118,14 @@ def update(self, instance, validated_data):

def create(self, validated_data):
grade = Grade.objects.get(pk=validated_data['grade'])
school = School.objects.get(pk=validated_data['school_id'])
return Profile.objects.create(
first_name=validated_data['first_name'],
last_name=validated_data['last_name'],
school=validated_data['school'],
school=school,
year_of_graduation=grade.get_year_of_graduation_by_date(),
phone=validated_data['phone'],
parent_phone=validated_data['parent_phone']
phone=validated_data.get('phone', None),
parent_phone=validated_data.get('parent_phone', None),
)


Expand Down

0 comments on commit 940118b

Please sign in to comment.