-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4158 from betagouv/4127-création-modèle-fiche-act…
…ion-1 Création modèle fiche action
- Loading branch information
Showing
8 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .wasteaction import WasteAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .wasteaction import WasteActionViewSet # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters