mirror of
https://github.com/pretix/pretix.git
synced 2026-09-14 16:24:43 +00:00
refactor: extract build_requested_valid_from_field method
This commit is contained in:
@@ -664,43 +664,7 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if cartpos and item.validity_mode == Item.VALIDITY_MODE_DYNAMIC and item.validity_dynamic_start_choice:
|
if cartpos and item.validity_mode == Item.VALIDITY_MODE_DYNAMIC and item.validity_dynamic_start_choice:
|
||||||
if item.validity_dynamic_start_choice_day_limit:
|
self.fields['requested_valid_from'] = self.build_requested_valid_from_field(event, pos, item)
|
||||||
max_date = time_machine_now().astimezone(event.timezone) + timedelta(days=item.validity_dynamic_start_choice_day_limit)
|
|
||||||
else:
|
|
||||||
max_date = None
|
|
||||||
min_date = time_machine_now()
|
|
||||||
initial = None
|
|
||||||
if (item.require_membership or (pos.variation and pos.variation.require_membership)) and pos.used_membership:
|
|
||||||
if pos.used_membership.date_start >= time_machine_now():
|
|
||||||
initial = min_date = pos.used_membership.date_start
|
|
||||||
max_date = min(max_date, pos.used_membership.date_end) if max_date else pos.used_membership.date_end
|
|
||||||
if item.validity_dynamic_duration_months or item.validity_dynamic_duration_days:
|
|
||||||
attrs = {}
|
|
||||||
if max_date:
|
|
||||||
attrs['data-max'] = max_date.date().isoformat()
|
|
||||||
if min_date:
|
|
||||||
attrs['data-min'] = min_date.date().isoformat()
|
|
||||||
self.fields['requested_valid_from'] = forms.DateField(
|
|
||||||
label=_('Start date'),
|
|
||||||
help_text='' if initial else _('If you keep this empty, the ticket will be valid starting at the time of purchase.'),
|
|
||||||
required=bool(initial),
|
|
||||||
initial=pos.requested_valid_from or initial,
|
|
||||||
widget=DatePickerWidget(attrs),
|
|
||||||
validators=([MaxDateValidator(max_date.date())] if max_date else []) + [MinDateValidator(min_date.date())]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.fields['requested_valid_from'] = forms.SplitDateTimeField(
|
|
||||||
label=_('Start date'),
|
|
||||||
help_text='' if initial else _('If you keep this empty, the ticket will be valid starting at the time of purchase.'),
|
|
||||||
required=bool(initial),
|
|
||||||
initial=pos.requested_valid_from or initial,
|
|
||||||
widget=SplitDateTimePickerWidget(
|
|
||||||
time_format=get_format_without_seconds('TIME_INPUT_FORMATS'),
|
|
||||||
min_date=min_date,
|
|
||||||
max_date=max_date
|
|
||||||
),
|
|
||||||
validators=([MaxDateTimeValidator(max_date)] if max_date else []) + [MinDateTimeValidator(min_date)]
|
|
||||||
)
|
|
||||||
|
|
||||||
for questionnaire in questionnaires:
|
for questionnaire in questionnaires:
|
||||||
for child in getattr(questionnaire, 'childlist', questionnaire.children.all()):
|
for child in getattr(questionnaire, 'childlist', questionnaire.children.all()):
|
||||||
@@ -733,6 +697,45 @@ class BaseQuestionsForm(forms.Form):
|
|||||||
else:
|
else:
|
||||||
v.widget.attrs['autocomplete'] = 'section-{} '.format(self.prefix) + autocomplete
|
v.widget.attrs['autocomplete'] = 'section-{} '.format(self.prefix) + autocomplete
|
||||||
|
|
||||||
|
def build_requested_valid_from_field(self, event, pos, item):
|
||||||
|
if item.validity_dynamic_start_choice_day_limit:
|
||||||
|
max_date = time_machine_now().astimezone(event.timezone) + timedelta(days=item.validity_dynamic_start_choice_day_limit)
|
||||||
|
else:
|
||||||
|
max_date = None
|
||||||
|
min_date = time_machine_now()
|
||||||
|
initial = None
|
||||||
|
if (item.require_membership or (pos.variation and pos.variation.require_membership)) and pos.used_membership:
|
||||||
|
if pos.used_membership.date_start >= time_machine_now():
|
||||||
|
initial = min_date = pos.used_membership.date_start
|
||||||
|
max_date = min(max_date, pos.used_membership.date_end) if max_date else pos.used_membership.date_end
|
||||||
|
if item.validity_dynamic_duration_months or item.validity_dynamic_duration_days:
|
||||||
|
attrs = {}
|
||||||
|
if max_date:
|
||||||
|
attrs['data-max'] = max_date.date().isoformat()
|
||||||
|
if min_date:
|
||||||
|
attrs['data-min'] = min_date.date().isoformat()
|
||||||
|
return forms.DateField(
|
||||||
|
label=_('Start date'),
|
||||||
|
help_text='' if initial else _('If you keep this empty, the ticket will be valid starting at the time of purchase.'),
|
||||||
|
required=bool(initial),
|
||||||
|
initial=pos.requested_valid_from or initial,
|
||||||
|
widget=DatePickerWidget(attrs),
|
||||||
|
validators=([MaxDateValidator(max_date.date())] if max_date else []) + [MinDateValidator(min_date.date())]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return forms.SplitDateTimeField(
|
||||||
|
label=_('Start date'),
|
||||||
|
help_text='' if initial else _('If you keep this empty, the ticket will be valid starting at the time of purchase.'),
|
||||||
|
required=bool(initial),
|
||||||
|
initial=pos.requested_valid_from or initial,
|
||||||
|
widget=SplitDateTimePickerWidget(
|
||||||
|
time_format=get_format_without_seconds('TIME_INPUT_FORMATS'),
|
||||||
|
min_date=min_date,
|
||||||
|
max_date=max_date
|
||||||
|
),
|
||||||
|
validators=([MaxDateTimeValidator(max_date)] if max_date else []) + [MinDateTimeValidator(min_date)]
|
||||||
|
)
|
||||||
|
|
||||||
def build_system_question_field(self, request, event, pos, qc):
|
def build_system_question_field(self, request, event, pos, qc):
|
||||||
field_name = qc.system_question
|
field_name = qc.system_question
|
||||||
if field_name == 'attendee_name_parts':
|
if field_name == 'attendee_name_parts':
|
||||||
|
|||||||
Reference in New Issue
Block a user