Remove initial.json (food) mandatory allergen are directly created in migration. Edit tables.py and views.py transformedfoodlist.html to improve/change the view. Edit base.html, urls.py to correct little mistakes. Edit initial.json (permission) to begin permission for food apps and create a new role (Respo Bouffe).

This commit is contained in:
quark 2024-08-13 02:07:32 +02:00
parent b2b1f03b46
commit 196df1e775
7 changed files with 154 additions and 138 deletions

View File

@ -1,107 +0,0 @@
[
{
"model": "food.allergen",
"pk": 1,
"fields": {
"name": "alcohol"
}
},
{
"model": "food.allergen",
"pk": 2,
"fields": {
"name": "celery"
}
},
{
"model": "food.allergen",
"pk": 3,
"fields": {
"name": "crustecean"
}
},
{
"model": "food.allergen",
"pk": 4,
"fields": {
"name": "egg"
}
},
{
"model": "food.allergen",
"pk": 5,
"fields": {
"name": "fish"
}
},
{
"model": "food.allergen",
"pk": 6,
"fields": {
"name": "gluten"
}
},
{
"model": "food.allergen",
"pk": 7,
"fields": {
"name": "groundnut"
}
},
{
"model": "food.allergen",
"pk": 8,
"fields": {
"name": "lupine"
}
},
{
"model": "food.allergen",
"pk": 9,
"fields": {
"name": "milk"
}
},
{
"model": "food.allergen",
"pk": 10,
"fields": {
"name": "mollusc"
}
},
{
"model": "food.allergen",
"pk": 11,
"fields": {
"name": "mustard"
}
},
{
"model": "food.allergen",
"pk": 12,
"fields": {
"name": "nut"
}
},
{
"model": "food.allergen",
"pk": 13,
"fields": {
"name": "sesame"
}
},
{
"model": "food.allergen",
"pk": 14,
"fields": {
"name": "soy"
}
},
{
"model": "food.allergen",
"pk": 15,
"fields": {
"name": "sulphite"
}
}
]

View File

@ -16,4 +16,4 @@ class TransformedFoodTable(tables.Table):
class Meta: class Meta:
model = TransformedFood model = TransformedFood
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
fields = ('name', ) fields = ('name', "owner", "allergens", "expiry_date")

View File

@ -7,18 +7,54 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% block content %} {% block content %}
<div class="card bg-light mb-3"> <div class="card bg-light mb-3">
<h3 class="card-header text-center">
{% trans "Meal served" %}
</h3>
{% if can_create_meal %}
<div class="card-footer"> <div class="card-footer">
<a class="btn btn-sm btn-success" href="{% url 'food:transformed_create' %}" data-turbolinks="false"> <a class="btn btn-sm btn-success" href="{% url 'food:transformed_create' %}" data-turbolinks="false">
{% trans 'New meal' %} {% trans 'New meal' %}
</a> </a>
</div> </div>
{% endif %}
{% if served.data %}
{% render_table served %}
{% else %}
<div class="card-body">
<div class="alert alert-warning">
{% trans "There is no meal served." %}
</div>
</div>
{% endif %}
</div>
<div class="card bg-light mb-3">
<h3 class="card-header text-center"> <h3 class="card-header text-center">
{% trans 'In preparation' %} {% trans "Open" %}
</h3> </h3>
{% if open.data %}
{% render_table open %}
{% else %}
<div> class="card-body">
<div class="alert alert-warning">
{% trans "There is no free meal." %}
</div>
</div>
{% endif %}
</div>
<div class="card bg-light mb-3">
<h3 class="card-header text-center">
{% trans "All meals" %}
</h3>
{% if table.data %}
{% render_table table %} {% render_table table %}
<h3 class="card-header text-center"> {% else %}
{% trans 'Free' %} <div> class="card-body">
</h3> <div class="alert alert-warning">
{% render_table open_table %} {% trans "There is no meal." %}
</div>
</div>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -8,7 +8,7 @@ from . import views
app_name = 'food' app_name = 'food'
urlpatterns = [ urlpatterns = [
path('', views.TransfomedListView.as_view(), name='food_list'), path('', views.TransformedListView.as_view(), name='food_list'),
path('<int:slug>', views.QRCodeView.as_view(), name='qrcode_view'), path('<int:slug>', views.QRCodeView.as_view(), name='qrcode_view'),
path('detail/<int:pk>', views.FoodView.as_view(), name='food_view'), path('detail/<int:pk>', views.FoodView.as_view(), name='food_view'),

View File

@ -4,12 +4,16 @@
from django.db import transaction from django.db import transaction
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django_tables2.views import SingleTableView from django_tables2.views import MultiTableMixin
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils import timezone from django.utils import timezone
from django.views.generic import DetailView, UpdateView, TemplateView from django.views.generic import DetailView, UpdateView, TemplateView
from django.views.generic.list import ListView
from permission.backends import PermissionBackend
from permission.views import ProtectQuerysetMixin, ProtectedCreateView from permission.views import ProtectQuerysetMixin, ProtectedCreateView
from member.models import Club
from note_kfet.middlewares import get_current_request
from .forms import AddIngredientForms, BasicFoodForms, QRCodeForms, TransformedFoodForms from .forms import AddIngredientForms, BasicFoodForms, QRCodeForms, TransformedFoodForms
from .models import BasicFood, Food, QRCode, TransformedFood from .models import BasicFood, Food, QRCode, TransformedFood
@ -253,26 +257,46 @@ class TransformedFoodCreateView(TransformedFoodFormView, ProtectedCreateView):
) )
class TransfomedListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): class TransformedListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, ListView):
""" """
Displays not ready TransformedFood Displays ready TransformedFood
""" """
model = TransformedFood model = TransformedFood
table_class = TransformedFoodTable tables = [TransformedFoodTable, TransformedFoodTable, TransformedFoodTable]
ordering = ('name',)
extra_context = {"title": _("Transformed food")} extra_context = {"title": _("Transformed food")}
def get_queryset(self, **kwargs): def get_queryset(self, **kwargs):
return super().get_queryset(**kwargs)\ return super().get_queryset(**kwargs).distinct()
.filter(is_ready=False)\
def get_tables(self):
tables = super().get_tables()
tables[0].prefix = "all-"
tables[1].prefix = "open-"
tables[2].prefix = "served-"
return tables
def get_tables_data(self):
# first table = all transformed food, second table = free, third = served
return [
self.get_queryset().order_by("-creation_date"),
TransformedFood.objects.filter(is_ready=True,is_active=True,was_eaten=False,expiry_date__lt=timezone.now())
.filter(PermissionBackend.filter_queryset(self.request, TransformedFood, "view"))
.distinct() .distinct()
.order_by("-creation_date"),
TransformedFood.objects.filter(is_ready=True,is_active=True,was_eaten=False,expiry_date__gte=timezone.now())
.filter(PermissionBackend.filter_queryset(self.request, TransformedFood, "view"))
.distinct()
.order_by("-creation_date")
]
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['open_table'] = TransformedFoodTable(
TransformedFood.objects.filter( # context["can_create_meal"] = PermissionBackend.check_perm(self.request, "food.add_transformedfood", TransformedFood(creation_date = timezone.now(), name = "", expiry_date = timezone.now(), owner = )) <- défi prendre un club qui fonctionne (s'il existe) pour l'utilisateur
was_eaten=False, context["can_create_meal"] = True
expiry_date__lt=timezone.now()
), tables = context["tables"]
prefix="open-") for name, table in zip(["table", "open", "served"], tables):
context[name] = table
return context return context

