mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Allow to link directly to voucher input form
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
{% load i18n %}
|
||||
{% load eventurl %}
|
||||
{% load rich_text %}
|
||||
{% if event.settings.voucher_explanation_text %}
|
||||
<div>
|
||||
{{ event.settings.voucher_explanation_text|rich_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="get" action="{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}">
|
||||
<div class="row row-voucher">
|
||||
<div class="col-md-8 col-sm-6 col-xs-12">
|
||||
<label for="voucher" class="sr-only">{% trans "Voucher code" %}
|
||||
{% if "voucher_invalid" in request.GET %}<strong>{% trans "has error" context "form" %},</strong>{% endif %}
|
||||
<i>{% trans "required" context "form" %}</i></label>
|
||||
<div class="input-group{% if "voucher_invalid" in request.GET %} has-error{% endif %}">
|
||||
<span class="input-group-addon"><i class="fa fa-ticket fa-fw" aria-hidden="true"></i></span>
|
||||
<input type="text" class="form-control{% if "voucher_invalid" in request.GET %} has-error{% endif %}" name="voucher" id="voucher"
|
||||
{% if "voucher_invalid" in request.GET %} aria-describedby="error-message"{% endif %}
|
||||
placeholder="{% trans "Voucher code" %}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
|
||||
<input type="hidden" name="next" value="{{ request.path }}" />
|
||||
<div class="col-md-4 col-sm-6 col-xs-12">
|
||||
<button class="btn btn-block btn-primary" type="submit">
|
||||
{% trans "Redeem voucher" %}
|
||||
</button>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -295,33 +295,7 @@
|
||||
{% if show_vouchers %}
|
||||
<aside class="front-page" aria-labelledby="redeem-a-voucher">
|
||||
<h3 id="redeem-a-voucher">{% trans "Redeem a voucher" %}</h3>
|
||||
{% if event.settings.voucher_explanation_text %}
|
||||
<div>
|
||||
{{ event.settings.voucher_explanation_text|rich_text }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="get" action="{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}">
|
||||
<div class="row row-voucher">
|
||||
<div class="col-md-8 col-sm-6 col-xs-12">
|
||||
<label for="voucher" class="sr-only">{% trans "Voucher code" %}
|
||||
{% if "voucher_invalid" in request.GET %}<strong>{% trans "has error" context "form" %},</strong>{% endif %}
|
||||
<i>{% trans "required" context "form" %}</i></label>
|
||||
<div class="input-group{% if "voucher_invalid" in request.GET %} has-error{% endif %}">
|
||||
<span class="input-group-addon"><i class="fa fa-ticket fa-fw" aria-hidden="true"></i></span>
|
||||
<input type="text" class="form-control{% if "voucher_invalid" in request.GET %} has-error{% endif %}" name="voucher" id="voucher"
|
||||
{% if "voucher_invalid" in request.GET %} aria-describedby="error-message"{% endif %}
|
||||
placeholder="{% trans "Voucher code" %}" required="required">
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
|
||||
<div class="col-md-4 col-sm-6 col-xs-12">
|
||||
<button class="btn btn-block btn-primary" type="submit">
|
||||
{% trans "Redeem voucher" %}
|
||||
</button>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</form>
|
||||
{% include "pretixpresale/event/fragment_voucher_form.html" %}
|
||||
</aside>
|
||||
{% endif %}
|
||||
{% if not cart_namespace %}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{% extends "pretixpresale/event/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load l10n %}
|
||||
{% load money %}
|
||||
{% load eventurl %}
|
||||
{% load eventsignal %}
|
||||
{% load thumb %}
|
||||
{% load rich_text %}
|
||||
{% block title %}{% trans "Voucher redemption" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans "Redeem a voucher" %}</h2>
|
||||
{% include "pretixpresale/event/fragment_voucher_form.html" %}
|
||||
{% endblock %}
|
||||
@@ -43,12 +43,12 @@ from django.contrib import messages
|
||||
from django.core.cache import caches
|
||||
from django.db.models import Q
|
||||
from django.http import FileResponse, Http404, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils import translation
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.http import is_safe_url
|
||||
from django.utils.http import is_safe_url, url_has_allowed_host_and_scheme
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
@@ -606,7 +606,7 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, CartMixin, TemplateView
|
||||
else:
|
||||
err = error_messages['voucher_invalid']
|
||||
else:
|
||||
return redirect(self.get_index_url())
|
||||
return render(request, 'pretixpresale/event/voucher_form.html')
|
||||
|
||||
if request.event.presale_start and now() < request.event.presale_start:
|
||||
err = error_messages['not_started']
|
||||
@@ -630,10 +630,15 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, CartMixin, TemplateView
|
||||
|
||||
if err:
|
||||
messages.error(request, _(err))
|
||||
return redirect(self.get_index_url() + "?voucher_invalid")
|
||||
return redirect(self.get_next_url() + "?voucher_invalid")
|
||||
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_next_url(self):
|
||||
if "next" in self.request.GET and url_has_allowed_host_and_scheme(self.request.GET.get("next"), allowed_hosts=None):
|
||||
return self.request.GET.get("next")
|
||||
return self.get_index_url()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if 'iframe' in request.GET and 'require_cookie' not in request.GET:
|
||||
return redirect(request.get_full_path() + '&require_cookie=1')
|
||||
|
||||
Reference in New Issue
Block a user