Skip to content

Commit

Permalink
WIP save
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Feb 7, 2024
1 parent 81c31f4 commit 16b8b65
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
22 changes: 17 additions & 5 deletions content_manager/management/commands/create_sample_pages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from django.urls import reverse
from wagtail.models import Page, Site
Expand Down Expand Up @@ -28,7 +29,8 @@ def handle(self, *args, **kwargs):
self.create_homepage()
elif slug == "mentions-legales":
title = "Mentions légales"
body = [("title", {"title": title, "large": True})]
body = []
body.append(("title", {"title": title, "large": True}))

alert_block = {
"title": title,
Expand All @@ -55,7 +57,8 @@ def handle(self, *args, **kwargs):
self.create_page(slug=slug, title=title, body=body)
elif slug == "accessibilite":
title = "Déclaration d’accessibilité"
body = [("title", {"title": title, "large": True})]
body = []
body.append(("title", {"title": title, "large": True}))

alert_block = {
"title": title,
Expand All @@ -80,7 +83,8 @@ def create_homepage(self) -> None:
raise ValueError(f"The home page seem to already exist with id {already_exists.id}")

# Create the page
body = [("title", {"title": "Votre nouveau site avec le CMS Beta", "large": True})]
body = []
body.append(("title", {"title": "Votre nouveau site avec le CMS Beta", "large": True}))

image = import_image(
full_path="staticfiles/dsfr/dist/artwork/pictograms/digital/coding.svg",
Expand Down Expand Up @@ -119,13 +123,21 @@ def create_homepage(self) -> None:

# Define it as default for the default site
site = Site.objects.filter(is_default_site=True).first()
if not site:
site = Site.objects.create(
root_page_id=1,
is_default_site=True,
hostname=settings.ALLOWED_HOSTS[0],
site_name=settings.ALLOWED_HOSTS[0],
)

site.root_page_id = home_page.id
site.save()

# Delete the original default page and get its slug
original_home = Page.objects.get(slug="home")
original_home.delete()
original_home = Page.objects.filter(slug="home").first()
if original_home:
original_home.delete()

home_page.slug = "home"
home_page.save()
Expand Down
19 changes: 19 additions & 0 deletions content_manager/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.forms import widgets
from django.template.response import TemplateResponse
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
Expand Down Expand Up @@ -189,6 +190,21 @@ class Meta:


class FormField(AbstractFormField):
FORM_FIELD_CHOICES = (
("singleline", _("Single line text")),
("multiline", _("Multi-line text")),
("email", _("Email")),
("number", _("Number")),
("url", _("URL")),
("checkbox", _("Checkbox")),
("cmsfr_checkboxes", _("Checkboxes")),
("dropdown", _("Drop down")),
("cmsfr_radio", _("Radio buttons")),
("cmsfr_date", _("Date")),
("cmsfr_datetime", _("Date/time")),
("hidden", _("Hidden field")),
)

page = ParentalKey("FormPage", on_delete=models.CASCADE, related_name="form_fields")


Expand Down Expand Up @@ -252,6 +268,9 @@ def serve(self, request, *args, **kwargs):
]:
visible.field.widget.attrs["class"] = "fr-select"
visible.field.widget.group_class = "fr-select-group"
elif isinstance(visible.field.widget, widgets.DateInput):
visible.field.widget.attrs["class"] = "fr-input"
visible.field.widget.attrs["type"] = "date"
elif isinstance(visible.field.widget, widgets.RadioSelect):
visible.field.widget.attrs["dsfr"] = "dsfr"
visible.field.widget.group_class = "fr-radio-group"
Expand Down
6 changes: 6 additions & 0 deletions content_manager/templates/content_manager/form_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ <h1>{{ page.title }}</h1>
{% dsfr_form %}

<input class="fr-btn" type="submit">

<ul>
{% for field in form %}
<li>{{ field.label }}, {{ field.type }}, {{ field.field.widget.attrs }} {{ field.field.widget }}</li>
{% endfor %}
</ul>
</form>
</div>
</div>
Expand Down

0 comments on commit 16b8b65

Please sign in to comment.