mirror of
https://github.com/pretix/pretix.git
synced 2026-05-11 16:13:59 +00:00
* [WIP] add date/time question type * Date/time questions python classes, types and form handling * use own timepicker * Fix argument naming * Add css and js for datetimepickers * remove not needed str call * seperate splitdatetime widget template and fix date/time questions * change date placeholder to dec 31 * do not show seconds in presale time pickers * improve codestyle * add new question types to api doc * add test * expand test to datetime question * add new questiontypes to changelog remove duplicate parens * remove timezone from time only question answers * improve codestyle * Fix date and time formatting in control question overview
This commit is contained in:
committed by
Raphael Michel
parent
b8c041d0d6
commit
251d62f3c4
@@ -4,6 +4,7 @@ from django.utils.translation import get_language_info
|
||||
from i18nfield.strings import LazyI18nString
|
||||
|
||||
from pretix.base.settings import GlobalSettingsObject
|
||||
from pretix.control.utils.i18n import get_javascript_format_without_seconds, get_moment_locale
|
||||
|
||||
from .signals import footer_link, html_footer, html_head
|
||||
|
||||
@@ -71,4 +72,9 @@ def contextprocessor(request):
|
||||
ctx['footer'] = _footer
|
||||
ctx['site_url'] = settings.SITE_URL
|
||||
|
||||
ctx['js_datetime_format'] = get_javascript_format_without_seconds('DATETIME_INPUT_FORMATS')
|
||||
ctx['js_date_format'] = get_javascript_format_without_seconds('DATE_INPUT_FORMATS')
|
||||
ctx['js_time_format'] = get_javascript_format_without_seconds('TIME_INPUT_FORMATS')
|
||||
ctx['js_locale'] = get_moment_locale()
|
||||
|
||||
return ctx
|
||||
|
||||
@@ -3,6 +3,8 @@ import os
|
||||
from decimal import Decimal
|
||||
from itertools import chain
|
||||
|
||||
import dateutil
|
||||
import pytz
|
||||
import vat_moss.errors
|
||||
import vat_moss.id
|
||||
from django import forms
|
||||
@@ -18,8 +20,12 @@ from pretix.base.models import ItemVariation, Question
|
||||
from pretix.base.models.orders import InvoiceAddress, OrderPosition
|
||||
from pretix.base.models.tax import EU_COUNTRIES, TAXED_ZERO
|
||||
from pretix.base.templatetags.rich_text import rich_text
|
||||
from pretix.control.forms import (
|
||||
DatePickerWidget, SplitDateTimePickerWidget, TimePickerWidget,
|
||||
)
|
||||
from pretix.multidomain.urlreverse import eventreverse
|
||||
from pretix.presale.signals import contact_form_fields, question_form_fields
|
||||
from pretix.control.utils.i18n import get_format_without_seconds
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -235,6 +241,7 @@ class QuestionsForm(forms.Form):
|
||||
initial = answers[0]
|
||||
else:
|
||||
initial = None
|
||||
tz = pytz.timezone(event.settings.timezone)
|
||||
if q.type == Question.TYPE_BOOLEAN:
|
||||
if q.required:
|
||||
# For some reason, django-bootstrap3 does not set the required attribute
|
||||
@@ -258,7 +265,7 @@ class QuestionsForm(forms.Form):
|
||||
label=q.question, required=q.required,
|
||||
help_text=q.help_text,
|
||||
initial=initial.answer if initial else None,
|
||||
min_value=Decimal('0.00')
|
||||
min_value=Decimal('0.00'),
|
||||
)
|
||||
elif q.type == Question.TYPE_STRING:
|
||||
field = forms.CharField(
|
||||
@@ -295,7 +302,28 @@ class QuestionsForm(forms.Form):
|
||||
label=q.question, required=q.required,
|
||||
help_text=q.help_text,
|
||||
initial=initial.file if initial else None,
|
||||
widget=UploadedFileWidget(position=pos, event=event, answer=initial)
|
||||
widget=UploadedFileWidget(position=pos, event=event, answer=initial),
|
||||
)
|
||||
elif q.type == Question.TYPE_DATE:
|
||||
field = forms.DateField(
|
||||
label=q.question, required=q.required,
|
||||
help_text=q.help_text,
|
||||
initial=dateutil.parser.parse(initial.answer).date() if initial and initial.answer else None,
|
||||
widget=DatePickerWidget(),
|
||||
)
|
||||
elif q.type == Question.TYPE_TIME:
|
||||
field = forms.TimeField(
|
||||
label=q.question, required=q.required,
|
||||
help_text=q.help_text,
|
||||
initial=dateutil.parser.parse(initial.answer).astimezone(tz).time() if initial and initial.answer else None,
|
||||
widget=TimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
||||
)
|
||||
elif q.type == Question.TYPE_DATETIME:
|
||||
field = forms.SplitDateTimeField(
|
||||
label=q.question, required=q.required,
|
||||
help_text=q.help_text,
|
||||
initial=dateutil.parser.parse(initial.answer).astimezone(tz) if initial and initial.answer else None,
|
||||
widget=SplitDateTimePickerWidget(time_format=get_format_without_seconds('TIME_INPUT_FORMATS')),
|
||||
)
|
||||
field.question = q
|
||||
if answers:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<script type="text/javascript" src="{% static "moment/moment-with-locales.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "js/jquery.formset.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "bootstrap/js/bootstrap.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "datetimepicker/bootstrap-datetimepicker.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixpresale/js/ui/main.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixbase/js/asynctask.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixbase/js/asyncdownload.js" %}"></script>
|
||||
@@ -35,7 +36,7 @@
|
||||
<link rel="icon" href="{% static "pretixbase/img/favicon.ico" %}">
|
||||
{% block custom_header %}{% endblock %}
|
||||
</head>
|
||||
<body data-locale="{{ request.LANGUAGE_CODE }}" data-now="{% now "U.u" %}">
|
||||
<body data-locale="{{ request.LANGUAGE_CODE }}" data-now="{% now "U.u" %}" data-datetimeformat="{{ js_datetime_format }}" data-timeformat="{{ js_time_format }}" data-dateformat="{{ js_date_format }}" data-datetimelocale="{{ js_locale }}">
|
||||
{% block above %}
|
||||
{% endblock %}
|
||||
<div class="container">
|
||||
|
||||
Reference in New Issue
Block a user