counter_click.jinja 3.04 KB
Newer Older
Skia's avatar
Skia committed
1
2
{% extends "core/base.jinja" %}

3
4
{% macro add_product(id, content) %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="inline" style="display:inline">
Skia's avatar
Skia committed
5
    {% csrf_token %}
6
7
8
9
10
11
12
13
14
15
    <input type="hidden" name="action" value="add_product">
    <button type="submit" name="product_id" value="{{ id }}"> {{ content }} </button>
</form>
{% endmacro %}

{% macro del_product(id, content) %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="inline" style="display:inline">
    {% csrf_token %}
    <input type="hidden" name="action" value="del_product">
    <button type="submit" name="product_id" value="{{ id }}"> {{ content }} </button>
Skia's avatar
Skia committed
16
17
18
</form>
{% endmacro %}

Skia's avatar
Skia committed
19
20
21
22
{% block content %}
    <h3>Counter</h3>
    <h4>{{ counter }}</h4>
    <p><strong>Club: </strong> {{ counter.club }}</p>
Skia's avatar
Skia committed
23

24
    <div>
Skia's avatar
Skia committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        <h5>Customer</h5>
        <p>{{ customer.user.get_display_name() }}, {{ customer.amount }}</p>
    </div>
    <div>
        <h5>Refilling</h5>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="refill">
            <input type="input" name="amount" value=""/>
            <input type="submit" value="Go" />
        </form>
    </div>
    <div>
        <h5>Selling</h5>
39
40
41
        {% if request.session['not_enough'] %}
            <p><strong>Not enough money</strong></p>
        {% endif %}
Skia's avatar
Skia committed
42
43
44
45
46
47
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="code">
            <input type="input" name="code" value="" autofocus />
            <input type="submit" value="Go" />
        </form>
48
49
        <p>Basket: </p>
        <ul>
50
        {% for id,infos in request.session['basket'].items() %}
51
            {% set product = counter.products.filter(id=id).first() %}
52
53
            {% set s = infos['qty'] * infos['price'] / 100 %}
            <li>{{ del_product(id, '-') }} {{ infos['qty'] }} {{ add_product(id, '+') }} {{ product.name }}: {{ "%0.2f"|format(s) }}</li>
54
55
        {% endfor %}
        </ul>
56
        <p><strong>Total: {{ "%0.2f"|format(basket_total) }}</strong></p>
57
58
59
60
61
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="finish">
            <input type="submit" value="Finish" />
        </form>
62
63
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
64
65
            <input type="hidden" name="action" value="cancel">
            <input type="submit" value="Cancel" />
66
        </form>
67
68
69
70
71
        <p><strong>Products: </strong>
        {% for p in counter.products.all() %}
            {{ add_product(p.id, p.name) }}
        {% endfor %}
        </p>
72
73
    </div>

Skia's avatar
Skia committed
74
75
76
77
{% endblock %}