Skip to content
Snippets Groups Projects
Commit b16b5325 authored by Pelle Koster's avatar Pelle Koster
Browse files

fix setting extras paid status, allow deleting orders for visitor for testing purposes

parent a1eafbb9
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ from typing import Sequence ...@@ -2,7 +2,7 @@ from typing import Sequence
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from stripe_checkout.stripe_checkout.models import ItemKind, PricedItem from stripe_checkout.stripe_checkout.models import ItemKind, Order, PricedItem
from . import visit from . import visit
from django.views.decorators.http import require_GET, require_POST from django.views.decorators.http import require_GET, require_POST
...@@ -47,12 +47,13 @@ def update_visitor(request, visitor_id): ...@@ -47,12 +47,13 @@ def update_visitor(request, visitor_id):
data = request.POST data = request.POST
all_answers = {} all_answers = {}
for extra in all_extras: for extra in all_extras:
question = extra.visit_checkout_question_id for question, answer in [
answer = extra.visit_checkout_answer_id (extra.visit_checkout_question_id, extra.visit_checkout_answer_id),
all_answers.setdefault(question, set()) (extra.visit_paid_question_id, extra.visit_paid_answer_id),
if data.get(f"{question}:{answer}"): ]:
all_answers[question].add(answer) all_answers.setdefault(question, set())
if data.get(f"{question}:{answer}"):
all_answers[question].add(answer)
for question, answers in all_answers.items(): for question, answers in all_answers.items():
visitor.set_answers(question, answers) visitor.set_answers(question, answers)
if registration_type := data.get("registration_type"): if registration_type := data.get("registration_type"):
...@@ -60,3 +61,10 @@ def update_visitor(request, visitor_id): ...@@ -60,3 +61,10 @@ def update_visitor(request, visitor_id):
visitor.paid = data.get("paid") visitor.paid = data.get("paid")
api.update_visitor(visitor) api.update_visitor(visitor)
return redirect("stripe_checkout:list-visitors") return redirect("stripe_checkout:list-visitors")
@login_required
@require_POST
def delete_orders(request, visitor_id):
Order.objects.filter(visitor_id=visitor_id).delete()
return redirect("stripe_checkout:list-visitors")
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
{% block body %} {% block body %}
<div> <div>
<h1>Manage visitors</h1> <h1>Manage visitors</h1>
<h2 style="color: red">Warning: Be careful, you may break things here</h2>
<table> <table>
<thead> <thead>
<tr> <tr>
...@@ -51,7 +52,7 @@ ...@@ -51,7 +52,7 @@
<span>(paid <span> <span>(paid <span>
<input type="checkbox" <input type="checkbox"
form="{{ visitor.id }}_checkout_update_form" form="{{ visitor.id }}_checkout_update_form"
name="{{ item.visit_checkout_question_id }}:{{ item.visit_checkout_answer_id }}:paid" name="{{ item.visit_paid_question_id }}:{{ item.visit_paid_answer_id }}"
autocomplete="off" autocomplete="off"
{% if visitor|has_paid:item %}checked{% endif %}> {% if visitor|has_paid:item %}checked{% endif %}>
</span>)</span> </span>)</span>
...@@ -65,6 +66,14 @@ ...@@ -65,6 +66,14 @@
<button>Update</button> <button>Update</button>
</form> </form>
</td> </td>
<td>
<form id="{{ visitor.id }}_delete_orders"
method="post"
action="{% url 'stripe_checkout:delete-orders' visitor_id=visitor.id %}">
{% csrf_token %}
<button>Delete orders</button>
</form>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
......
from django.urls import include, path, re_path from django.urls import include, path, re_path
from .management_views import update_visitor, list_visitors, index from .management_views import delete_orders, update_visitor, list_visitors, index
from .visit_views import stripe_event, checkout, checkout_success from .visit_views import stripe_event, checkout, checkout_success
visitor_id = r"(?P<visitor_id>[a-z0-9]+)" visitor_id = r"(?P<visitor_id>[a-z0-9]+)"
...@@ -11,6 +11,7 @@ urlpatterns = [ ...@@ -11,6 +11,7 @@ urlpatterns = [
"visitors/", "visitors/",
include( include(
[ [
re_path(f"{visitor_id}/delete_orders/", delete_orders, name="delete-orders"),
re_path(f"{visitor_id}/", update_visitor, name="update-visitor"), re_path(f"{visitor_id}/", update_visitor, name="update-visitor"),
path("", list_visitors, name="list-visitors"), path("", list_visitors, name="list-visitors"),
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment