Skip to content

Commit

Permalink
feat: proper logic structure, handle edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
fronbasal committed Mar 16, 2024
1 parent acd47d3 commit 6332911
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Pretix Check-in/out buttons on Order Page
# Pretix Check-in buttons on Order Page

This is a plugin for [pretix](https://github.com/pretix/pretix).

Add a check-in button to the order detail and overview page.

### TODOs:

- [ ] Handle "checked in but left" case

Adds check-in related buttons to the order overview page.

### Warning

Expand Down
2 changes: 1 addition & 1 deletion pretix_order_checkin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.4"
__version__ = "1.1.0"
56 changes: 33 additions & 23 deletions pretix_order_checkin/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Register your receivers here
from django.db.models import Q, Exists
from django.db.models import Q
from django.dispatch import receiver
from django.template.loader import render_to_string

Expand All @@ -20,28 +20,38 @@ def order_position_buttons(
if not checkin_list:
return

checked_in = position.checkins.filter(list=checkin_list, successful=True).all()

# TODO: Handle "checked in but left" case
if not checked_in.exists():
return render_to_string(
"pretix_order_checkin/checkin_button.html",
{
"event": order.event,
"checkinlist": checkin_list,
"item": position.id,
"returnquery": f"user={order.code}&item={position.item.id}",
},
request=request,
output_html = ""

checkins = position.checkins.filter(list=checkin_list, successful=True).order_by(
"-datetime"
)
has_left = (
False if not checkins.exists() else checkins.first().type == Checkin.TYPE_EXIT
)

template_ctx = {
"event": order.event,
"checkinlist": checkin_list,
"item": position.id,
"returnquery": f"user={order.code}&item={position.item.id}",
}

if has_left or not checkins.exists():
output_html += render_to_string(
"pretix_order_checkin/check_in_button.html", template_ctx, request=request
)
else:
return render_to_string(
"pretix_order_checkin/checked_out_buttons.html",
{
"event": order.event,
"checkinlist": checkin_list,
"item": position.id,
"returnquery": f"user={order.code}&item={position.item.id}",
},

if checkins.exists():
if not has_left:
output_html += render_to_string(
"pretix_order_checkin/check_out_button.html",
template_ctx,
request=request,
)
output_html += render_to_string(
"pretix_order_checkin/delete_check_in_button.html",
template_ctx,
request=request,
)

return output_html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
<input name="returnquery" type="hidden" value="{{ returnquery }}">
<input name="checkin" type="hidden" value="{{ item }}">
{% csrf_token %}
<button
class="btn btn-xs btn-danger"
type="submit"
name="revert"
formaction="{% url "control:event.orders.checkinlists.bulk_revert" event=event.slug organizer=event.organizer.slug list=checkinlist.pk %}"
data-no-asynctask
value="true">
<span class="fa fa-trash"></span>
{% trans "Delete Check-in" %}
</button>

<button class="btn btn-xs btn-warning" type="submit" name="checkout" value="true">
<span class="fa fa-sign-out"></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load i18n %}
{% load bootstrap3 %}

<form method="post" action="{% url "control:event.orders.checkinlists.bulk_revert" event=event.slug organizer=event.organizer.slug list=checkinlist.pk %}" class="form-inline helper-display-inline">
<input name="returnquery" type="hidden" value="{{ returnquery }}">
<input name="checkin" type="hidden" value="{{ item }}">
{% csrf_token %}
<button class="btn btn-xs btn-danger" type="submit" name="revert" value="true">
<span class="fa fa-trash"></span>
{% trans "Delete Check-in" %}
</button>
</form>

0 comments on commit 6332911

Please sign in to comment.