WIP: modified form models idea

pull/18/head
mtyton 2023-10-10 22:28:02 +02:00
rodzic f509df6a9d
commit dc25fa01a7
3 zmienionych plików z 32 dodań i 24 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
# Generated by Django 4.1.11 on 2023-10-09 19:30
# Generated by Django 4.1.11 on 2023-10-10 20:22
import django.core.serializers.json
from django.db import migrations, models
@ -19,19 +19,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name="CustomEmailForm",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("intro", wagtail.fields.RichTextField(blank=True)),
("thank_you_text", wagtail.fields.RichTextField(blank=True)),
("allow_attachments", models.BooleanField(default=False)),
("from_address", models.EmailField(blank=True, help_text="Sender email address", max_length=254)),
("to_address", models.CharField(help_text="Comma separated list of recipients", max_length=255)),
("subject", models.CharField(help_text="Subject of the email with data", max_length=255)),
@ -39,7 +30,7 @@ class Migration(migrations.Migration):
options={
"abstract": False,
},
bases=(wagtail.contrib.forms.models.FormMixin, "wagtailcore.page"),
bases=(wagtail.contrib.forms.models.FormMixin, models.Model),
),
migrations.CreateModel(
name="EmailFormSubmission",
@ -115,7 +106,7 @@ class Migration(migrations.Migration):
),
("help_text", models.CharField(blank=True, max_length=255, verbose_name="help text")),
(
"page",
"form",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="form_fields",

Wyświetl plik

@ -5,6 +5,7 @@ from django.conf import settings
from django.utils.formats import date_format
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.panels import (
FieldPanel, FieldRowPanel,
InlinePanel, MultiFieldPanel
@ -12,7 +13,7 @@ from wagtail.admin.panels import (
from wagtail.fields import RichTextField
from wagtail.contrib.forms.models import (
AbstractFormField,
AbstractForm,
FormMixin,
Page,
AbstractFormSubmission
)
@ -20,13 +21,11 @@ from wagtail.contrib.forms.models import (
from mailings.models import send_mail
class FormPage(AbstractForm):
adapter = None
class Form(FormMixin, ClusterableModel):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
allow_attachments = models.BooleanField(default=False)
content_panels = Page.content_panels + [
FieldPanel('intro'),
InlinePanel('form_fields', label="Form fields"),
@ -72,7 +71,7 @@ class EmailFormSubmission(AbstractFormSubmission):
)
class CustomEmailForm(FormPage):
class CustomEmailForm(Form):
from_address = models.EmailField(
blank=True,
help_text="Sender email address"
@ -86,10 +85,10 @@ class CustomEmailForm(FormPage):
help_text="Subject of the email with data"
)
template = "forms/form_page.html"
template = "forms/email_form_page.html"
class EmailFormField(AbstractFormField):
page = ParentalKey(
CustomEmailForm, related_name="form_fields", on_delete=models.CASCADE
form = ParentalKey(
"CustomEmailForm", related_name="form_fields", on_delete=models.CASCADE
)

Wyświetl plik

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block content %}
<h1>{{ page.title }}</h1>
<p class="meta">{{ page.date }}</p>
<div class="body">{{ page.body|richtext }}</div>
{% for item in page.gallery_images.all %}
<div style="float: left; margin: 10px">
{% image item.image fill-320x240 %}
<p>{{ item.caption }}</p>
</div>
{% endfor %}
{% endblock %}