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 12, 2023
1 parent 300f2d1 commit 43b43d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
38 changes: 21 additions & 17 deletions competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ def __str__(self):
return self.name


class RegistrationLink(models.Model):
class Meta:
verbose_name = 'link na registráciu'
verbose_name_plural = 'linky na registráciu'

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):
return self.event.can_user_modify(user)


class Event(models.Model):
"""
Slúži na označenie instancie súťaže (Napríklad: Matboj 2020,
Expand Down Expand Up @@ -150,7 +164,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.ForeignKey(
RegistrationLink,
on_delete=models.SET_NULL,
null=True,
)

objects = ActiveQuerySet.as_manager()

Expand Down Expand Up @@ -629,22 +649,6 @@ def make_name_on_creation(sender, instance, created, **kwargs):
instance.generate_name()


class RegistrationLink(models.Model):
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):
return self.event.can_user_modify(user)


class ProblemCorrection(models.Model):
# TODO: Add images
class Meta:
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 43b43d9

Please sign in to comment.