Skip to content

Commit

Permalink
Optional registration link when creating event
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Mihálik committed Nov 16, 2023
1 parent 300f2d1 commit 0481fe9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
3 changes: 0 additions & 3 deletions competition/fixtures/registration_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"model": "competition.RegistrationLink",
"pk": 0,
"fields": {
"event": 0,
"start": "2020-04-01T20:00:00.000Z",
"end": "2021-10-01T20:00:00.000Z",
"url": "https://seminar.strom.sk/sk/prispevky/",
Expand All @@ -14,7 +13,6 @@
"model": "competition.RegistrationLink",
"pk": 1,
"fields": {
"event": 1,
"start": "2021-11-01T20:00:00.000Z",
"end": "2021-12-01T20:00:00.000Z",
"url": "https://seminar.strom.sk/sk/prispevky/",
Expand All @@ -25,7 +23,6 @@
"model": "competition.RegistrationLink",
"pk": 2,
"fields": {
"event": 2,
"start": "2020-04-01T20:00:00.000Z",
"end": "2020-05-01T20:00:00.000Z",
"url": "https://seminar.strom.sk/sk/prispevky/",
Expand Down
9 changes: 6 additions & 3 deletions competition/fixtures/semesters.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"school_year": "2019/2020",
"start": "2020-01-01T20:00:00+02:00",
"end": "2025-06-01T20:00:00+02:00",
"season_code": 1
"season_code": 1,
"registration_link": 0
}
},
{
Expand Down Expand Up @@ -177,7 +178,8 @@
"school_year": "2020/2021",
"start": "2020-10-08T00:00:00+02:00",
"end": "2020-12-02T00:00:00+02:00",
"season_code": 0
"season_code": 0,
"registration_link": 1
}
},
{
Expand Down Expand Up @@ -324,7 +326,8 @@
"school_year": "2018/2019",
"start": "2019-02-26T00:00:00+02:00",
"end": "2019-04-24T00:00:00+02:00",
"season_code": 1
"season_code": 1,
"registration_link": 2
}
},
{
Expand Down
11 changes: 8 additions & 3 deletions competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ class Meta:
start = models.DateTimeField(verbose_name='dátum začiatku súťaže')
end = models.DateTimeField(verbose_name='dátum konca súťaže')
additional_name = models.CharField(
max_length=50, verbose_name='Prísvlastok súťaže', null=True, blank=True)
max_length=50, verbose_name='Prívlastok súťaže', null=True, blank=True)

registration_link = models.OneToOneField(
"competition.RegistrationLink",
on_delete=models.SET_NULL,
null=True,
)

objects = ActiveQuerySet.as_manager()

Expand Down Expand Up @@ -634,14 +640,13 @@ class Meta:
verbose_name = 'link na registráciu'
verbose_name_plural = 'linky na registráciu'

event = models.OneToOneField(
Event, related_name='registration_link', on_delete=models.CASCADE)
url = models.URLField(verbose_name='url registrácie')
start = models.DateTimeField(verbose_name='Začiatok registrácie')
end = models.DateTimeField(verbose_name='Koniec registrácie')
additional_info = models.TextField(verbose_name='Doplňujúce informácie')

def can_user_modify(self, user):
# pylint: disable=no-member
return self.event.can_user_modify(user)


Expand Down
20 changes: 17 additions & 3 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework import serializers

from competition import models
from competition.models import Problem
from competition.models import Problem, RegistrationLink, Event
from personal.serializers import ProfileShortSerializer, SchoolShortSerializer


Expand Down Expand Up @@ -43,13 +43,27 @@ class Meta:

@ts_interface(context='competition')
class EventSerializer(ModelWithParticipationSerializer):
publication_set = PublicationSerializer(many=True)
registration_link = RegistrationLinkSerializer(many=False)
publication_set = PublicationSerializer(many=True, read_only=True)
registration_link = RegistrationLinkSerializer(
many=False,
required=False,
allow_null=True,
)

class Meta:
model = models.Event
fields = '__all__'

def create(self, validated_data):
registration_link = RegistrationLink.objects.create(
**validated_data.pop('registration_link'),
)

return Event.objects.create(
registration_link=registration_link,
**validated_data,
)


@ts_interface(context='competition')
class CompetitionTypeSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 0481fe9

Please sign in to comment.