mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-24 18:14:22 +00:00
second patch on eboutic
This commit is contained in:
parent
96510b270d
commit
60eff1000f
@ -184,9 +184,7 @@
|
||||
</div>
|
||||
<a href="{{ url('forum:main') }}">{% trans %}Forum{% 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>
|
||||
{% endif %}
|
||||
<div class="dropdown">
|
||||
<button class="dropbtn">{% trans %}Services{% endtrans %}
|
||||
<i class="fa fa-caret-down"></i>
|
||||
|
18
counter/migrations/0018_producttype_priority.py
Normal file
18
counter/migrations/0018_producttype_priority.py
Normal 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),
|
||||
),
|
||||
]
|
@ -133,8 +133,13 @@ class ProductType(models.Model):
|
||||
comment = models.TextField(_("comment"), 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:
|
||||
verbose_name = _("product type")
|
||||
ordering = ["-priority", "name"]
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
|
@ -954,7 +954,7 @@ class ProductTypeCreateView(CounterAdminTabsMixin, CounterAdminMixin, CreateView
|
||||
"""
|
||||
|
||||
model = ProductType
|
||||
fields = ["name", "description", "comment", "icon"]
|
||||
fields = ["name", "description", "comment", "icon", "priority"]
|
||||
template_name = "core/create.jinja"
|
||||
current_tab = "products"
|
||||
|
||||
@ -966,7 +966,7 @@ class ProductTypeEditView(CounterAdminTabsMixin, CounterAdminMixin, UpdateView):
|
||||
|
||||
model = ProductType
|
||||
template_name = "core/edit.jinja"
|
||||
fields = ["name", "description", "comment", "icon"]
|
||||
fields = ["name", "description", "comment", "icon", "priority"]
|
||||
pk_url_kwarg = "type_id"
|
||||
current_tab = "products"
|
||||
|
||||
|
@ -41,7 +41,9 @@ def get_eboutic_products(user: User) -> List[Product]:
|
||||
.products.filter(product_type__isnull=False)
|
||||
.filter(archived=False)
|
||||
.filter(limit_age__lte=user.age)
|
||||
.annotate(priority=F("product_type__priority"))
|
||||
.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)]
|
||||
|
||||
|
@ -88,15 +88,16 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for category, items in products|groupby('category') %}
|
||||
{% for priority_groups in products|groupby('priority')|reverse %}
|
||||
{% for category, items in priority_groups.list|groupby('category') %}
|
||||
{% if items|count > 0 %}
|
||||
<section>
|
||||
{# I would have wholeheartedly directly used the header element instead
|
||||
but it has already been made messy in core/style.scss #}
|
||||
<div class="category-header">
|
||||
<h3>{{ category }}</h3>
|
||||
{% if category.comment %}
|
||||
<p>{{ category.comment }}</p>
|
||||
{% if items[0].category_comment %}
|
||||
<p><i>{{ items[0].category_comment }}</i></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="product-group">
|
||||
@ -116,6 +117,7 @@
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>{% trans %}There are no items available for sale{% endtrans %}</p>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user