Skip to content

Commit

Permalink
fix: fix registration-form serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Dec 13, 2024
1 parent 035440f commit ba22c96
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 20 deletions.
18 changes: 18 additions & 0 deletions apps/fsm/migrations/0234_alter_paper_paper_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2024-12-13 15:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fsm', '0233_form_participant_limit'),
]

operations = [
migrations.AlterField(
model_name='paper',
name='paper_type',
field=models.CharField(choices=[('RegistrationForm', 'Registrationform'), ('Hint', 'Hint'), ('WidgetHint', 'Widgethint'), ('Article', 'Article'), ('General', 'General')], default='General', max_length=25),
),
]
1 change: 0 additions & 1 deletion apps/fsm/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class Paper(PolymorphicModel, ObjectMixin):

class PaperType(models.TextChoices):
RegistrationForm = 'RegistrationForm'
State = 'State'
Hint = 'Hint'
WidgetHint = 'WidgetHint'
Article = 'Article'
Expand Down
12 changes: 12 additions & 0 deletions apps/fsm/serializers/form/form_polymorphic_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_polymorphic.serializers import PolymorphicSerializer

from apps.fsm.models.form import Form, RegistrationForm
from apps.fsm.serializers.form.form_serializer import FormSerializer
from apps.fsm.serializers.form.registration_form_serializer import RegistrationFormSerializer


class FormPolymorphicSerializer(PolymorphicSerializer):
model_serializer_mapping = {
Form: FormSerializer,
RegistrationForm: RegistrationFormSerializer,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class FormSerializer(PaperSerializer):
class Meta(PaperSerializer.Meta):
model = Form
ref_name = 'registration_form'
fields = PaperSerializer.Meta.get_fields() + \
fields = [field for field in PaperSerializer.Meta.fields if field != 'widgets'] +\
['audience_type', 'start_date', 'end_date']
read_only_fields = PaperSerializer.Meta.read_only_fields + []
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from apps.fsm.models.base import Paper
from apps.fsm.serializers.form_serializer import FormSerializer
from apps.fsm.serializers.form.form_serializer import FormSerializer
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import transaction
from rest_framework import serializers
Expand Down Expand Up @@ -31,6 +31,6 @@ def create(self, validated_data):

class Meta(FormSerializer.Meta):
model = RegistrationForm
fields = FormSerializer.Meta.get_fields() + ['min_grade', 'max_grade', 'program', 'accepting_status',
'certificate_templates', 'has_certificate', 'certificates_ready', 'gender_partition_status']
fields = FormSerializer.Meta.fields + ['min_grade', 'max_grade', 'program', 'accepting_status',
'certificate_templates', 'has_certificate', 'certificates_ready', 'gender_partition_status']
read_only_fields = FormSerializer.Meta.read_only_fields + []
4 changes: 2 additions & 2 deletions apps/fsm/serializers/papers/article_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def to_representation(self, instance):
class Meta(PaperSerializer.Meta):
model = Article
ref_name = 'article'
fields = PaperSerializer.Meta.get_fields() + ['name', 'description', 'tags',
'is_draft', 'publisher', 'cover_page']
fields = [field for field in PaperSerializer.Meta.fields if field != 'widgets'] +\
['name', 'description', 'tags', 'is_draft', 'publisher', 'cover_page']
read_only_fields = PaperSerializer.Meta.read_only_fields + []
3 changes: 2 additions & 1 deletion apps/fsm/serializers/papers/hint_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class HintSerializer(PaperSerializer):

class Meta(PaperSerializer.Meta):
model = Hint
fields = PaperSerializer.Meta.get_fields() + ['reference']
fields = [field for field in PaperSerializer.Meta.fields if field != 'widgets'] +\
['reference']
read_only_fields = PaperSerializer.Meta.read_only_fields + []
4 changes: 1 addition & 3 deletions apps/fsm/serializers/papers/paper_polymorphic_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from apps.fsm.serializers.papers.article_serializer import ArticleSerializer
from apps.fsm.serializers.papers.hint_serializer import HintSerializer
from apps.fsm.serializers.papers.paper_serializer import PaperSerializer
from apps.fsm.serializers.papers.registration_form_serializer import RegistrationFormSerializer
from apps.widgets.serializers.widget_hint_serializer import WidgetHintSerializer


class PaperPolymorphicSerializer(PolymorphicSerializer):
model_serializer_mapping = {
'Paper': PaperSerializer,
'RegistrationForm': RegistrationFormSerializer,
'General': PaperSerializer,
'Article': ArticleSerializer,
'Hint': HintSerializer,
'WidgetHint': WidgetHintSerializer,
Expand Down
3 changes: 0 additions & 3 deletions apps/fsm/serializers/papers/paper_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class Meta:
fields = ['id', 'widgets', 'paper_type', 'creator']
read_only_fields = ['id']

def get_fields():
return [field for field in PaperSerializer.Meta.fields if field != 'widgets']


class ChangeWidgetOrderSerializer(serializers.Serializer):
order = serializers.ListField(
Expand Down
2 changes: 1 addition & 1 deletion apps/fsm/serializers/program_serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework.exceptions import ParseError
from rest_framework import serializers

from apps.fsm.serializers.papers.registration_form_serializer import RegistrationFormSerializer
from apps.fsm.serializers.form.registration_form_serializer import RegistrationFormSerializer
from apps.fsm.serializers.program_contact_info_serializer import ProgramContactInfoSerializer
from apps.fsm.utils.utils import add_admin_to_program
from errors.error_codes import serialize_error
Expand Down
5 changes: 2 additions & 3 deletions apps/fsm/views/form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from rest_framework.permissions import AllowAny
from rest_framework.exceptions import PermissionDenied
from drf_yasg.utils import swagger_auto_schema
from django.db import transaction

from apps.fsm.models.form import Form
from apps.fsm.serializers.form_serializer import FormSerializer
from apps.fsm.serializers.form.form_polymorphic_serializer import FormPolymorphicSerializer
from apps.fsm.utils.submission.form_submission_handler import FormSubmissionHandler
from apps.response.serializers.answer_sheet import AnswerSheetSerializer


class FormViewSet(ModelViewSet):
serializer_class = FormSerializer
serializer_class = FormPolymorphicSerializer
queryset = Form.objects.all()
permission_classes = [AllowAny]

Expand Down
2 changes: 1 addition & 1 deletion apps/fsm/views/registration_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from apps.fsm.serializers.answer_sheet_serializers import RegistrationReceiptSerializer
from apps.fsm.models import RegistrationForm, transaction, RegistrationReceipt, Invitation
from apps.fsm.permissions import IsRegistrationFormModifier
from apps.fsm.serializers.papers.registration_form_serializer import RegistrationFormSerializer
from apps.fsm.serializers.form.registration_form_serializer import RegistrationFormSerializer
from apps.fsm.serializers.team_serializer import InvitationSerializer
from apps.fsm.pagination import RegistrationReceiptSetPagination

Expand Down
3 changes: 2 additions & 1 deletion apps/widgets/serializers/widget_hint_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class WidgetHintSerializer(PaperSerializer):

class Meta(PaperSerializer.Meta):
model = WidgetHint
fields = PaperSerializer.Meta.get_fields() + ['reference']
fields = [field for field in PaperSerializer.Meta.fields if field != 'widgets'] +\
['reference']
read_only_fields = PaperSerializer.Meta.read_only_fields + []

0 comments on commit ba22c96

Please sign in to comment.