mirror of https://gitlab.crans.org/bde/nk20
Un peu de nettoyage, rajout de commentaires
This commit is contained in:
parent
3f997f94fa
commit
896095a44c
|
@ -1,3 +1,6 @@
|
|||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.contrib import admin
|
||||
from note_kfet.admin import admin_site
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.2.28 on 2024-05-21 12:05
|
||||
# Generated by Django 2.2.28 on 2024-05-25 20:32
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -15,14 +15,15 @@ class Migration(migrations.Migration):
|
|||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Basic_food',
|
||||
name='BasicFood',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||
('is_DLC', models.BooleanField(default=False, verbose_name='is DLC')),
|
||||
('is_DDM', models.BooleanField(default=False, verbose_name='is DDM')),
|
||||
('expiry_date', models.DateTimeField(blank=True, default=django.utils.timezone.now, verbose_name='expiry date')),
|
||||
('label', models.ImageField(default='pic/default.png', max_length=255, upload_to='label/', verbose_name='food label')),
|
||||
('arrival_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='arrival date')),
|
||||
('expiry_date', models.DateTimeField(blank=True, null=True, verbose_name='expiry date')),
|
||||
('label', models.ImageField(max_length=255, upload_to='label/', verbose_name='food label')),
|
||||
('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')),
|
||||
],
|
||||
|
@ -32,7 +33,7 @@ class Migration(migrations.Migration):
|
|||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Transformed_food',
|
||||
name='TransformedFood',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||
|
@ -41,7 +42,7 @@ class Migration(migrations.Migration):
|
|||
('is_active', models.BooleanField(default=True, verbose_name='is active')),
|
||||
('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')),
|
||||
('transformed_ingredient', models.ManyToManyField(blank=True, related_name='transformed_ingredient_inv', to='food.Transformed_food', verbose_name='transformed ingredient')),
|
||||
('transformed_ingredient', models.ManyToManyField(blank=True, related_name='transformed_ingredient_inv', to='food.TransformedFood', verbose_name='transformed ingredient')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Transformed food',
|
||||
|
@ -53,8 +54,8 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('qr_code_number', models.PositiveIntegerField(verbose_name='QR-code number')),
|
||||
('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.Basic_food', verbose_name='basic food')),
|
||||
('transformed_food_container', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.Transformed_food', verbose_name='transformed food container')),
|
||||
('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.BasicFood', verbose_name='basic food')),
|
||||
('transformed_food_container', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.TransformedFood', verbose_name='transformed food container')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'QR-code',
|
||||
|
@ -62,9 +63,9 @@ class Migration(migrations.Migration):
|
|||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='basic_food',
|
||||
model_name='basicfood',
|
||||
name='transformed_food',
|
||||
field=models.ManyToManyField(blank=True, related_name='Basic_food', to='food.Transformed_food', verbose_name='transformed food'),
|
||||
field=models.ManyToManyField(blank=True, related_name='BasicFood', to='food.TransformedFood', verbose_name='transformed food'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Allergen',
|
||||
|
@ -85,8 +86,8 @@ class Migration(migrations.Migration):
|
|||
('groundnut', models.BooleanField(default=False, verbose_name='groundnut')),
|
||||
('sesame', models.BooleanField(default=False, verbose_name='sesame')),
|
||||
('alcohol', models.BooleanField(default=False, verbose_name='alcohol')),
|
||||
('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.Basic_food', verbose_name='basic food')),
|
||||
('transformed_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.Transformed_food', verbose_name='transformed food')),
|
||||
('basic_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.BasicFood', verbose_name='basic food')),
|
||||
('transformed_food', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.TransformedFood', verbose_name='transformed food')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Allergen',
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 2.2.28 on 2024-05-24 19:39
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='basic_food',
|
||||
name='expiry_date',
|
||||
field=models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True, verbose_name='expiry date'),
|
||||
),
|
||||
]
|
|
@ -1,55 +0,0 @@
|
|||
# Generated by Django 2.2.28 on 2024-05-25 11:50
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('member', '0011_profile_vss_charter_read'),
|
||||
('food', '0002_auto_20240524_2139'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='BasicFood',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||
('is_DLC', models.BooleanField(default=False, verbose_name='is DLC')),
|
||||
('is_DDM', models.BooleanField(default=False, verbose_name='is DDM')),
|
||||
('expiry_date', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True, verbose_name='expiry date')),
|
||||
('label', models.ImageField(default='pic/default.png', max_length=255, upload_to='label/', verbose_name='food label')),
|
||||
('was_eaten', models.BooleanField(default=False, verbose_name='was eaten')),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='member.Club', verbose_name='owner')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Basic food',
|
||||
'verbose_name_plural': 'Basic foods',
|
||||
},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='allergen',
|
||||
name='basic_food',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='Allergen', to='food.BasicFood', verbose_name='basic food'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='qr_code',
|
||||
name='basic_food',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='QR_code', to='food.BasicFood', verbose_name='basic food'),
|
||||
),
|
||||
migrations.RenameModel(
|
||||
old_name='Transformed_food',
|
||||
new_name='TransformedFood',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Basic_food',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='basicfood',
|
||||
name='transformed_food',
|
||||
field=models.ManyToManyField(blank=True, null=True, related_name='BasicFood', to='food.TransformedFood', verbose_name='transformed food'),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 2.2.28 on 2024-05-25 11:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0003_auto_20240525_1350'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='basicfood',
|
||||
name='transformed_food',
|
||||
field=models.ManyToManyField(blank=True, related_name='BasicFood', to='food.TransformedFood', verbose_name='transformed food'),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 2.2.28 on 2024-05-25 13:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0004_auto_20240525_1352'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='basicfood',
|
||||
name='label',
|
||||
field=models.ImageField(max_length=255, upload_to='label/', verbose_name='food label'),
|
||||
),
|
||||
]
|
|
@ -13,6 +13,12 @@ from django.utils import timezone
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from member.models import Club
|
||||
|
||||
#################################################################
|
||||
# TO DO
|
||||
# - link allergen with one food (basic or transformed) with check
|
||||
# - check on basic food
|
||||
# - check on transformed food
|
||||
#################################################################
|
||||
|
||||
class QR_code(models.Model):
|
||||
"""
|
||||
|
@ -173,10 +179,14 @@ class BasicFood(models.Model):
|
|||
verbose_name=_("is DDM"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
arrival_date = models.DateTimeField(
|
||||
verbose_name=_('arrival date'),
|
||||
default=timezone.now,
|
||||
)
|
||||
|
||||
expiry_date = models.DateTimeField(
|
||||
verbose_name=_('expiry date'),
|
||||
default=timezone.now,
|
||||
blank=True,
|
||||
null = True,
|
||||
)
|
||||
|
|
|
@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
{% block content %}
|
||||
<div class="card bg-white mb-3">
|
||||
<h3 class="card-header text-center">
|
||||
HTML not finished <br>
|
||||
{{ title }}
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
|
|
|
@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
{% block content %}
|
||||
<div class="card bg-white mb-3">
|
||||
<h3 class="card-header text-center">
|
||||
HTML not finished <br>
|
||||
{{ title }}
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
|
|
|
@ -5,12 +5,14 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
###############################
|
||||
# TO DO
|
||||
# - name url correctly, thinking about the scheme of the app
|
||||
###############################
|
||||
|
||||
app_name = 'food'
|
||||
|
||||
urlpatterns = [
|
||||
path('test_basic_food_form',views.test_basic_foodform),
|
||||
path('test_transformed_food_form', views.test_transformed_foodform),
|
||||
path('test_allergen_form', views.test_allergenform),
|
||||
path('0', views.BasicFoodCreateView.as_view(), name = 'basic_food'),
|
||||
path('1', views.TransformedFoodCreateView.as_view(), name = 'transformed_food'),
|
||||
]
|
||||
|
|
|
@ -1,57 +1,35 @@
|
|||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
'''
|
||||
from crispy_forms.helper import FormHelper
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import ValidationError, PermissionDenied
|
||||
from django.db.models import Q
|
||||
from django.forms import Form
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
'''
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.db import transaction
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
'''
|
||||
from django.views.generic import UpdateView, DetailView
|
||||
from django.views.generic.base import View, TemplateView
|
||||
from django.views.generic.edit import BaseFormView, DeleteView
|
||||
from django_tables2 import SingleTableView
|
||||
'''
|
||||
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
from .forms import BasicFoodForms, TransformedFoodForms, AllergenForms
|
||||
from .models import BasicFood, TransformedFood, Allergen
|
||||
|
||||
def test_basic_foodform(request):
|
||||
return render(request,'food/test.html', {"form": BasicFoodForms()})
|
||||
|
||||
def test_transformed_foodform(request):
|
||||
return render(request,'food/transformed_food_form.html', {"form": TransformedFoodForms()})
|
||||
|
||||
def test_allergenform(request):
|
||||
return render(request,'food/test.html', {"form": AllergenForms()})
|
||||
|
||||
|
||||
class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
#####################################################################
|
||||
# TO DO
|
||||
# - fix picture save
|
||||
# - implement solution crop and convert image (reuse or recode ImageForm from members apps
|
||||
# - implement AllergenForms
|
||||
# - redirect to another view after the poll is submitted
|
||||
#####################################################################
|
||||
"""
|
||||
A view to add a basic food
|
||||
"""
|
||||
model = BasicFood
|
||||
form_class = BasicFoodForms
|
||||
template_name = 'food/basic_food_form.html'
|
||||
second_form = AllergenForms
|
||||
extra_context = {"title": _("Add a new aliment")}
|
||||
|
||||
def get_sample_object(self):
|
||||
return Allergen(
|
||||
groundnut = "False",
|
||||
)
|
||||
'''
|
||||
return BasicFood(
|
||||
name="",
|
||||
is_DLC=False,
|
||||
|
@ -59,7 +37,6 @@ class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||
expiry_date=timezone.now(),
|
||||
label='pic/default.png',
|
||||
)
|
||||
'''
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
|
@ -71,6 +48,8 @@ class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||
|
||||
# Save the aliment and the allergens associed
|
||||
basic_food = form.save(commit=False)
|
||||
# We assume the date of labeling and the same as the date of arrival
|
||||
basic_food.arrival_date = timezone.now
|
||||
basic_food._force_save = True
|
||||
basic_food.save()
|
||||
basic_food.refresh_from_db()
|
||||
|
@ -78,10 +57,15 @@ class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||
|
||||
def get_success_url(self, **kwargs):
|
||||
self.object.refresh_from_db()
|
||||
# TEMPORARY, I create a fonctionnal view before
|
||||
# return reverse_lazy('food:basicfood', kwargs={"pk": self.object.pk})
|
||||
return '0'
|
||||
|
||||
class TransformedFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
###############################################
|
||||
# TO DO
|
||||
# -redirect to another view after submit
|
||||
###############################################
|
||||
"""
|
||||
A view to add a tranformed food
|
||||
"""
|
||||
|
@ -105,7 +89,7 @@ class TransformedFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||
|
||||
# Save the aliment and allergens associated
|
||||
transformed_food = form.save(commit=False)
|
||||
# Without microbiologic analysis, the time of conservation is 3 days
|
||||
# Without microbiological analyzes, the storage time is 3 days
|
||||
transformed_food.expiry_date = transformed_food.creation_date + timedelta(days = 3)
|
||||
transformed_food._force_save = True
|
||||
transformed_food.save()
|
||||
|
@ -115,5 +99,6 @@ class TransformedFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||
|
||||
def get_success_url(self, **kwargs):
|
||||
self.object.refresh_from_db()
|
||||
# TEMPORARY, I create a fonctionnal view before
|
||||
# return reverse_lazy('food:tranformed_food', kwargs={"pk": self.object.pk})
|
||||
return '1'
|
||||
|
|
Loading…
Reference in New Issue