Skip to content

Commit

Permalink
Merge a7171cd into fb54f20
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt authored Oct 4, 2021
2 parents fb54f20 + a7171cd commit 9399218
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
32 changes: 32 additions & 0 deletions ephios/core/migrations/0013_auto_20211003_1734.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.7 on 2021-10-03 15:34

from django.db import migrations, models

import ephios.core.models.users


class Migration(migrations.Migration):

dependencies = [
("core", "0012_rename_included_qualifications_qualification_includes"),
]

operations = [
migrations.AddField(
model_name="abstractparticipation",
name="individual_end_time",
field=models.DateTimeField(null=True, verbose_name="end time"),
),
migrations.AddField(
model_name="abstractparticipation",
name="individual_start_time",
field=models.DateTimeField(null=True, verbose_name="start time"),
),
migrations.AlterField(
model_name="qualificationgrant",
name="expires",
field=ephios.core.models.users.ExpirationDateField(
blank=True, null=True, verbose_name="expiration date"
),
),
]
22 changes: 22 additions & 0 deletions ephios/core/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
SlugField,
TextField,
)
from django.db.models.functions import Coalesce
from django.utils import formats
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from dynamic_preferences.models import PerInstancePreferenceModel
from guardian.shortcuts import assign_perm
from polymorphic.managers import PolymorphicManager
from polymorphic.models import PolymorphicModel

from ephios.extra.json import CustomJSONDecoder, CustomJSONEncoder
Expand Down Expand Up @@ -136,6 +138,18 @@ def activate(self):
register_model_for_logging(Event, ModelFieldsLogConfig())


class ParticipationManager(PolymorphicManager):
def get_queryset(self):
return (
super()
.get_queryset()
.annotate(
start_time=Coalesce("individual_start_time", "shift__start_time"),
end_time=Coalesce("individual_end_time", "shift__end_time"),
)
)


class AbstractParticipation(PolymorphicModel):
class States(models.IntegerChoices):
REQUESTED = 0, _("requested")
Expand All @@ -154,12 +168,20 @@ def labels_dict(cls):
state = IntegerField(_("state"), choices=States.choices)
data = models.JSONField(default=dict, verbose_name=_("Signup data"))

"""
Overwrites shift time. Use `start_time` and `end_time` to get the applicable time (implemented with a custom manager).
"""
individual_start_time = DateTimeField(_("start time"), null=True)
individual_end_time = DateTimeField(_("end time"), null=True)

"""
The finished flag is used to make sure the participation_finished signal is only sent out once, even
if the shift time is changed afterwards.
"""
finished = models.BooleanField(default=False, verbose_name=_("finished"))

objects = ParticipationManager()

@property
def hours_value(self):
td = self.shift.end_time - self.shift.start_time
Expand Down
12 changes: 8 additions & 4 deletions ephios/core/signup/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,13 @@ def perform_signup(self, participant: AbstractParticipant, **kwargs) -> Abstract

if errors := self.get_signup_errors(participant):
raise ParticipationError(errors)
participation = self._configure_participation(
self.get_participation_for(participant), **kwargs
)
participation = self.get_participation_for(participant)

for attr in ("start_time", "end_time"):
if attr in kwargs:
setattr(participation, f"individual_{attr}", kwargs.pop(attr))

participation = self._configure_participation(participation, **kwargs)
participation.save()
ResponsibleParticipationRequested.send(participation)
return participation
Expand Down Expand Up @@ -533,7 +537,7 @@ class SignupStats:
max_count: Optional[int] # None means infinite max

@classproperty
def ZERO(self):
def ZERO(cls): # pylint: disable=no-self-argument
return SignupStats(
requested_count=0,
confirmed_count=0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.7 on 2021-10-03 15:34

from django.db import migrations

import ephios.core.models.users


class Migration(migrations.Migration):

dependencies = [
("eventautoqualification", "0003_alter_eventautoqualificationconfiguration_id"),
]

operations = [
migrations.AlterField(
model_name="eventautoqualificationconfiguration",
name="expiration_date",
field=ephios.core.models.users.ExpirationDateField(
blank=True, null=True, verbose_name="Expiration date"
),
),
]

0 comments on commit 9399218

Please sign in to comment.