mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Slug widget
This commit is contained in:
@@ -88,3 +88,13 @@ class ExtFileField(forms.FileField):
|
||||
if ext not in self.ext_whitelist:
|
||||
raise forms.ValidationError(_("Filetype not allowed!"))
|
||||
return data
|
||||
|
||||
|
||||
class SlugWidget(forms.TextInput):
|
||||
template_name = 'pretixcontrol/slug_widget.html'
|
||||
prefix = ''
|
||||
|
||||
def get_context(self, name, value, attrs):
|
||||
ctx = super().get_context(name, value, attrs)
|
||||
ctx['pre'] = self.prefix
|
||||
return ctx
|
||||
|
||||
@@ -11,7 +11,8 @@ from pytz import common_timezones, timezone
|
||||
from pretix.base.forms import I18nModelForm, PlaceholderValidator, SettingsForm
|
||||
from pretix.base.models import Event, Organizer
|
||||
from pretix.base.reldate import RelativeDateField, RelativeDateTimeField
|
||||
from pretix.control.forms import ExtFileField
|
||||
from pretix.control.forms import ExtFileField, SlugWidget
|
||||
from pretix.multidomain.urlreverse import build_absolute_uri
|
||||
|
||||
|
||||
class EventWizardFoundationForm(forms.Form):
|
||||
@@ -77,6 +78,7 @@ class EventWizardBasicsForm(I18nModelForm):
|
||||
'presale_start': forms.DateTimeInput(attrs={'class': 'datetimepicker'}),
|
||||
'presale_end': forms.DateTimeInput(attrs={'class': 'datetimepicker',
|
||||
'data-date-after': '#id_basics-presale_start'}),
|
||||
'slug': SlugWidget
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -88,6 +90,7 @@ class EventWizardBasicsForm(I18nModelForm):
|
||||
self.initial['timezone'] = get_current_timezone_name()
|
||||
self.fields['locale'].choices = [(a, b) for a, b in settings.LANGUAGES if a in self.locales]
|
||||
self.fields['location'].widget.attrs['rows'] = '3'
|
||||
self.fields['slug'].widget.prefix = build_absolute_uri(self.organizer, 'presale:organizer.index')
|
||||
if self.has_subevents:
|
||||
del self.fields['presale_start']
|
||||
del self.fields['presale_end']
|
||||
|
||||
@@ -5,9 +5,30 @@
|
||||
<fieldset>
|
||||
<legend>{% trans "General information" %}</legend>
|
||||
{% bootstrap_field form.name layout="horizontal" %}
|
||||
{% trans "Random" as rndlabel %}
|
||||
{% url "control:events.add.slugrng" organizer=organizer.slug as rngurl %}
|
||||
{% bootstrap_field form.slug layout="horizontal" addon_after='<button class="btn btn-default" type="button" id="event-slug-random-generate" data-rng-url="'|add:rngurl|add:'">'|add:rndlabel|add:'</button>' addon_after_class='input-group-btn' %}
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label" for="{{ form.slug.id_for_label }}">{{ form.slug.label }}</label>
|
||||
<div class="col-md-9 form-inline">
|
||||
<button class="btn btn-default pull-right" type="button" id="event-slug-random-generate"
|
||||
data-rng-url="{% url "control:events.add.slugrng" organizer=organizer.slug %}">
|
||||
{% trans "Set to random" %}
|
||||
</button>
|
||||
{% bootstrap_field form.slug form_group_class="helper-display-inline" show_label=False layout="inline" %}
|
||||
<div class="help-block">
|
||||
{% blocktrans trimmed %}
|
||||
This is the address users can buy your tickets at. Should be short, only contain lowercase
|
||||
letters and numbers, and must be unique among your events. We recommend some kind of
|
||||
abbreviation or a date with less than 10 characters that can be easily remembered, but you
|
||||
can also choose to use a random value.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<div class="help-block">
|
||||
{% blocktrans trimmed %}
|
||||
We will also use this in some places like order codes, invoice numbers or bank transfer
|
||||
references as an abbreviation to reference this event.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% bootstrap_field form.date_from layout="horizontal" %}
|
||||
{% bootstrap_field form.date_to layout="horizontal" %}
|
||||
{% bootstrap_field form.location layout="horizontal" %}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<div class="form-inline helper-display-inline">
|
||||
{{ pre }}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"
|
||||
{% if widget.value != None %}value="{{ widget.value }}"{% endif %}
|
||||
{% include "django/forms/widgets/attrs.html" %}
|
||||
/>
|
||||
/
|
||||
</div>
|
||||
Reference in New Issue
Block a user