-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2455 from dotkom/feat/application-periods
Add application periods for committee applications
- Loading branch information
Showing
18 changed files
with
981 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import django_filters as filters | ||
|
||
from ..models import CommitteeApplicationPeriod | ||
|
||
|
||
class CommitteeApplicationPeriodFilter(filters.FilterSet): | ||
accepting_applications = filters.BooleanFilter(field_name="accepting_applications") | ||
actual_deadline__lte = filters.DateTimeFilter( | ||
field_name="actual_deadline", lookup_expr="lte" | ||
) | ||
actual_deadline__gte = filters.DateTimeFilter( | ||
field_name="actual_deadline", lookup_expr="lte" | ||
) | ||
|
||
class Meta: | ||
model = CommitteeApplicationPeriod | ||
fields = { | ||
"start": ["gte", "lte"], | ||
"deadline": ["gte", "lte"], | ||
"accepting_applications": "exact", | ||
"actual_deadline__lte": "exact", | ||
"actual_deadline__gte": "exact", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
from django.utils import timezone | ||
|
||
from apps.dashboard.widgets import DatetimePickerInput, multiple_widget_generator | ||
|
||
from ..models import CommitteeApplicationPeriod | ||
|
||
|
||
class CommitteeApplicationPeriodForm(forms.ModelForm): | ||
def clean(self): | ||
cleaned_data = super().clean() | ||
data = cleaned_data.copy() | ||
data.pop("committees") | ||
period = CommitteeApplicationPeriod(**data) | ||
|
||
minimum_duration = timezone.timedelta(days=1) | ||
if period.start + minimum_duration >= period.deadline: | ||
raise ValidationError("En opptaksperiode må vare i minst én dag") | ||
|
||
actual_deadline = period.deadline + period.deadline_delta | ||
overlapping_periods = CommitteeApplicationPeriod.objects.filter_overlapping( | ||
period.start, actual_deadline | ||
) | ||
|
||
if overlapping_periods.exists(): | ||
raise ValidationError("Opptaksperioder kan ikke overlappe med hverandre") | ||
|
||
return cleaned_data | ||
|
||
class Meta: | ||
model = CommitteeApplicationPeriod | ||
fields = ("title", "start", "deadline", "deadline_delta", "committees") | ||
|
||
dtp_fields = (("start", {}), ("deadline", {})) | ||
widgetlist = [(DatetimePickerInput, dtp_fields)] | ||
|
||
widgets = multiple_widget_generator(widgetlist) |
Oops, something went wrong.