second patch on eboutic

This commit is contained in:
Thomas Girod 2022-11-16 20:41:24 +01:00
parent 96510b270d
commit 60eff1000f
6 changed files with 106 additions and 81 deletions

View File

@ -184,9 +184,7 @@
</div> </div>
<a href="{{ url('forum:main') }}">{% trans %}Forum{% endtrans %}</a> <a href="{{ url('forum:main') }}">{% trans %}Forum{% endtrans %}</a>
<a href="{{ url('sas:main') }}">{% trans %}Gallery{% endtrans %}</a> <a href="{{ url('sas:main') }}">{% trans %}Gallery{% endtrans %}</a>
{% if request.user.is_authenticated %} <a href="{{ url('eboutic:main') }}">{% trans %}Eboutic{% endtrans %}</a>
<a href="{{ url('eboutic:main') }}">{% trans %}Eboutic{% endtrans %}</a>
{% endif %}
<div class="dropdown"> <div class="dropdown">
<button class="dropbtn">{% trans %}Services{% endtrans %} <button class="dropbtn">{% trans %}Services{% endtrans %}
<i class="fa fa-caret-down"></i> <i class="fa fa-caret-down"></i>

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2022-11-16 18:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("counter", "0017_studentcard"),
]
operations = [
migrations.AddField(
model_name="producttype",
name="priority",
field=models.PositiveIntegerField(default=0),
),
]

View File

@ -133,8 +133,13 @@ class ProductType(models.Model):
comment = models.TextField(_("comment"), null=True, blank=True) comment = models.TextField(_("comment"), null=True, blank=True)
icon = models.ImageField(upload_to="products", null=True, blank=True) icon = models.ImageField(upload_to="products", null=True, blank=True)
# priority holds no real backend logic but helps to handle the order in which
# the items are to be shown to the user
priority = models.PositiveIntegerField(default=0)
class Meta: class Meta:
verbose_name = _("product type") verbose_name = _("product type")
ordering = ["-priority", "name"]
def is_owned_by(self, user): def is_owned_by(self, user):
""" """

View File

@ -954,7 +954,7 @@ class ProductTypeCreateView(CounterAdminTabsMixin, CounterAdminMixin, CreateView
""" """
model = ProductType model = ProductType
fields = ["name", "description", "comment", "icon"] fields = ["name", "description", "comment", "icon", "priority"]
template_name = "core/create.jinja" template_name = "core/create.jinja"
current_tab = "products" current_tab = "products"
@ -966,7 +966,7 @@ class ProductTypeEditView(CounterAdminTabsMixin, CounterAdminMixin, UpdateView):
model = ProductType model = ProductType
template_name = "core/edit.jinja" template_name = "core/edit.jinja"
fields = ["name", "description", "comment", "icon"] fields = ["name", "description", "comment", "icon", "priority"]
pk_url_kwarg = "type_id" pk_url_kwarg = "type_id"
current_tab = "products" current_tab = "products"

View File

@ -41,7 +41,9 @@ def get_eboutic_products(user: User) -> List[Product]:
.products.filter(product_type__isnull=False) .products.filter(product_type__isnull=False)
.filter(archived=False) .filter(archived=False)
.filter(limit_age__lte=user.age) .filter(limit_age__lte=user.age)
.annotate(priority=F("product_type__priority"))
.annotate(category=F("product_type__name")) .annotate(category=F("product_type__name"))
.annotate(category_comment=F("product_type__comment"))
) )
return [p for p in products if p.can_be_sold_to(user)] return [p for p in products if p.can_be_sold_to(user)]

View File

