forked from CGM_Public/pretix_original
* Data model and migration * Some backwards compatibility * CRUD for checkin lists * Show and perform checkins * Correct numbers in table and dashboard widget * event creation and cloning * Allow to link specific exports and pass options per query * Play with the CSV export * PDF export * Collapse exports by default * Improve PDF exporter * Addon stuff * Subevent stuff, pretixdroid tests * pretixdroid tests * Add CRUD API * Test compatibility * Fix test * DB-independent sorting behavior * Add CRUD and coyp tests * Re-enable pretixdroid plugin * pretixdroid config * Tests & fixes
153 lines
4.8 KiB
Python
153 lines
4.8 KiB
Python
from django import forms
|
||
from django.utils.functional import cached_property
|
||
from i18nfield.forms import I18nInlineFormSet
|
||
|
||
from pretix.base.forms import I18nModelForm
|
||
from pretix.base.models.event import SubEvent, SubEventMetaValue
|
||
from pretix.base.models.items import SubEventItem
|
||
from pretix.control.forms import SplitDateTimePickerWidget
|
||
|
||
|
||
class SubEventForm(I18nModelForm):
|
||
def __init__(self, *args, **kwargs):
|
||
self.event = kwargs['event']
|
||
super().__init__(*args, **kwargs)
|
||
self.fields['location'].widget.attrs['rows'] = '3'
|
||
|
||
class Meta:
|
||
model = SubEvent
|
||
localized_fields = '__all__'
|
||
fields = [
|
||
'name',
|
||
'active',
|
||
'date_from',
|
||
'date_to',
|
||
'date_admission',
|
||
'presale_start',
|
||
'presale_end',
|
||
'location',
|
||
'frontpage_text'
|
||
]
|
||
field_classes = {
|
||
'date_from': forms.SplitDateTimeField,
|
||
'date_to': forms.SplitDateTimeField,
|
||
'date_admission': forms.SplitDateTimeField,
|
||
'presale_start': forms.SplitDateTimeField,
|
||
'presale_end': forms.SplitDateTimeField,
|
||
}
|
||
widgets = {
|
||
'date_from': SplitDateTimePickerWidget(),
|
||
'date_to': SplitDateTimePickerWidget(attrs={'data-date-after': '#id_date_from_0'}),
|
||
'date_admission': SplitDateTimePickerWidget(attrs={'data-date-after': '#id_date_from_0'}),
|
||
'presale_start': SplitDateTimePickerWidget(),
|
||
'presale_end': SplitDateTimePickerWidget(attrs={'data-date-after': '#id_presale_start_0'}),
|
||
}
|
||
|
||
|
||
class SubEventItemOrVariationFormMixin:
|
||
def __init__(self, *args, **kwargs):
|
||
self.item = kwargs.pop('item')
|
||
self.variation = kwargs.pop('variation', None)
|
||
super().__init__(*args, **kwargs)
|
||
|
||
|
||
class SubEventItemForm(SubEventItemOrVariationFormMixin, forms.ModelForm):
|
||
def __init__(self, *args, **kwargs):
|
||
super().__init__(*args, **kwargs)
|
||
self.fields['price'].widget.attrs['placeholder'] = '{} {}'.format(
|
||
self.item.default_price, self.item.event.currency
|
||
)
|
||
self.fields['price'].label = str(self.item.name)
|
||
|
||
class Meta:
|
||
model = SubEventItem
|
||
fields = ['price']
|
||
|
||
|
||
class SubEventItemVariationForm(SubEventItemOrVariationFormMixin, forms.ModelForm):
|
||
def __init__(self, *args, **kwargs):
|
||
super().__init__(*args, **kwargs)
|
||
self.fields['price'].widget.attrs['placeholder'] = '{} {}'.format(
|
||
self.variation.price, self.item.event.currency
|
||
)
|
||
self.fields['price'].label = '{} – {}'.format(str(self.item.name), self.variation.value)
|
||
|
||
class Meta:
|
||
model = SubEventItem
|
||
fields = ['price']
|
||
|
||
|
||
class QuotaFormSet(I18nInlineFormSet):
|
||
|
||
def __init__(self, *args, **kwargs):
|
||
self.event = kwargs.pop('event', None)
|
||
self.locales = self.event.settings.get('locales')
|
||
super().__init__(*args, **kwargs)
|
||
|
||
@cached_property
|
||
def items(self):
|
||
return self.event.items.prefetch_related('variations').all()
|
||
|
||
def _construct_form(self, i, **kwargs):
|
||
kwargs['locales'] = self.locales
|
||
kwargs['event'] = self.event
|
||
kwargs['items'] = self.items
|
||
return super()._construct_form(i, **kwargs)
|
||
|
||
@property
|
||
def empty_form(self):
|
||
form = self.form(
|
||
auto_id=self.auto_id,
|
||
prefix=self.add_prefix('__prefix__'),
|
||
empty_permitted=True,
|
||
locales=self.locales,
|
||
event=self.event,
|
||
items=self.items
|
||
)
|
||
self.add_fields(form, None)
|
||
return form
|
||
|
||
|
||
class SubEventMetaValueForm(forms.ModelForm):
|
||
|
||
def __init__(self, *args, **kwargs):
|
||
self.property = kwargs.pop('property')
|
||
self.default = kwargs.pop('default', None)
|
||
super().__init__(*args, **kwargs)
|
||
self.fields['value'].required = False
|
||
self.fields['value'].widget.attrs['placeholder'] = self.default or self.property.default
|
||
|
||
class Meta:
|
||
model = SubEventMetaValue
|
||
fields = ['value']
|
||
widgets = {
|
||
'value': forms.TextInput
|
||
}
|
||
|
||
|
||
class CheckinListFormSet(I18nInlineFormSet):
|
||
|
||
def __init__(self, *args, **kwargs):
|
||
self.event = kwargs.pop('event', None)
|
||
self.locales = self.event.settings.get('locales')
|
||
super().__init__(*args, **kwargs)
|
||
|
||
@cached_property
|
||
def items(self):
|
||
return self.event.items.prefetch_related('variations').all()
|
||
|
||
def _construct_form(self, i, **kwargs):
|
||
kwargs['event'] = self.event
|
||
return super()._construct_form(i, **kwargs)
|
||
|
||
@property
|
||
def empty_form(self):
|
||
form = self.form(
|
||
auto_id=self.auto_id,
|
||
prefix=self.add_prefix('__prefix__'),
|
||
empty_permitted=True,
|
||
event=self.event,
|
||
)
|
||
self.add_fields(form, None)
|
||
return form
|