forked from CGM_Public/pretix_original
Added voucher redemption
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9 on 2016-02-11 14:59
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import pretix.base.models.vouchers
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pretixbase', '0004_auto_20160209_1023'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='voucher',
|
||||||
|
name='redeemed',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='Redeemed'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='voucher',
|
||||||
|
name='code',
|
||||||
|
field=models.CharField(default=pretix.base.models.vouchers.generate_code, max_length=255, verbose_name='Voucher code'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -475,12 +475,24 @@ class Quota(LoggedModel):
|
|||||||
if size_left <= 0:
|
if size_left <= 0:
|
||||||
return Quota.AVAILABILITY_ORDERED, 0
|
return Quota.AVAILABILITY_ORDERED, 0
|
||||||
|
|
||||||
|
size_left -= self.count_blocking_vouchers()
|
||||||
|
if size_left <= 0:
|
||||||
|
return Quota.AVAILABILITY_ORDERED, 0
|
||||||
|
|
||||||
size_left -= self.count_in_cart()
|
size_left -= self.count_in_cart()
|
||||||
if size_left <= 0:
|
if size_left <= 0:
|
||||||
return Quota.AVAILABILITY_RESERVED, 0
|
return Quota.AVAILABILITY_RESERVED, 0
|
||||||
|
|
||||||
return Quota.AVAILABILITY_OK, size_left
|
return Quota.AVAILABILITY_OK, size_left
|
||||||
|
|
||||||
|
def count_blocking_vouchers(self) -> int:
|
||||||
|
from pretix.base.models import Voucher
|
||||||
|
return Voucher.objects.filter(
|
||||||
|
item__quotas__in=[self],
|
||||||
|
block_quota=True,
|
||||||
|
redeemed=False
|
||||||
|
).count()
|
||||||
|
|
||||||
def count_in_cart(self) -> int:
|
def count_in_cart(self) -> int:
|
||||||
from pretix.base.models import CartPosition
|
from pretix.base.models import CartPosition
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ class Voucher(LoggedModel):
|
|||||||
verbose_name=_("Voucher code"),
|
verbose_name=_("Voucher code"),
|
||||||
max_length=255, default=generate_code
|
max_length=255, default=generate_code
|
||||||
)
|
)
|
||||||
|
redeemed = models.BooleanField(
|
||||||
|
verbose_name=_("Redeemed"),
|
||||||
|
default=False
|
||||||
|
)
|
||||||
valid_until = models.DateTimeField(
|
valid_until = models.DateTimeField(
|
||||||
blank=True, null=True,
|
blank=True, null=True,
|
||||||
verbose_name=_("Valid until")
|
verbose_name=_("Valid until")
|
||||||
@@ -71,6 +75,11 @@ class Voucher(LoggedModel):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.code = self.code.upper()
|
self.code = self.code.upper()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
self.event.get_cache().set('vouchers_exist', True)
|
||||||
|
|
||||||
|
def delete(self, using=None, keep_parents=False):
|
||||||
|
super().delete(using, keep_parents)
|
||||||
|
self.event.get_cache().delete('vouchers_exist')
|
||||||
|
|
||||||
def is_ordered(self) -> int:
|
def is_ordered(self) -> int:
|
||||||
return OrderPosition.objects.filter(
|
return OrderPosition.objects.filter(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from typing import List, Optional, Tuple
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
from pretix.base.models import (
|
from pretix.base.models import (
|
||||||
CartPosition, Event, EventLock, Item, ItemVariation, Quota,
|
CartPosition, Event, EventLock, Item, ItemVariation, Quota, Voucher,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +27,10 @@ error_messages = {
|
|||||||
'the quantity you selected. Please see below for details.'),
|
'the quantity you selected. Please see below for details.'),
|
||||||
'max_items': _("You cannot select more than %s items per order"),
|
'max_items': _("You cannot select more than %s items per order"),
|
||||||
'not_started': _('The presale period for this event has not yet started.'),
|
'not_started': _('The presale period for this event has not yet started.'),
|
||||||
'ended': _('The presale period has ended.')
|
'ended': _('The presale period has ended.'),
|
||||||
|
'voucher_invalid': _('This voucher code is not known in our database.'),
|
||||||
|
'voucher_redeemed': _('This voucher code has already been used an can only be used once.'),
|
||||||
|
'voucher_expired': _('This voucher is expired'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -98,7 +101,7 @@ def _add_new_items(event: Event, items: List[Tuple[int, Optional[int], int]],
|
|||||||
err = err or error_messages['unavailable']
|
err = err or error_messages['unavailable']
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Assume that all quotas allow us to buy i[2] instances of the object
|
# Check that all quotas allow us to buy i[2] instances of the object
|
||||||
quota_ok = i[2]
|
quota_ok = i[2]
|
||||||
for quota in quotas:
|
for quota in quotas:
|
||||||
avail = quota.availability()
|
avail = quota.availability()
|
||||||
@@ -131,7 +134,35 @@ def _add_new_items(event: Event, items: List[Tuple[int, Optional[int], int]],
|
|||||||
return err
|
return err
|
||||||
|
|
||||||
|
|
||||||
def _add_items_to_cart(event: Event, items: List[Tuple[int, Optional[int], int]], cart_id: str=None) -> None:
|
def _add_voucher(event: Event, voucher: str, expiry: datetime, cart_id: str):
|
||||||
|
try:
|
||||||
|
v = Voucher.objects.get(code=voucher, event=event)
|
||||||
|
if v.redeemed:
|
||||||
|
raise CartError(error_messages['voucher_redeemed'])
|
||||||
|
if v.valid_until is not None and v.valid_until < now():
|
||||||
|
raise CartError(error_messages['voucher_expired'])
|
||||||
|
|
||||||
|
quotas = list(v.item.quotas.all())
|
||||||
|
if len(quotas) == 0 or not v.item.is_available():
|
||||||
|
raise CartError(error_messages['unavailable'])
|
||||||
|
|
||||||
|
if not v.allow_ignore_quota and not v.block_quota:
|
||||||
|
for quota in quotas:
|
||||||
|
avail = quota.availability()
|
||||||
|
if avail[1] is not None and avail[1] < 1:
|
||||||
|
raise CartError(error_messages['unavailable'])
|
||||||
|
|
||||||
|
CartPosition.objects.create(
|
||||||
|
event=event, item=v.item, variation=None,
|
||||||
|
price=v.price if v.price is not None else v.item.default_price,
|
||||||
|
expires=expiry, cart_id=cart_id, voucher=v
|
||||||
|
)
|
||||||
|
except Voucher.DoesNotExist:
|
||||||
|
raise CartError(error_messages['voucher_invalid'])
|
||||||
|
|
||||||
|
|
||||||
|
def _add_items_to_cart(event: Event, items: List[Tuple[int, Optional[int], int]], cart_id: str=None,
|
||||||
|
voucher: str=None) -> None:
|
||||||
with event.lock():
|
with event.lock():
|
||||||
_check_date(event)
|
_check_date(event)
|
||||||
existing = CartPosition.objects.filter(Q(cart_id=cart_id) & Q(event=event)).count()
|
existing = CartPosition.objects.filter(Q(cart_id=cart_id) & Q(event=event)).count()
|
||||||
@@ -143,31 +174,36 @@ def _add_items_to_cart(event: Event, items: List[Tuple[int, Optional[int], int]]
|
|||||||
_extend_existing(event, cart_id, expiry)
|
_extend_existing(event, cart_id, expiry)
|
||||||
|
|
||||||
expired = _re_add_expired_positions(items, event, cart_id)
|
expired = _re_add_expired_positions(items, event, cart_id)
|
||||||
if not items:
|
if items:
|
||||||
|
err = _add_new_items(event, items, cart_id, expiry)
|
||||||
|
_delete_expired(expired)
|
||||||
|
if err:
|
||||||
|
raise CartError(err)
|
||||||
|
elif not voucher:
|
||||||
raise CartError(error_messages['empty'])
|
raise CartError(error_messages['empty'])
|
||||||
|
|
||||||
err = _add_new_items(event, items, cart_id, expiry)
|
if voucher:
|
||||||
_delete_expired(expired)
|
_add_voucher(event, voucher, expiry, cart_id)
|
||||||
if err:
|
|
||||||
raise CartError(err)
|
|
||||||
|
|
||||||
|
|
||||||
def add_items_to_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str=None) -> None:
|
def add_items_to_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str=None,
|
||||||
|
voucher: str=None) -> None:
|
||||||
"""
|
"""
|
||||||
Adds a list of items to a user's cart.
|
Adds a list of items to a user's cart.
|
||||||
:param event: The event ID in question
|
:param event: The event ID in question
|
||||||
:param items: A list of tuple of the form (item id, variation id or None, number)
|
:param items: A list of tuple of the form (item id, variation id or None, number)
|
||||||
:param session: Session ID of a guest
|
:param session: Session ID of a guest
|
||||||
|
:param coupon: A coupon that should also be reeemed
|
||||||
:raises CartError: On any error that occured
|
:raises CartError: On any error that occured
|
||||||
"""
|
"""
|
||||||
event = Event.objects.get(id=event)
|
event = Event.objects.get(id=event)
|
||||||
try:
|
try:
|
||||||
_add_items_to_cart(event, items, cart_id)
|
_add_items_to_cart(event, items, cart_id, voucher)
|
||||||
except EventLock.LockTimeoutException:
|
except EventLock.LockTimeoutException:
|
||||||
raise CartError(error_messages['busy'])
|
raise CartError(error_messages['busy'])
|
||||||
|
|
||||||
|
|
||||||
def _remove_items_from_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: int) -> None:
|
def _remove_items_from_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str) -> None:
|
||||||
with event.lock():
|
with event.lock():
|
||||||
for item, variation, cnt in items:
|
for item, variation, cnt in items:
|
||||||
cw = Q(cart_id=cart_id) & Q(item_id=item) & Q(event=event)
|
cw = Q(cart_id=cart_id) & Q(item_id=item) & Q(event=event)
|
||||||
@@ -179,7 +215,7 @@ def _remove_items_from_cart(event: int, items: List[Tuple[int, Optional[int], in
|
|||||||
cp.delete()
|
cp.delete()
|
||||||
|
|
||||||
|
|
||||||
def remove_items_from_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: int=None) -> None:
|
def remove_items_from_cart(event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str=None) -> None:
|
||||||
"""
|
"""
|
||||||
Removes a list of items from a user's cart.
|
Removes a list of items from a user's cart.
|
||||||
:param event: The event ID in question
|
:param event: The event ID in question
|
||||||
@@ -197,10 +233,11 @@ if settings.HAS_CELERY:
|
|||||||
from pretix.celery import app
|
from pretix.celery import app
|
||||||
|
|
||||||
@app.task(bind=True, max_retries=5, default_retry_delay=2)
|
@app.task(bind=True, max_retries=5, default_retry_delay=2)
|
||||||
def add_items_to_cart_task(self, event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str):
|
def add_items_to_cart_task(self, event: int, items: List[Tuple[int, Optional[int], int]], cart_id: str,
|
||||||
|
voucher: str=None):
|
||||||
event = Event.objects.get(id=event)
|
event = Event.objects.get(id=event)
|
||||||
try:
|
try:
|
||||||
_add_items_to_cart(event, items, cart_id)
|
_add_items_to_cart(event, items, cart_id, voucher)
|
||||||
except EventLock.LockTimeoutException:
|
except EventLock.LockTimeoutException:
|
||||||
self.retry(exc=CartError(error_messages['busy']))
|
self.retry(exc=CartError(error_messages['busy']))
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ error_messages = {
|
|||||||
'internal': _("An internal error occured, please try again."),
|
'internal': _("An internal error occured, please try again."),
|
||||||
'busy': _('We were not able to process your request completely as the '
|
'busy': _('We were not able to process your request completely as the '
|
||||||
'server was too busy. Please try again.'),
|
'server was too busy. Please try again.'),
|
||||||
|
'voucher_redeemed': _('A voucher you tried to use already has been used.'),
|
||||||
|
'voucher_expired': _('A voucher you tried to use has expired.'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -133,29 +135,51 @@ def _check_positions(event: Event, dt: datetime, positions: List[CartPosition]):
|
|||||||
cp.delete()
|
cp.delete()
|
||||||
continue
|
continue
|
||||||
quotas = list(cp.item.quotas.all()) if cp.variation is None else list(cp.variation.quotas.all())
|
quotas = list(cp.item.quotas.all()) if cp.variation is None else list(cp.variation.quotas.all())
|
||||||
|
|
||||||
|
if cp.voucher:
|
||||||
|
if cp.voucher.redeemed:
|
||||||
|
err = err or error_messages['voucher_redeemed']
|
||||||
|
continue
|
||||||
|
cp.voucher.redeemed = True
|
||||||
|
cp.voucher.save()
|
||||||
|
|
||||||
if cp.expires >= dt:
|
if cp.expires >= dt:
|
||||||
# Other checks are not necessary
|
# Other checks are not necessary
|
||||||
continue
|
continue
|
||||||
|
|
||||||
price = cp.item.default_price if cp.variation is None else (
|
price = cp.item.default_price if cp.variation is None else (
|
||||||
cp.variation.default_price if cp.variation.default_price is not None else cp.item.default_price)
|
cp.variation.default_price if cp.variation.default_price is not None else cp.item.default_price)
|
||||||
|
|
||||||
|
if cp.voucher:
|
||||||
|
if cp.voucher.valid_until < now():
|
||||||
|
err = err or error_messages['voucher_expired']
|
||||||
|
continue
|
||||||
|
if price is not False and cp.voucher.price is not None:
|
||||||
|
price = cp.voucher.price
|
||||||
|
|
||||||
if price is False or len(quotas) == 0:
|
if price is False or len(quotas) == 0:
|
||||||
err = err or error_messages['unavailable']
|
err = err or error_messages['unavailable']
|
||||||
cp.delete()
|
cp.delete()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if price != cp.price:
|
if price != cp.price:
|
||||||
positions[i] = cp
|
positions[i] = cp
|
||||||
cp.price = price
|
cp.price = price
|
||||||
cp.save()
|
cp.save()
|
||||||
err = err or error_messages['price_changed']
|
err = err or error_messages['price_changed']
|
||||||
continue
|
continue
|
||||||
|
|
||||||
quota_ok = True
|
quota_ok = True
|
||||||
for quota in quotas:
|
|
||||||
avail = quota.availability()
|
if not cp.voucher or not (cp.voucher.allow_ignore_quota or cp.voucher.block_quota):
|
||||||
if avail[0] != Quota.AVAILABILITY_OK:
|
for quota in quotas:
|
||||||
# This quota is sold out/currently unavailable, so do not sell this at all
|
avail = quota.availability()
|
||||||
err = err or error_messages['unavailable']
|
if avail[0] != Quota.AVAILABILITY_OK:
|
||||||
quota_ok = False
|
# This quota is sold out/currently unavailable, so do not sell this at all
|
||||||
break
|
err = err or error_messages['unavailable']
|
||||||
|
quota_ok = False
|
||||||
|
break
|
||||||
|
|
||||||
if quota_ok:
|
if quota_ok:
|
||||||
positions[i] = cp
|
positions[i] = cp
|
||||||
cp.expires = now() + timedelta(
|
cp.expires = now() + timedelta(
|
||||||
@@ -167,7 +191,6 @@ def _check_positions(event: Event, dt: datetime, positions: List[CartPosition]):
|
|||||||
raise OrderError(err)
|
raise OrderError(err)
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic()
|
|
||||||
def _create_order(event: Event, email: str, positions: List[CartPosition], dt: datetime,
|
def _create_order(event: Event, email: str, positions: List[CartPosition], dt: datetime,
|
||||||
payment_provider: BasePaymentProvider, locale: str=None):
|
payment_provider: BasePaymentProvider, locale: str=None):
|
||||||
total = sum([c.price for c in positions])
|
total = sum([c.price for c in positions])
|
||||||
@@ -211,9 +234,10 @@ def _perform_order(event: str, payment_provider: str, position_ids: List[str],
|
|||||||
id__in=position_ids).select_related('item', 'variation'))
|
id__in=position_ids).select_related('item', 'variation'))
|
||||||
if len(position_ids) != len(positions):
|
if len(position_ids) != len(positions):
|
||||||
raise OrderError(error_messages['internal'])
|
raise OrderError(error_messages['internal'])
|
||||||
_check_positions(event, dt, positions)
|
with transaction.atomic():
|
||||||
order = _create_order(event, email, positions, dt, pprov,
|
_check_positions(event, dt, positions)
|
||||||
locale=locale)
|
order = _create_order(event, email, positions, dt, pprov,
|
||||||
|
locale=locale)
|
||||||
|
|
||||||
mail(
|
mail(
|
||||||
order.email, _('Your order: %(code)s') % {'code': order.code},
|
order.email, _('Your order: %(code)s') % {'code': order.code},
|
||||||
|
|||||||
@@ -85,6 +85,12 @@
|
|||||||
{% if line.variation %}
|
{% if line.variation %}
|
||||||
– {{ line.variation }}
|
– {{ line.variation }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if line.voucher %}
|
||||||
|
<br /><span class="fa fa-ticket"></span> {% trans "Voucher code used:" %}
|
||||||
|
<a href="{% url "control:event.voucher" event=request.event.slug organizer=request.event.organizer.slug voucher=line.voucher.pk %}">
|
||||||
|
{{ line.voucher.code }}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
{% if line.has_questions %}
|
{% if line.has_questions %}
|
||||||
<dl>
|
<dl>
|
||||||
{% if line.item.admission and event.settings.attendee_names_asked %}
|
{% if line.item.admission and event.settings.attendee_names_asked %}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
{% block title %}{% trans "Voucher" %}{% endblock %}
|
{% block title %}{% trans "Voucher" %}{% endblock %}
|
||||||
{% block inside %}
|
{% block inside %}
|
||||||
<h1>{% trans "Voucher" %}</h1>
|
<h1>{% trans "Voucher" %}</h1>
|
||||||
|
{% if voucher.redeemed %}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
{% trans "This voucher already has been used. It is not recommended to modify it." %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<form action="" method="post" class="form-horizontal">
|
<form action="" method="post" class="form-horizontal">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form_errors form %}
|
{% bootstrap_form_errors form %}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<strong><a href="
|
<strong><a href="
|
||||||
{% url "control:event.voucher" organizer=request.event.organizer.slug event=request.event.slug voucher=v.id %}">{{ v.code }}</a></strong>
|
{% url "control:event.voucher" organizer=request.event.organizer.slug event=request.event.slug voucher=v.id %}">{{ v.code }}</a></strong>
|
||||||
</td>
|
</td>
|
||||||
<td>{% if v.is_ordered %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
|
<td>{% if v.redeemed %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
|
||||||
<td>{{ v.valid_until|date }}</td>
|
<td>{{ v.valid_until|date }}</td>
|
||||||
<td>{{ v.item }}</td>
|
<td>{{ v.item }}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ class OrderDetail(OrderView):
|
|||||||
def keyfunc(pos):
|
def keyfunc(pos):
|
||||||
if (pos.item.admission and self.request.event.settings.attendee_names_asked) \
|
if (pos.item.admission and self.request.event.settings.attendee_names_asked) \
|
||||||
or pos.item.questions.all():
|
or pos.item.questions.all():
|
||||||
return pos.id, 0, 0, 0
|
return pos.id, 0, 0, 0, None
|
||||||
return 0, pos.item_id, pos.variation_id, pos.price
|
return 0, pos.item_id, pos.variation_id, pos.price, pos.voucher
|
||||||
|
|
||||||
positions = []
|
positions = []
|
||||||
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):
|
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
{% if line.variation %}
|
{% if line.variation %}
|
||||||
– {{ line.variation }}
|
– {{ line.variation }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if line.voucher %}
|
||||||
|
<br /><span class="fa fa-ticket"></span> {% trans "Voucher code used:" %} {{ line.voucher.code }}
|
||||||
|
{% endif %}
|
||||||
{% if line.has_questions %}
|
{% if line.has_questions %}
|
||||||
<dl>
|
<dl>
|
||||||
{% if line.item.admission and event.settings.attendee_names_asked%}
|
{% if line.item.admission and event.settings.attendee_names_asked%}
|
||||||
|
|||||||
@@ -6,32 +6,32 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if cart.positions %}
|
{% if cart.positions %}
|
||||||
<div class="panel panel-primary cart">
|
<div class="panel panel-primary cart">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">{% trans "Your cart" %}</h3>
|
<h3 class="panel-title">{% trans "Your cart" %}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
|
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="col-md-6 col-xs-12">
|
<div class="col-md-6 col-xs-12">
|
||||||
{% if cart.minutes_left > 0 %}
|
{% if cart.minutes_left > 0 %}
|
||||||
<em>{% blocktrans trimmed with minutes=cart.minutes_left %}
|
<em>{% blocktrans trimmed with minutes=cart.minutes_left %}
|
||||||
The items in your cart are reserved for you for {{ minutes }} minutes.
|
The items in your cart are reserved for you for {{ minutes }} minutes.
|
||||||
{% endblocktrans %}</em>
|
{% endblocktrans %}</em>
|
||||||
{% else %}
|
{% else %}
|
||||||
<em>{% trans "The items in your cart are no longer reserved for you." %}</em>
|
<em>{% trans "The items in your cart are no longer reserved for you." %}</em>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 col-md-offset-2 col-xs-12">
|
||||||
|
<a class="btn btn-block btn-primary btn-lg"
|
||||||
|
href="{% eventurl request.event "presale:event.checkout.start" %}">
|
||||||
|
<i class="fa fa-shopping-cart"></i> {% trans "Proceed with checkout" %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 col-md-offset-2 col-xs-12">
|
|
||||||
<a class="btn btn-block btn-primary btn-lg"
|
|
||||||
href="{% eventurl request.event "presale:event.checkout.start" %}">
|
|
||||||
<i class="fa fa-shopping-cart"></i> {% trans "Proceed with checkout" %}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not event.presale_is_running %}
|
{% if not event.presale_is_running %}
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
data-title="{{ item.name }}"
|
data-title="{{ item.name }}"
|
||||||
data-lightbox="{{ item.id }}">
|
data-lightbox="{{ item.id }}">
|
||||||
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
|
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
|
||||||
alt="{{ item.name }}" />
|
alt="{{ item.name }}"/>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="javascript:void(0);" data-toggle="variations">
|
<a href="javascript:void(0);" data-toggle="variations">
|
||||||
@@ -100,7 +100,8 @@
|
|||||||
<div class="col-md-2 col-xs-6 price">
|
<div class="col-md-2 col-xs-6 price">
|
||||||
{{ event.currency }} {{ var.price|floatformat:2 }}
|
{{ event.currency }} {{ var.price|floatformat:2 }}
|
||||||
{% if item.tax_rate %}
|
{% if item.tax_rate %}
|
||||||
<br /><small>{% blocktrans trimmed with rate=item.tax_rate %}
|
<br/>
|
||||||
|
<small>{% blocktrans trimmed with rate=item.tax_rate %}
|
||||||
incl. {{ rate }}% taxes
|
incl. {{ rate }}% taxes
|
||||||
{% endblocktrans %}</small>
|
{% endblocktrans %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -127,7 +128,7 @@
|
|||||||
data-title="{{ item.name }}"
|
data-title="{{ item.name }}"
|
||||||
data-lightbox="{{ item.id }}">
|
data-lightbox="{{ item.id }}">
|
||||||
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
|
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
|
||||||
alt="{{ item.name }}" />
|
alt="{{ item.name }}"/>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<strong>{{ item.name }}</strong>
|
<strong>{{ item.name }}</strong>
|
||||||
@@ -136,9 +137,10 @@
|
|||||||
<div class="col-md-2 col-xs-6 price">
|
<div class="col-md-2 col-xs-6 price">
|
||||||
{{ event.currency }} {{ item.price|floatformat:2 }}
|
{{ event.currency }} {{ item.price|floatformat:2 }}
|
||||||
{% if item.tax_rate %}
|
{% if item.tax_rate %}
|
||||||
<br /><small>{% blocktrans trimmed with rate=item.tax_rate %}
|
<br/>
|
||||||
incl. {{ rate }}% taxes
|
<small>{% blocktrans trimmed with rate=item.tax_rate %}
|
||||||
{% endblocktrans %}</small>
|
incl. {{ rate }}% taxes
|
||||||
|
{% endblocktrans %}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if item.cached_availability.0 == 100 %}
|
{% if item.cached_availability.0 == 100 %}
|
||||||
@@ -156,8 +158,29 @@
|
|||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if event.presale_is_running %}
|
{% if event.presale_is_running %}
|
||||||
|
{% if vouchers_exist %}
|
||||||
|
<div class="row-fluid voucher-row">
|
||||||
|
<div class="col-md-4 col-md-offset-8 col-xs-12">
|
||||||
|
<div id="voucher-box">
|
||||||
|
<label for="voucher">{% trans "Redeem a voucher" %}</label>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="fa fa-ticket fa-fw"></i></span>
|
||||||
|
<input type="text" class="form-control" name="voucher" id="voucher"
|
||||||
|
placeholder="{% trans "Voucher code" %}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="voucher-toggle">
|
||||||
|
<a href="javascript:void(0);">
|
||||||
|
<span class="fa fa-ticket"></span> Redeem a voucher
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="row-fluid checkout-button-row">
|
<div class="row-fluid checkout-button-row">
|
||||||
<div class="col-md-4 col-md-offset-8">
|
<div class="col-md-4 col-md-offset-8 col-xs-12">
|
||||||
<button class="btn btn-block btn-primary btn-lg" type="submit">
|
<button class="btn btn-block btn-primary btn-lg" type="submit">
|
||||||
<i class="fa fa-shopping-cart"></i> {% trans "Add to cart" %}
|
<i class="fa fa-shopping-cart"></i> {% trans "Add to cart" %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ class CartMixin:
|
|||||||
def keyfunc(pos):
|
def keyfunc(pos):
|
||||||
if answers and ((pos.item.admission and self.request.event.settings.attendee_names_asked)
|
if answers and ((pos.item.admission and self.request.event.settings.attendee_names_asked)
|
||||||
or pos.item.questions.all()):
|
or pos.item.questions.all()):
|
||||||
return pos.id, 0, 0, 0
|
return pos.id, 0, 0, 0, None
|
||||||
return 0, pos.item_id, pos.variation_id, pos.price
|
return 0, pos.item_id, pos.variation_id, pos.price, pos.voucher
|
||||||
|
|
||||||
positions = []
|
positions = []
|
||||||
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):
|
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class CartActionMixin:
|
|||||||
def get_error_url(self):
|
def get_error_url(self):
|
||||||
return self.get_next_url()
|
return self.get_next_url()
|
||||||
|
|
||||||
def _items_from_post_data(self):
|
def _items_from_post_data(self, warn=True):
|
||||||
"""
|
"""
|
||||||
Parses the POST data and returns a list of tuples in the
|
Parses the POST data and returns a list of tuples in the
|
||||||
form (item id, variation id or None, number)
|
form (item id, variation id or None, number)
|
||||||
@@ -47,7 +47,7 @@ class CartActionMixin:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
messages.error(self.request, _('Please enter numbers only.'))
|
messages.error(self.request, _('Please enter numbers only.'))
|
||||||
return []
|
return []
|
||||||
if len(items) == 0:
|
if len(items) == 0 and warn:
|
||||||
messages.warning(self.request, _('You did not select any products.'))
|
messages.warning(self.request, _('You did not select any products.'))
|
||||||
return []
|
return []
|
||||||
return items
|
return items
|
||||||
@@ -93,9 +93,11 @@ class CartAdd(EventViewMixin, CartActionMixin, AsyncAction, View):
|
|||||||
return super().get_error_message(exception)
|
return super().get_error_message(exception)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
items = self._items_from_post_data()
|
voucher = self.request.POST.get('voucher')
|
||||||
if items:
|
items = self._items_from_post_data(warn=not voucher)
|
||||||
return self.do(self.request.event.id, items, self.request.session.session_key)
|
if items or voucher:
|
||||||
|
return self.do(self.request.event.id, items, self.request.session.session_key,
|
||||||
|
voucher)
|
||||||
else:
|
else:
|
||||||
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
|
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
|
|||||||
@@ -60,5 +60,11 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
|
|||||||
group[0] is not None and group[0].id is not None) else (0, 0)
|
group[0] is not None and group[0].id is not None) else (0, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
vouchers_exist = self.request.event.get_cache().get('vouchers_exist')
|
||||||
|
if vouchers_exist is None:
|
||||||
|
vouchers_exist = self.request.event.vouchers.exists()
|
||||||
|
self.request.event.get_cache().set('vouchers_exist', vouchers_exist)
|
||||||
|
context['vouchers_exist'] = vouchers_exist
|
||||||
|
|
||||||
context['cart'] = self.get_cart()
|
context['cart'] = self.get_cart()
|
||||||
return context
|
return context
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ $(function () {
|
|||||||
$(this).parent().parent().parent().find(".variations").slideToggle();
|
$(this).parent().parent().parent().find(".variations").slideToggle();
|
||||||
});
|
});
|
||||||
$(".collapsed").removeClass("collapsed").addClass("collapse");
|
$(".collapsed").removeClass("collapsed").addClass("collapse");
|
||||||
|
|
||||||
|
$("#voucher-box").hide();
|
||||||
|
$("#voucher-toggle a").click(function () {
|
||||||
|
$("#voucher-box").slideDown();
|
||||||
|
$("#voucher-toggle").slideUp();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var waitingDialog = {
|
var waitingDialog = {
|
||||||
|
|||||||
Reference in New Issue
Block a user