@ -23,56 +23,56 @@
<h1 id="eboutic-title">{% trans %}Eboutic{% endtrans %}</h1> <h1 id="eboutic-title">{% trans %}Eboutic{% endtrans %}</h1>
<div id="eboutic" x-data="basket"> <div id="eboutic" x-data="basket">
<div id="basket"> <div id="basket">
<h3>Panier</h3> <h3>Panier</h3>
{% if errors %} {% if errors %}
<div class="error-message"> <div class="error-message">
{% for error in errors %} {% for error in errors %}
<p>{{ error }}</p> <p>{{ error }}</p>
{% endfor %} {% endfor %}
{% trans %}Your basket has been cleaned accordingly to those errors.{% endtrans %} {% trans %}Your basket has been cleaned accordingly to those errors.{% endtrans %}
</div>
{% endif %}
<ul class="item-list">
{# Starting money #}
<li>
<span class="item-name">
<strong>{% trans %}Current account amount: {% endtrans %}</strong>
</span>
<span class="item-price">
<strong>{{ "%0.2f"|format(customer_amount) }} €</strong>
</span>
</li>
<template x-for="item in items" :key="item.id">
<li class="item-row" x-show="item.quantity > 0">
<span class="item-name" x-text="item.name"></span>
<div class="item-quantity">
<i class="fa fa-minus fa-xs" @click="remove(item.id)"></i>
<span x-text="item.quantity"></span>
<i class="fa fa-plus" @click="add(item)"></i>
</div>
<span class="item-price" x-text="(item.unit_price * item.quantity).toFixed(2) + ' €'"></span>
</li>
</template>
{# Total price #}
<li style="margin-top: 20px">
<span class="item-name"><strong>{% trans %}Basket amount: {% endtrans %}</strong></span>
<span x-text="get_total().toFixed(2) + ' €'" class="item-price"></span>
</li>
</ul>
<div class="catalog-buttons">
<button @click="clear_basket()" class="clear">
<i class="fa fa-trash"></i>
{% trans %}Clear{% endtrans %}
</button>
<form method="post" action="{{ url('eboutic:command') }}">
{% csrf_token %}
<button class="validate">
<i class="fa fa-check"></i>
<input type="submit" value="{% trans %}Validate{% endtrans %}"/>
</button>
</form>
</div> </div>
{% endif %}
<ul class="item-list">
{# Starting money #}
<li>
<span class="item-name">
<strong>{% trans %}Current account amount: {% endtrans %}</strong>
</span>
<span class="item-price">
<strong>{{ "%0.2f"|format(customer_amount) }} €</strong>
</span>
</li>
<template x-for="item in items" :key="item.id">
<li class="item-row" x-show="item.quantity > 0">
<span class="item-name" x-text="item.name"></span>
<div class="item-quantity">
<i class="fa fa-minus fa-xs" @click="remove(item.id)"></i>
<span x-text="item.quantity"></span>
<i class="fa fa-plus" @click="add(item)"></i>
</div>
<span class="item-price" x-text="(item.unit_price * item.quantity).toFixed(2) + ' €'"></span>
</li>
</template>
{# Total price #}
<li style="margin-top: 20px">
<span class="item-name"><strong>{% trans %}Basket amount: {% endtrans %}</strong></span>
<span x-text="get_total().toFixed(2) + ' €'" class="item-price"></span>
</li>
</ul>
<div class="catalog-buttons">
<button @click="clear_basket()" class="clear">
<i class="fa fa-trash"></i>
{% trans %}Clear{% endtrans %}
</button>
<form method="post" action="{{ url('eboutic:command') }}">
{% csrf_token %}
<button class="validate">
<i class="fa fa-check"></i>
<input type="submit" value="{% trans %}Validate{% endtrans %}"/>
</button>
</form>
</div> </div>
</div>
<div id="catalog"> <div id="catalog">
{% if not request.user.date_of_birth %} {% if not request.user.date_of_birth %}
<div class="alert" x-data="{show_alert: true}" x-show="show_alert" x-transition> <div class="alert" x-data="{show_alert: true}" x-show="show_alert" x-transition>
@ -88,35 +88,37 @@
</div> </div>
{% endif %} {% endif %}
{% for category, items in products|groupby('category') %} {% for priority_groups in products|groupby('priority')|reverse %}
{% if items|count > 0 %} {% for category, items in priority_groups.list|groupby('category') %}
<section> {% if items|count > 0 %}
{# I would have wholeheartedly directly used the header element instead <section>
but it has already been made messy in core/style.scss #} {# I would have wholeheartedly directly used the header element instead
<div class="category-header"> but it has already been made messy in core/style.scss #}
<h3>{{ category }}</h3> <div class="category-header">
{% if category.comment %} <h3>{{ category }}</h3>
<p>{{ category.comment }}</p> {% if items[0].category_comment %}
{% endif %} <p><i>{{ items[0].category_comment }}</i></p>
</div> {% endif %}
<div class="product-group"> </div>
{% for p in items %} <div class="product-group">
<button class="product-button" {% for p in items %}
@click='add_from_catalog({{ p.id }}, {{ p.name|tojson }}, {{ p.selling_price }})'> <button class="product-button"
{% if p.icon %} @click='add_from_catalog({{ p.id }}, {{ p.name|tojson }}, {{ p.selling_price }})'>
<img src="{{ p.icon.url }}" alt="image de {{ p.name }}" {% if p.icon %}
width="40px" height="40px"> <img src="{{ p.icon.url }}" alt="image de {{ p.name }}"
{% else %} width="40px" height="40px">
<i class="fa fa-2x fa-picture-o"></i> {% else %}
{% endif %} <i class="fa fa-2x fa-picture-o"></i>
<p><strong>{{ p.name }}</strong></p> {% endif %}
<p>{{ p.selling_price }} €</p> <p><strong>{{ p.name }}</strong></p>
</button> <p>{{ p.selling_price }} €</p>
{% endfor %} </button>
</div> {% endfor %}
</section> </div>
{% endif %} </section>
{% else %} {% endif %}
{% endfor %}
{% else %}
<p>{% trans %}There are no items available for sale{% endtrans %}</p> <p>{% trans %}There are no items available for sale{% endtrans %}</p>
{% endfor %} {% endfor %}
</div> </div>