Subevents: Validate time order of product availability

This commit is contained in:
Raphael Michel
2023-02-07 15:29:11 +01:00
parent 82dd417a8e
commit 9a56874083
4 changed files with 18 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ from datetime import datetime
from urllib.parse import urlencode
from django import forms
from django.core.exceptions import ValidationError
from django.forms import formset_factory
from django.forms.utils import ErrorDict
from django.urls import reverse
@@ -273,6 +274,13 @@ class SubEventItemForm(SubEventItemOrVariationFormMixin, forms.ModelForm):
'available_until': SplitDateTimeField,
}
def clean(self):
d = super().clean()
if d.get('available_from') and d.get('available_until'):
if d.get('available_from') > d.get('available_until'):
raise ValidationError(_('The end of availability should be after the start of availability.'))
return d
class SubEventItemVariationForm(SubEventItemOrVariationFormMixin, forms.ModelForm):
def __init__(self, *args, **kwargs):
@@ -293,6 +301,13 @@ class SubEventItemVariationForm(SubEventItemOrVariationFormMixin, forms.ModelFor
'available_until': SplitDateTimeField,
}
def clean(self):
d = super().clean()
if d.get('available_from') and d.get('available_until'):
if d.get('available_from') > d.get('available_until'):
raise ValidationError(_('The end of availability should be after the start of availability.'))
return d
class BulkSubEventItemForm(SubEventItemForm):
rel_available_from = RelativeDateTimeField(

View File

@@ -487,6 +487,7 @@
{% trans "These settings are optional, if you leave them empty, the default values from the product settings will be used." %}
</p>
{% for f in itemvar_forms %}
{% bootstrap_form_errors f %}
<div class="form-group subevent-itemvar-group">
<label class="col-md-3 control-label" for="id_{{ f.prefix }}-price">
{% if f.variation %}{{ f.item }} {{ f.variation }}{% else %}{{ f.item }}{% endif %}

View File

@@ -151,6 +151,7 @@
<fieldset>
<legend>{% trans "Item prices" %}</legend>
{% for f in itemvar_forms %}
{% bootstrap_form_errors f %}
<div class="form-group subevent-itemvar-group">
<label class="col-md-3 control-label" for="id_{{ f.prefix }}-price">
{% if f.variation %}{{ f.item }} {{ f.variation }}{% else %}{{ f.item }}{% endif %}

View File

@@ -129,6 +129,7 @@
{% trans "These settings are optional, if you leave them empty, the default values from the product settings will be used." %}
</p>
{% for f in itemvar_forms %}
{% bootstrap_form_errors f %}
<div class="form-group subevent-itemvar-group">
<label class="col-md-3 control-label" for="id_{{ f.prefix }}-price">
{% if f.variation %}{{ f.item }} {{ f.variation }}{% else %}{{ f.item }}{% endif %}