mirror of https://gitlab.crans.org/bde/nk20
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:
parent
b2b1f03b46
commit
196df1e775
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -16,4 +16,4 @@ class TransformedFoodTable(tables.Table):
|
|||
class Meta:
|
||||
model = TransformedFood
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('name', )
|
||||
fields = ('name', "owner", "allergens", "expiry_date")
|
||||
|
|
|
@ -7,18 +7,54 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
||||
{% block content %}
|
||||
<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">
|
||||
<a class="btn btn-sm btn-success" href="{% url 'food:transformed_create' %}" data-turbolinks="false">
|
||||
{% trans 'New meal' %}
|
||||
</a>
|
||||
</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">
|
||||
{% trans 'In preparation' %}
|
||||
{% trans "Open" %}
|
||||
</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 %}
|
||||
<h3 class="card-header text-center">
|
||||
{% trans 'Free' %}
|
||||
</h3>
|
||||
{% render_table open_table %}
|
||||
{% else %}
|
||||
<div> class="card-body">
|
||||
<div class="alert alert-warning">
|
||||
{% trans "There is no meal." %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -8,7 +8,7 @@ from . import views
|
|||
app_name = 'food'
|
||||
|
||||
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('detail/<int:pk>', views.FoodView.as_view(), name='food_view'),
|
||||
|
||||
|
|
|
@ -4,12 +4,16 @@
|
|||
from django.db import transaction
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django_tables2.views import SingleTableView
|
||||
from django_tables2.views import MultiTableMixin
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils import timezone
|
||||
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 member.models import Club
|
||||
from note_kfet.middlewares import get_current_request
|
||||
|
||||
from .forms import AddIngredientForms, BasicFoodForms, QRCodeForms, TransformedFoodForms
|
||||
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
|
||||
table_class = TransformedFoodTable
|
||||
ordering = ('name',)
|
||||
tables = [TransformedFoodTable, TransformedFoodTable, TransformedFoodTable]
|
||||
extra_context = {"title": _("Transformed food")}
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
return super().get_queryset(**kwargs)\
|
||||
.filter(is_ready=False)\
|
||||
.distinct()
|
||||
return super().get_queryset(**kwargs).distinct()
|
||||
|
||||
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()
|
||||
.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):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['open_table'] = TransformedFoodTable(
|
||||
TransformedFood.objects.filter(
|
||||
was_eaten=False,
|
||||
expiry_date__lt=timezone.now()
|
||||
),
|
||||
prefix="open-")
|
||||
|
||||
# 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
|
||||
context["can_create_meal"] = True
|
||||
|
||||
tables = context["tables"]
|
||||
for name, table in zip(["table", "open", "served"], tables):
|
||||
context[name] = table
|
||||
return context
|
||||
|
|
|
@ -3111,6 +3111,54 @@
|
|||
"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",
|
||||
"pk": 1,
|
||||
|
@ -3148,11 +3196,11 @@
|
|||
187,
|
||||
188,
|
||||
189,
|
||||
190,
|
||||
191,
|
||||
195,
|
||||
196,
|
||||
198
|
||||
190,
|
||||
191,
|
||||
195,
|
||||
196,
|
||||
198
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -3190,7 +3238,8 @@
|
|||
157,
|
||||
158,
|
||||
159,
|
||||
160
|
||||
160,
|
||||
200
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -3216,7 +3265,8 @@
|
|||
49,
|
||||
50,
|
||||
141,
|
||||
169
|
||||
169,
|
||||
199
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -3390,7 +3440,8 @@
|
|||
166,
|
||||
167,
|
||||
168,
|
||||
182
|
||||
182,
|
||||
199
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -3594,7 +3645,8 @@
|
|||
168,
|
||||
176,
|
||||
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",
|
||||
"pk": 12,
|
||||
|
|
|
@ -69,7 +69,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
{% if request.user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
{% 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>
|
||||
{% endif %}
|
||||
{% if user.is_authenticated and user|is_member:"Kfet" %}
|
||||
|
|
Loading…
Reference in New Issue