Skip to content

Commit

Permalink
Merge pull request #4158 from betagouv/4127-création-modèle-fiche-act…
Browse files Browse the repository at this point in the history
…ion-1

Création modèle fiche action
  • Loading branch information
valleepa authored Jul 22, 2024
2 parents 9dcca6f + b946a03 commit e1c3cfe
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 4 deletions.
96 changes: 96 additions & 0 deletions cms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Generated by Django 5.0.7 on 2024-07-22 09:07

import data.fields
import django.db.models.deletion
import wagtail.fields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
("wagtailimages", "0026_delete_uploadedimage"),
]

operations = [
migrations.CreateModel(
name="WasteAction",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"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(
choices=[
("SMALL", "Petit pas"),
("MEDIUM", "Moyen"),
("LARGE", "Grand projet"),
],
max_length=255,
verbose_name="Niveau d'effort",
),
),
(
"waste_origin",
data.fields.ChoiceArrayField(
base_field=models.CharField(
choices=[
("PREP", "Préparation"),
("UNSERVED", "Non servi"),
("PLATE", "Retour assiette"),
],
max_length=255,
),
size=None,
verbose_name="Origines du gaspillage",
),
),
(
"description",
wagtail.fields.RichTextField(
default="<h2>Description</h2><h2>Conseils pratiques</h2><ul><li></li></ul>",
verbose_name="Description",
),
),
(
"lead_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.image",
verbose_name="Image",
),
),
],
options={
"verbose_name": "Action anti-gaspi",
"verbose_name_plural": "Actions anti-gaspi",
"ordering": ["-modification_date"],
},
),
]
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
42 changes: 42 additions & 0 deletions cms/models/wasteaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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>",
)
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
32 changes: 32 additions & 0 deletions cms/viewsets/wasteaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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"),
],
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

0 comments on commit e1c3cfe

Please sign in to comment.