mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-09 16:24:39 +00:00
forbid past dates for product actions
This commit is contained in:
@@ -13,6 +13,7 @@ from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
from club.widgets.ajax_select import AutoCompleteSelectClub
|
||||
from core.models import User
|
||||
from core.views.forms import (
|
||||
FutureDateTimeField,
|
||||
NFCTextInput,
|
||||
SelectDate,
|
||||
SelectDateTime,
|
||||
@@ -185,7 +186,7 @@ class ScheduledProductActionForm(forms.ModelForm):
|
||||
labels = {"task": _("Action")}
|
||||
help_texts = {"task": ""}
|
||||
|
||||
trigger_at = forms.DateTimeField(
|
||||
trigger_at = FutureDateTimeField(
|
||||
label=_("Date and time of action"), widget=SelectDateTime
|
||||
)
|
||||
counters = forms.ModelMultipleChoiceField(
|
||||
@@ -206,7 +207,7 @@ class ScheduledProductActionForm(forms.ModelForm):
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
if not self.changed_data:
|
||||
if not self.changed_data or "trigger_at" in self.errors:
|
||||
return super().clean()
|
||||
if "trigger_at" in self.changed_data:
|
||||
if not self.instance.clocked_id:
|
||||
|
@@ -1385,3 +1385,13 @@ class ScheduledProductAction(PeriodicTask):
|
||||
def full_clean(self, *args, **kwargs):
|
||||
self.one_off = True # A product action should occur one time only
|
||||
return super().full_clean(*args, **kwargs)
|
||||
|
||||
def clean_clocked(self):
|
||||
if not self.clocked:
|
||||
raise ValidationError(_("Product actions must declare a clocked schedule."))
|
||||
|
||||
def validate_unique(self, exclude):
|
||||
# The checks done in PeriodicTask.validate_unique aren't
|
||||
# adapted in the case of scheduled product action,
|
||||
# so we skip it and execute directly Model.validate_unique
|
||||
return super(PeriodicTask, self).validate_unique(exclude=exclude)
|
||||
|
Reference in New Issue
Block a user