View File

@ -3111,6 +3111,54 @@
"description": "Voir ceux nous ayant pour ami, pour toujours" "description": "Voir ceux nous ayant pour ami, pour toujours"
} }
}, },
{
"model": "permission.permission",
"pk": 199,
"fields": {
"model": [
"food",
"transformedfood"
],
"query": "",
"type": "view",
"mask": 3,
"field": "",
"permanent": false,
"description": "Voir tout les plats"
}
},
{
"model": "permission.permission",
"pk": 200,
"fields": {
"model": [
"food",
"transformedfood"
],
"query": "{\"owner\": \"club\"}",
"type": "view",
"mask": 3,
"field": "",
"permanent": false,
"description": "Voir tout les plats de son club"
}
},
{
"model": "permission.permission",
"pk": 200,
"fields": {
"model": [
"food",
"transformedfood"
],
"query": "{\"is_ready\": true, \"is_active\": true, \"was_eaten\": false}",
"type": "view",
"mask": 1,
"field": "",
"permanent": false,
"description": "Voir les plats préparés actifs servis"
}
},
{ {
"model": "permission.role", "model": "permission.role",
"pk": 1, "pk": 1,
@ -3190,7 +3238,8 @@
157, 157,
158, 158,
159, 159,
160 160,
200
] ]
} }
}, },
@ -3216,7 +3265,8 @@
49, 49,
50, 50,
141, 141,
169 169,
199
] ]
} }
}, },
@ -3390,7 +3440,8 @@
166, 166,
167, 167,
168, 168,
182 182,
199
] ]
} }
}, },
@ -3594,7 +3645,8 @@
168, 168,
176, 176,
177, 177,
197 197,
199
] ]
} }
}, },
@ -3612,6 +3664,17 @@
] ]
} }
}, },
{
"model": "permission.role",
"pk": 22,
"fields": {
"for_club": 2,
"name": "Respo Bouffe",
"permissions": [
199
]
}
},
{ {
"model": "wei.weirole", "model": "wei.weirole",
"pk": 12, "pk": 12,

View File

@ -69,7 +69,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<li class="nav-item"> <li class="nav-item">
{% url 'food:food_list' as url %} {% url 'food:food_list' as url %}
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-cutlery"></i>_{% trans 'Food' %}</a> <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-cutlery"></i> {% trans 'Food' %}</a>
</li> </li>
{% endif %} {% endif %}
{% if user.is_authenticated and user|is_member:"Kfet" %} {% if user.is_authenticated and user|is_member:"Kfet" %}