Subevent and quota creation: Prevent common mistakes

This commit is contained in:
Raphael Michel
2021-05-19 16:06:12 +02:00
parent 670389c8ae
commit 9809b88b52
2 changed files with 18 additions and 3 deletions

View File

@@ -213,7 +213,7 @@ class QuotaForm(I18nModelForm):
self.fields['itemvars'] = forms.MultipleChoiceField(
label=_('Products'),
required=False,
required=True,
choices=choices,
widget=forms.CheckboxSelectMultiple
)

View File

@@ -263,7 +263,6 @@ class SubEventEditorMixin(MetaDataEditorMixin):
@cached_property
def formset(self):
extra = 0
kwargs = {}
if self.copy_from and self.request.method != "POST":
@@ -277,7 +276,14 @@ class SubEventEditorMixin(MetaDataEditorMixin):
]
} for q in self.copy_from.quotas.prefetch_related('items', 'variations')
]
extra = len(kwargs['initial'])
extra = len(kwargs['initial']) - 1
else:
kwargs['initial'] = [
{
'name': _('Tickets'),
}
]
extra = 0
formsetclass = inlineformset_factory(
SubEvent, Quota,
@@ -509,6 +515,11 @@ class SubEventCreate(SubEventEditorMixin, EventPermissionRequiredMixin, CreateVi
context_object_name = 'subevent'
form_class = SubEventForm
def get_initial(self):
return {
'active': True,
}
def post(self, request, *args, **kwargs):
self.object = SubEvent(event=self.request.event)
form = self.get_form()
@@ -568,6 +579,10 @@ class SubEventCreate(SubEventEditorMixin, EventPermissionRequiredMixin, CreateVi
f.save()
return ret
def form_invalid(self, form):
messages.error(self.request, _('We could not save your changes. See below for details.'))
return super().form_invalid(form)
@cached_property
def meta_forms(self):
def clone(o):