Waitinglist: Improve waitinglist and logging

This commit is contained in:
Raphael Michel
2017-02-10 11:19:22 +01:00
parent c03ac624fc
commit 8310597944
6 changed files with 16 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ class WaitingListEntry(LoggedModel):
if not self.variation and self.item.has_variations: if not self.variation and self.item.has_variations:
raise ValidationError(_('Please select a specific variation of this product.')) raise ValidationError(_('Please select a specific variation of this product.'))
def send_voucher(self, quota_cache=None): def send_voucher(self, quota_cache=None, user=None):
availability = ( availability = (
self.variation.check_quotas(count_waitinglist=False, _cache=quota_cache) self.variation.check_quotas(count_waitinglist=False, _cache=quota_cache)
if self.variation if self.variation
@@ -108,8 +108,8 @@ class WaitingListEntry(LoggedModel):
'max_usages': 1, 'max_usages': 1,
'email': self.email, 'email': self.email,
'waitinglistentry': self.pk 'waitinglistentry': self.pk
}) }, user=user)
self.log_action('pretix.waitinglist.voucher') self.log_action('pretix.waitinglist.voucher', user=user)
self.voucher = v self.voucher = v
self.save() self.save()

View File

@@ -1,6 +1,6 @@
from django.dispatch import receiver from django.dispatch import receiver
from pretix.base.models import Event, WaitingListEntry from pretix.base.models import Event, User, WaitingListEntry
from pretix.base.models.waitinglist import WaitingListException from pretix.base.models.waitinglist import WaitingListException
from pretix.base.services.async import ProfiledTask from pretix.base.services.async import ProfiledTask
from pretix.base.signals import periodic_task from pretix.base.signals import periodic_task
@@ -8,8 +8,12 @@ from pretix.celery_app import app
@app.task(base=ProfiledTask) @app.task(base=ProfiledTask)
def assign_automatically(event_id: int): def assign_automatically(event_id: int, user_id: int = None):
event = Event.objects.get(id=event_id) event = Event.objects.get(id=event_id)
if user_id:
user = User.objects.get(id=user_id)
else:
user = None
quota_cache = {} quota_cache = {}
gone = set() gone = set()
@@ -31,7 +35,7 @@ def assign_automatically(event_id: int):
) )
if availability[1] > 0: if availability[1] > 0:
try: try:
wle.send_voucher(quota_cache) wle.send_voucher(quota_cache, user=user)
sent += 1 sent += 1
except WaitingListException: # noqa except WaitingListException: # noqa
continue continue

View File

@@ -54,7 +54,7 @@
{% trans "Sales estimate" %} {% trans "Sales estimate" %}
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% blocktrans trimmed with amount=estimate|floatformat:2 currency=request.event.currency %} {% blocktrans trimmed with amount=estimate|default:0|floatformat:2 currency=request.event.currency %}
If you can make enough room at your event to fit all the persons on the waiting list in, you If you can make enough room at your event to fit all the persons on the waiting list in, you
could sell tickets worth an additional <strong>{{ amount }} {{ currency }}</strong>. could sell tickets worth an additional <strong>{{ amount }} {{ currency }}</strong>.
{% endblocktrans %} {% endblocktrans %}

View File

@@ -32,7 +32,7 @@ class AutoAssign(EventPermissionRequiredMixin, AsyncAction, View):
}) })
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
return self.do(self.request.event.id) return self.do(self.request.event.id, self.request.user.id)
class WaitingListView(EventPermissionRequiredMixin, ListView): class WaitingListView(EventPermissionRequiredMixin, ListView):
@@ -55,7 +55,7 @@ class WaitingListView(EventPermissionRequiredMixin, ListView):
pk=request.POST.get('assign'), event=self.request.event, pk=request.POST.get('assign'), event=self.request.event,
) )
try: try:
wle.send_voucher() wle.send_voucher(user=request.user)
except WaitingListException as e: except WaitingListException as e:
messages.error(request, str(e)) messages.error(request, str(e))
else: else:

View File

@@ -17,8 +17,8 @@
<div class="form-group"> <div class="form-group">
<div class="col-md-9 col-md-offset-3"> <div class="col-md-9 col-md-offset-3">
<div class="help-block"> <div class="help-block">
{% blocktrans trimmed %} {% blocktrans trimmed with hours=event.settings.waiting_list_hours %}
If tickets become available again, we will inform the first persons on the waiting list. If we notify you, you'll have 48 hours time to buy a ticket until we assign it to the next person on the list. If tickets become available again, we will inform the first persons on the waiting list. If we notify you, you'll have {{ hours }} hours time to buy a ticket until we assign it to the next person on the list.
{% endblocktrans %} {% endblocktrans %}
</div> </div>
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">

View File

@@ -63,7 +63,7 @@ class WaitingView(FormView):
else self.item_and_variation[0].check_quotas(count_waitinglist=False) else self.item_and_variation[0].check_quotas(count_waitinglist=False)
) )
if availability[0] == 100: if availability[0] == 100:
messages.error(self.request, _("You cannot add yourself to the waiting list as this product ist currently " messages.error(self.request, _("You cannot add yourself to the waiting list as this product is currently "
"available.")) "available."))
return redirect(eventreverse(self.request.event, 'presale:event.index')) return redirect(eventreverse(self.request.event, 'presale:event.index'))