Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Création modèle fiche action #4158

Merged
merged 10 commits into from
Jul 22, 2024
1 change: 1 addition & 0 deletions cms/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .wasteaction import WasteAction
44 changes: 44 additions & 0 deletions cms/models/wasteaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.db import models
from data.fields import ChoiceArrayField
from wagtail.fields import RichTextField


class WasteAction(models.Model):
class Meta:
verbose_name = "Action anti-gaspi"
verbose_name_plural = "Actions anti-gaspi"
ordering = ["-modification_date"]

class Effort(models.TextChoices):
SMALL = "SMALL", "Petit pas"
MEDIUM = "MEDIUM", "Moyen"
LARGE = "LARGE", "Grand projet"

class WasteOrigin(models.TextChoices):
PREP = "PREP", "Préparation"
UNSERVED = "UNSERVED", "Non servi"
PLATE = "PLATE", "Retour assiette"

creation_date = models.DateTimeField(auto_now_add=True, verbose_name="Date de création")
modification_date = models.DateTimeField(auto_now=True, verbose_name="Date de dernière modification")

title = models.TextField(verbose_name="Titre")
subtitle = models.TextField(verbose_name="Sous-titre")
effort = models.CharField(max_length=255, choices=Effort.choices, verbose_name="Niveau d'effort")
waste_origin = ChoiceArrayField(
base_field=models.CharField(max_length=255, choices=WasteOrigin.choices),
size=None,
verbose_name="Origines du gaspillage",
)
description = RichTextField(
verbose_name="Description",
default="<h2>Description</h2><h2>Conseils pratiques</h2><ul><li></li></ul>",
)
# savings_estimation = models.IntegerField(verbose_name="Estimation d'économies (€)")
# coefficient = models.IntegerField(verbose_name="Coefficient d'évolution")
valleepa marked this conversation as resolved.
Show resolved Hide resolved
lead_image = models.ForeignKey(
"wagtailimages.Image", on_delete=models.SET_NULL, related_name="+", null=True, blank=True, verbose_name="Image"
)

def __str__(self):
return f'Action anti-gaspi "{self.title}"'
1 change: 1 addition & 0 deletions cms/viewsets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .wasteaction import WasteActionViewSet # noqa: F401
34 changes: 34 additions & 0 deletions cms/viewsets/wasteaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.admin.panels import TabbedInterface, ObjectList, FieldPanel
from cms.models.wasteaction import WasteAction


class WasteActionViewSet(SnippetViewSet):
"""
This viewset allows using wasteactions on wagtail admin.
"""

model = WasteAction
icon = "doc-full"
menu_label = "Actions anti-gaspi"
menu_name = "wasteactions"
menu_order = 90
add_to_admin_menu = True
edit_handler = TabbedInterface(
[
ObjectList(
[FieldPanel("title"), FieldPanel("subtitle"), FieldPanel("description")], heading="Description"
),
ObjectList(
[
FieldPanel("effort"),
FieldPanel("waste_origin"),
# FieldPanel("savings_estimation"),
# FieldPanel("coefficient"),
valleepa marked this conversation as resolved.
Show resolved Hide resolved
],
heading="Caractéristiques",
),
ObjectList([FieldPanel("lead_image")], heading="Illustration"),
]
)
list_display = ["title", "modification_date"]
4 changes: 4 additions & 0 deletions cms/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from wagtail.snippets.models import register_snippet
from cms.viewsets import WasteActionViewSet

register_snippet(WasteActionViewSet)
2 changes: 1 addition & 1 deletion macantine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,4 @@
# Wagtail CMS
WAGTAIL_SITE_NAME = "ma-cantine"
# WAGTAILADMIN_BASE_URL # Declare if null URL in notification emails
WAGTAILDOCS_EXTENSIONS = ['csv', 'docx', 'key', 'odt', 'pdf', 'pptx', 'rtf', 'txt', 'xlsx', 'zip']
WAGTAILDOCS_EXTENSIONS = ["csv", "docx", "key", "odt", "pdf", "pptx", "rtf", "txt", "xlsx", "zip"]
6 changes: 3 additions & 3 deletions macantine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
path("admin/", admin.site.urls), # if the path of 'admin/' changes, update historical_record_add_auth_method
path("ckeditor/", include("ckeditor_uploader.urls")),
path("o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
path('cms/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),
path('pages/', include(wagtail_urls)),
path("cms/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path("pages/", include(wagtail_urls)),
]
urlpatterns.append(re_path(r"", include("web.urls")))
urlpatterns.append(re_path(r"^api/v1/", include("api.urls")))
Expand Down
Loading