mirror of
https://github.com/pretix/pretix.git
synced 2026-08-19 12:16:26 +00:00
First UI steps
This commit is contained in:
@@ -174,14 +174,14 @@ class VoucherForm(I18nModelForm):
|
||||
|
||||
|
||||
class VoucherBulkForm(VoucherForm):
|
||||
codes = forms.CharField(
|
||||
widget=forms.Textarea,
|
||||
label=_("Codes"),
|
||||
help_text=_(
|
||||
"Add one voucher code per line. We suggest that you copy this list and save it into a file."
|
||||
),
|
||||
number = forms.IntegerField(
|
||||
label=_("Number"),
|
||||
required=True
|
||||
)
|
||||
itemvar = forms.ChoiceField(
|
||||
label=_("Product"),
|
||||
widget=forms.RadioSelect
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Voucher
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/sb-admin-2.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/ui/main.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/ui/quota.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/ui/voucher.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/ui/question.js" %}"></script>
|
||||
{% endcompress %}
|
||||
{{ html_head|safe }}
|
||||
|
||||
@@ -2,68 +2,144 @@
|
||||
{% load i18n %}
|
||||
{% load eventsignal %}
|
||||
{% load bootstrap3 %}
|
||||
{% load capture_tags %}
|
||||
{% block title %}{% trans "Voucher" %}{% endblock %}
|
||||
{% block inside %}
|
||||
<h1>{% trans "Create multiple voucher" %}</h1>
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<h1>{% trans "Create new vouchers" %}</h1>
|
||||
<form action="" method="post" class="form-inline" id="voucher-create">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_errors form %}
|
||||
<fieldset>
|
||||
<legend>{% trans "Voucher codes" %}</legend>
|
||||
<div class="form-group">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control input-xs"
|
||||
id="voucher-bulk-codes-num"
|
||||
placeholder="{% trans "Number" %}">
|
||||
<div class="input-group-btn">
|
||||
<button class="btn btn-default" type="button" id="voucher-bulk-codes-generate"
|
||||
data-rng-url="{% url 'control:event.vouchers.rng' organizer=request.event.organizer.slug event=request.event.slug %}">
|
||||
{% trans "Generate random codes" %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% capture as number_field silent %} {% bootstrap_field form.number layout="inline" %} {% endcapture %}
|
||||
{% capture as max_usages_field silent %} {% bootstrap_field form.max_usages layout="inline" %} {% endcapture %}
|
||||
{% capture as valid_until_field silent %} {% bootstrap_field form.valid_until layout="inline" %} {% endcapture %}
|
||||
{% capture as value_field_percent silent %}
|
||||
<input class="form-control price" name="price[percent]" type="text"> {% endcapture %}
|
||||
{% capture as value_field_subtract silent %}
|
||||
<input class="form-control price" name="price[subtract]" type="text"> {% endcapture %}
|
||||
{% capture as value_field_set silent %}
|
||||
<input class="form-control price" name="price[set]" type="text"> {% endcapture %}
|
||||
|
||||
{% bootstrap_form_errors form type="all" %}
|
||||
|
||||
<div class="wizard-step" id="step-number">
|
||||
<div class="wizard-step-inner">
|
||||
<h4>{% trans "How many vouchers do you want to create?" %}</h4>
|
||||
<div class="form-line">
|
||||
{% blocktrans trimmed %}
|
||||
Create {{ number_field }} voucher codes. Each of them can be redeemed {{ max_usages_field }}
|
||||
times.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
{% bootstrap_field form.codes layout="horizontal" %}
|
||||
{% bootstrap_field form.max_usages layout="horizontal" %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{% trans "Voucher details" %}</legend>
|
||||
{% bootstrap_field form.valid_until layout="horizontal" %}
|
||||
{% bootstrap_field form.block_quota layout="horizontal" %}
|
||||
{% bootstrap_field form.allow_ignore_quota layout="horizontal" %}
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label" for="id_tag">{% trans "Price effect" %}</label>
|
||||
<div class="col-md-5">
|
||||
{% bootstrap_field form.price_mode show_label=False form_group_class="" %}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
{% bootstrap_field form.value show_label=False form_group_class="" %}
|
||||
</div>
|
||||
</div>
|
||||
{% bootstrap_field form.itemvar layout="horizontal" %}
|
||||
<div class="form-group">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<div class="controls">
|
||||
<div class="alert alert-info">
|
||||
{% blocktrans trimmed %}
|
||||
If you choose "any product" for a specific quota and choose to reserve quota for this
|
||||
voucher above, the product can still be unavailable to the voucher holder if another quota
|
||||
associated with the product is sold out!
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% bootstrap_field form.tag layout="horizontal" %}
|
||||
{% bootstrap_field form.comment layout="horizontal" %}
|
||||
</fieldset>
|
||||
{% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="wizard-step" id="step-valid">
|
||||
<div class="wizard-step-inner">
|
||||
<h4>{% trans "How long should the vouchers be valid?" %}</h4>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="has_valid_until" value="no">
|
||||
{% trans "The whole presale period" %}
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="has_valid_until" value="yes">
|
||||
{% blocktrans trimmed %}
|
||||
Only valid until {{ valid_until_field }}
|
||||
{% endblocktrans %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-step" id="step-products">
|
||||
<div class="wizard-step-inner">
|
||||
<h4>{% trans "For which products should the vouchers be applicable?" %}</h4>
|
||||
{% bootstrap_field form.itemvar layout="inline" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-step" id="step-price">
|
||||
<div class="wizard-step-inner">
|
||||
<h4>{% trans "Should the vouchers modify the product's price?" %}</h4>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="price_mode" value="none">
|
||||
{% trans "No, just allow to buy this product" %}
|
||||
<span class="help-block">
|
||||
{% trans "This is useful if you have products that can only be bought using vouchers. It also allows you to just block quota for someone (see next step)." %}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="price_mode" value="percent">
|
||||
{% blocktrans trimmed %}
|
||||
Reduce price by {{ value_field_percent }} %
|
||||
{% endblocktrans %}
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="price_mode" value="subtract">
|
||||
{% blocktrans trimmed with currency=request.event.currency %}
|
||||
Reduce price by {{ value_field_subtract }} {{ currency }}
|
||||
{% endblocktrans %}
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="price_mode" value="set">
|
||||
{% blocktrans trimmed with currency=request.event.currency %}
|
||||
Change price to {{ value_field_set }} {{ currency }}
|
||||
{% endblocktrans %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-step" id="step-block">
|
||||
<div class="wizard-step-inner">
|
||||
<h4>{% trans "Should the vouchers block quota?" %}</h4>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="block_quota" value="no">
|
||||
{% trans "No" %}
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio radio-alt">
|
||||
<label>
|
||||
<input type="radio" name="block_quota" value="yes">
|
||||
{% trans "Yes" %}
|
||||
<span class="help-block">
|
||||
{% trans "If you select this option, these vouchers will be guaranteed, i.e. the applicable quotas will be reduced in a way that these vouchers can be redeemed as long as they are valid, even if your event sells out otherwise." %}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-step" id="step-advanced">
|
||||
<div class="wizard-step-inner">
|
||||
<a href="#" id="wizard-advanced-show">Show advanced options</a>
|
||||
<div class="wizard-advanced">
|
||||
<h4>{% trans "Advanced options" %}</h4>
|
||||
{% bootstrap_field form.allow_ignore_quota %}
|
||||
<p><strong>{% trans "Comment" %}</strong></p>
|
||||
{% bootstrap_field form.comment layout="inline" form_group_class="comment" %}
|
||||
<div class="help-block">
|
||||
{% trans "The text entered in this field will not be visible to the user and is available for your convenience." %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
|
||||
</form>
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Create" %}
|
||||
</button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -90,7 +90,6 @@ urlpatterns = [
|
||||
url(r'^vouchers/(?P<voucher>\d+)/delete$', vouchers.VoucherDelete.as_view(),
|
||||
name='event.voucher.delete'),
|
||||
url(r'^vouchers/add$', vouchers.VoucherCreate.as_view(), name='event.vouchers.add'),
|
||||
url(r'^vouchers/bulk_add$', vouchers.VoucherBulkCreate.as_view(), name='event.vouchers.bulk'),
|
||||
url(r'^orders/(?P<code>[0-9A-Z]+)/transition$', orders.OrderTransition.as_view(),
|
||||
name='event.order.transition'),
|
||||
url(r'^orders/(?P<code>[0-9A-Z]+)/resend$', orders.OrderResendLink.as_view(),
|
||||
|
||||
@@ -189,44 +189,6 @@ class VoucherUpdate(EventPermissionRequiredMixin, UpdateView):
|
||||
|
||||
|
||||
class VoucherCreate(EventPermissionRequiredMixin, CreateView):
|
||||
model = Voucher
|
||||
template_name = 'pretixcontrol/vouchers/detail.html'
|
||||
permission = 'can_change_vouchers'
|
||||
context_object_name = 'voucher'
|
||||
|
||||
def get_form_class(self):
|
||||
form_class = VoucherForm
|
||||
for receiver, response in voucher_form_class.send(self.request.event, cls=form_class):
|
||||
if response:
|
||||
form_class = response
|
||||
return form_class
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
return reverse('control:event.vouchers', kwargs={
|
||||
'organizer': self.request.event.organizer.slug,
|
||||
'event': self.request.event.slug,
|
||||
})
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['instance'] = Voucher(event=self.request.event)
|
||||
return kwargs
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
form.instance.event = self.request.event
|
||||
messages.success(self.request, _('The new voucher has been created.'))
|
||||
ret = super().form_valid(form)
|
||||
form.instance.log_action('pretix.voucher.added', data=dict(form.cleaned_data), user=self.request.user)
|
||||
return ret
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
# TODO: Transform this into an asynchronous call?
|
||||
with request.event.lock():
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class VoucherBulkCreate(EventPermissionRequiredMixin, CreateView):
|
||||
model = Voucher
|
||||
template_name = 'pretixcontrol/vouchers/bulk.html'
|
||||
permission = 'can_change_vouchers'
|
||||
@@ -241,6 +203,11 @@ class VoucherBulkCreate(EventPermissionRequiredMixin, CreateView):
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['instance'] = Voucher(event=self.request.event)
|
||||
initial = {
|
||||
}
|
||||
if 'initial' in kwargs:
|
||||
initial.update(kwargs['initial'])
|
||||
kwargs['initial'] = initial
|
||||
return kwargs
|
||||
|
||||
@transaction.atomic
|
||||
|
||||
Reference in New Issue
Block a user