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 .actionsheet import ActionSheet
38 changes: 38 additions & 0 deletions cms/models/actionsheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.db import models
from data.fields import ChoiceArrayField
from wagtail.fields import RichTextField

class ActionSheet(models.Model):
valleepa marked this conversation as resolved.
Show resolved Hide resolved
class Meta:
verbose_name = "Fiche action"
verbose_name_plural = "Fiche actions"
valleepa marked this conversation as resolved.
Show resolved Hide resolved
ordering = ["-modification_date"]
class Effort(models.TextChoices):
SMALL = "SMALL", "Petit pas"
LARGE = "LARGE", "Grand projet"
valleepa marked this conversation as resolved.
Show resolved Hide resolved
class WasteOrigin(models.TextChoices):
PREP = "PREP", "Préparation"
UNSERVED = "UNSERVED", "Non servi"
PLATE = "PLATE", "Retour assiette"
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"
hfroot marked this conversation as resolved.
Show resolved Hide resolved
)
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")
valleepa marked this conversation as resolved.
Show resolved Hide resolved
description = RichTextField(verbose_name="Description", null=True, blank=True, default="<h2>Description</h2><h2>Conseils pratiques</h2><ul><li></li></ul>")
valleepa marked this conversation as resolved.
Show resolved Hide resolved
savings_estimation = models.IntegerField(verbose_name="Estimation d'économies (€)")
valleepa marked this conversation as resolved.
Show resolved Hide resolved
coefficient = models.IntegerField(verbose_name="Coefficient d'évolution")
valleepa marked this conversation as resolved.
Show resolved Hide resolved
image = models.ForeignKey(
valleepa marked this conversation as resolved.
Show resolved Hide resolved
'wagtailimages.Image', on_delete=models.SET_NULL, related_name='+', null=True, blank=True
)
def __str__(self):
return f'Fiche action "{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 .actionsheet import ActionSheetViewSet # noqa: F401
22 changes: 22 additions & 0 deletions cms/viewsets/actionsheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.admin.panels import TabbedInterface, ObjectList, FieldPanel, MultipleChooserPanel
from cms.models.actionsheet import ActionSheet
from django import forms


class ActionSheetViewSet(SnippetViewSet):
"""
This viewset allows using actionsheets on wagtail admin.
"""
model = ActionSheet
icon = "doc-full"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca aurait été bien, mais c'est déja l'icône de Workflow . P-e le mieux serait d'ajouter une icône, car la plupart de celles proposées par wagtail sont déja utilisées quelque part
image

menu_label = "Fiches action"
menu_name = "actionsheets"
menu_order = 000
valleepa marked this conversation as resolved.
Show resolved Hide resolved
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")], heading="Caractéristiques"),
ObjectList([FieldPanel("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 ActionSheetViewSet

register_snippet(ActionSheetViewSet)
Loading