2
0
Эх сурвалжийг харах

Add Generic and Site settings models. Fix #395 (#419)

Co-authored-by: Thibaud Colas <thibaudcolas@gmail.com>
Ben Morse 1 жил өмнө
parent
commit
6831b21f9c

+ 143 - 103
bakerydemo/base/fixtures/bakerydemo.json

@@ -1,92 +1,4 @@
 [
-  {
-    "model": "base.person",
-    "pk": 1,
-    "fields": {
-      "latest_revision": null,
-      "live": true,
-      "has_unpublished_changes": false,
-      "first_published_at": null,
-      "last_published_at": null,
-      "live_revision": null,
-      "go_live_at": null,
-      "expire_at": null,
-      "expired": false,
-      "locked": false,
-      "locked_at": null,
-      "locked_by": null,
-      "first_name": "Roberta",
-      "last_name": "Johnson",
-      "job_title": "Editorial Manager",
-      "image": 8
-    }
-  },
-  {
-    "model": "base.person",
-    "pk": 2,
-    "fields": {
-      "latest_revision": null,
-      "live": true,
-      "has_unpublished_changes": false,
-      "first_published_at": null,
-      "last_published_at": null,
-      "live_revision": null,
-      "go_live_at": null,
-      "expire_at": null,
-      "expired": false,
-      "locked": false,
-      "locked_at": null,
-      "locked_by": null,
-      "first_name": "Olivia",
-      "last_name": "Ava",
-      "job_title": "Director",
-      "image": 52
-    }
-  },
-  {
-    "model": "base.person",
-    "pk": 3,
-    "fields": {
-      "latest_revision": null,
-      "live": true,
-      "has_unpublished_changes": false,
-      "first_published_at": null,
-      "last_published_at": null,
-      "live_revision": null,
-      "go_live_at": null,
-      "expire_at": null,
-      "expired": false,
-      "locked": false,
-      "locked_at": null,
-      "locked_by": null,
-      "first_name": "Lightnin'",
-      "last_name": "Hopkins",
-      "job_title": "Designer",
-      "image": 53
-    }
-  },
-  {
-    "model": "base.person",
-    "pk": 4,
-    "fields": {
-      "latest_revision": null,
-      "live": true,
-      "has_unpublished_changes": false,
-      "first_published_at": null,
-      "last_published_at": null,
-      "live_revision": null,
-      "go_live_at": null,
-      "expire_at": null,
-      "expired": false,
-      "locked": false,
-      "locked_at": null,
-      "locked_by": null,
-      "first_name": "Muddy",
-      "last_name": "Waters",
-      "job_title": "Assistant Editor",
-      "image": 51
-    }
-  },
   {
     "model": "base.footertext",
     "pk": 1,
@@ -180,6 +92,15 @@
       "page": 69
     }
   },
+  {
+    "model": "base.genericsettings",
+    "pk": 1,
+    "fields": {
+      "twitter_url": "https://twitter.com/wagtailcms",
+      "github_url": "https://github.com/wagtail/wagtail",
+      "organisation_url": "https://wagtail.org/"
+    }
+  },
   {
     "model": "blog.blogpersonrelationship",
     "pk": 2,
@@ -1278,21 +1199,6 @@
       "person": 4
     }
   },
-  {
-    "model": "wagtailforms.formsubmission",
-    "pk": 1,
-    "fields": {
-      "form_data": {
-        "purpose": "Feedback",
-        "subject": "What's up?",
-        "body": "Love what you guys are doing with the site so far.",
-        "your_name": "Scot Hacker",
-        "your_email": "shacker@birdhouse.org"
-      },
-      "page": 69,
-      "submit_time": "2019-02-15T16:56:48.939Z"
-    }
-  },
   {
     "model": "wagtailembeds.embed",
     "pk": 1,
@@ -1379,6 +1285,21 @@
       "hits": 1
     }
   },
+  {
+    "model": "wagtailforms.formsubmission",
+    "pk": 1,
+    "fields": {
+      "form_data": {
+        "purpose": "Feedback",
+        "subject": "What's up?",
+        "body": "Love what you guys are doing with the site so far.",
+        "your_name": "Scot Hacker",
+        "your_email": "shacker@birdhouse.org"
+      },
+      "page": 69,
+      "submit_time": "2019-02-15T16:56:48.939Z"
+    }
+  },
   {
     "model": "wagtailcore.locale",
     "pk": 1,
@@ -1444,6 +1365,13 @@
       "workflow": 1
     }
   },
+  {
+    "model": "wagtailcore.workflowcontenttype",
+    "pk": 4,
+    "fields": {
+      "workflow": 1
+    }
+  },
   {
     "model": "wagtailcore.workflowtask",
     "pk": 1,
@@ -3587,6 +3515,22 @@
       "file_hash": ""
     }
   },
+  {
+    "model": "wagtailusers.userprofile",
+    "pk": 1,
+    "fields": {
+      "user": ["admin"],
+      "submitted_notifications": true,
+      "approved_notifications": true,
+      "rejected_notifications": true,
+      "updated_comments_notifications": true,
+      "preferred_language": "",
+      "current_time_zone": "",
+      "avatar": "",
+      "dismissibles": {},
+      "theme": "system"
+    }
+  },
   {
     "model": "recipes.recipeindexpage",
     "pk": 80,
@@ -3918,6 +3862,14 @@
       "date_published": "2019-02-24"
     }
   },
+  {
+    "model": "base.sitesettings",
+    "pk": 1,
+    "fields": {
+      "site": ["127.0.0.1", 8000],
+      "title_suffix": "The Wagtail Bakery"
+    }
+  },
   {
     "model": "base.formpage",
     "pk": 69,
@@ -3968,5 +3920,93 @@
       "image": 41,
       "body": "[{\"type\": \"paragraph_block\", \"value\": \"<h2>Welcome to the Wagtail Demo Site!</h2><p>If you've gotten this far, congratulations - you're running an instance of a killer content management system written for and on top of Django, <i>the framework for perfectionists with deadlines.</i></p><p>What does Wagtail get you that Django alone does not?\\u00a0</p><p></p><ul><li>Focus on content creators/managers, rather than developers (but developer-friendly!)</li><li>\\\"Page-centric\\\" content modeling</li><li>Beautiful, modern, intuitive user interface optimized for content people</li><li>Super-powerful hierarchical content management (\\\"content trees\\\")</li><li>User- and group-based permissions system attached to content hierarchies</li><li>Flexible image resizing with a ton of image display helpers</li><li>Innovative \\\"<a href=\\\"https://torchbox.com/blog/rich-text-fields-and-faster-horses/\\\">StreamFields</a>\\\" as an alternative to traditional \\\"anything goes\\\" rich text fields</li><li>Intuitive choosers for embedded Pages, Images, Documents and other content</li><li>Native integration with ElasticSearch to help you build powerful search features</li><li>Template tags to help create image renditions, smart links, and to navigate content trees</li></ul><p>If you're new to Wagtail, there are two primary paths to learning:</p><p></p><ul><li>The source code that powers this demo site</li><li>The official <a href=\\\"https://docs.wagtail.org/en/stable/getting_started/index.html\\\">tutorial</a></li></ul><p></p><p></p>\", \"id\": \"c6629b9b-3e70-4e30-a00c-b1ab878c8df9\"}]"
     }
+  },
+  {
+    "model": "base.person",
+    "pk": 1,
+    "fields": {
+      "latest_revision": null,
+      "live": true,
+      "has_unpublished_changes": false,
+      "first_published_at": null,
+      "last_published_at": null,
+      "live_revision": null,
+      "go_live_at": null,
+      "expire_at": null,
+      "expired": false,
+      "locked": false,
+      "locked_at": null,
+      "locked_by": null,
+      "first_name": "Roberta",
+      "last_name": "Johnson",
+      "job_title": "Editorial Manager",
+      "image": 8
+    }
+  },
+  {
+    "model": "base.person",
+    "pk": 2,
+    "fields": {
+      "latest_revision": null,
+      "live": true,
+      "has_unpublished_changes": false,
+      "first_published_at": null,
+      "last_published_at": null,
+      "live_revision": null,
+      "go_live_at": null,
+      "expire_at": null,
+      "expired": false,
+      "locked": false,
+      "locked_at": null,
+      "locked_by": null,
+      "first_name": "Olivia",
+      "last_name": "Ava",
+      "job_title": "Director",
+      "image": 52
+    }
+  },
+  {
+    "model": "base.person",
+    "pk": 3,
+    "fields": {
+      "latest_revision": null,
+      "live": true,
+      "has_unpublished_changes": false,
+      "first_published_at": null,
+      "last_published_at": null,
+      "live_revision": null,
+      "go_live_at": null,
+      "expire_at": null,
+      "expired": false,
+      "locked": false,
+      "locked_at": null,
+      "locked_by": null,
+      "first_name": "Lightnin'",
+      "last_name": "Hopkins",
+      "job_title": "Designer",
+      "image": 53
+    }
+  },
+  {
+    "model": "base.person",
+    "pk": 4,
+    "fields": {
+      "latest_revision": null,
+      "live": true,
+      "has_unpublished_changes": false,
+      "first_published_at": null,
+      "last_published_at": null,
+      "live_revision": null,
+      "go_live_at": null,
+      "expire_at": null,
+      "expired": false,
+      "locked": false,
+      "locked_at": null,
+      "locked_by": null,
+      "first_name": "Muddy",
+      "last_name": "Waters",
+      "job_title": "Assistant Editor",
+      "image": 51
+    }
   }
 ]

+ 75 - 0
bakerydemo/base/migrations/0018_add_genericsettings_and_sitesettings.py

@@ -0,0 +1,75 @@
+# Generated by Django 4.2.2 on 2023-06-21 15:31
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("wagtailcore", "0083_workflowcontenttype"),
+        ("base", "0017_footertext_enforce_not_null"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="GenericSettings",
+            fields=[
+                (
+                    "id",
+                    models.AutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                (
+                    "twitter_url",
+                    models.URLField(blank=True, verbose_name="Twitter URL"),
+                ),
+                ("github_url", models.URLField(blank=True, verbose_name="GitHub URL")),
+                (
+                    "organisation_url",
+                    models.URLField(blank=True, verbose_name="Organisation URL"),
+                ),
+            ],
+            options={
+                "abstract": False,
+            },
+        ),
+        migrations.CreateModel(
+            name="SiteSettings",
+            fields=[
+                (
+                    "id",
+                    models.AutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                (
+                    "title_suffix",
+                    models.CharField(
+                        default="The Wagtail Bakery",
+                        help_text="The suffix for the title meta tag e.g. ' | The Wagtail Bakery'",
+                        max_length=255,
+                        verbose_name="Title suffix",
+                    ),
+                ),
+                (
+                    "site",
+                    models.OneToOneField(
+                        editable=False,
+                        on_delete=django.db.models.deletion.CASCADE,
+                        to="wagtailcore.site",
+                    ),
+                ),
+            ],
+            options={
+                "abstract": False,
+            },
+        ),
+    ]

+ 37 - 0
bakerydemo/base/models.py

@@ -12,6 +12,11 @@ from wagtail.admin.panels import (
     PublishingPanel,
 )
 from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
+from wagtail.contrib.settings.models import (
+    BaseGenericSetting,
+    BaseSiteSetting,
+    register_setting,
+)
 from wagtail.fields import RichTextField, StreamField
 from wagtail.models import (
     Collection,
@@ -448,3 +453,35 @@ class FormPage(AbstractEmailForm):
             "Email",
         ),
     ]
+
+
+@register_setting
+class GenericSettings(ClusterableModel, BaseGenericSetting):
+    twitter_url = models.URLField(verbose_name="Twitter URL", blank=True)
+    github_url = models.URLField(verbose_name="GitHub URL", blank=True)
+    organisation_url = models.URLField(verbose_name="Organisation URL", blank=True)
+
+    panels = [
+        MultiFieldPanel(
+            [
+                FieldPanel("github_url"),
+                FieldPanel("twitter_url"),
+                FieldPanel("organisation_url"),
+            ],
+            "Social settings",
+        )
+    ]
+
+
+@register_setting
+class SiteSettings(BaseSiteSetting):
+    title_suffix = models.CharField(
+        verbose_name="Title suffix",
+        max_length=255,
+        help_text="The suffix for the title meta tag e.g. ' | The Wagtail Bakery'",
+        default="The Wagtail Bakery",
+    )
+
+    panels = [
+        FieldPanel("title_suffix"),
+    ]

+ 6 - 4
bakerydemo/settings/base.py

@@ -43,9 +43,6 @@ INSTALLED_APPS = [
     "bakerydemo.locations",
     "bakerydemo.recipes",
     "bakerydemo.search",
-    "wagtail.contrib.search_promotions",
-    "wagtail.contrib.forms",
-    "wagtail.contrib.redirects",
     "wagtail.embeds",
     "wagtail.sites",
     "wagtail.users",
@@ -56,10 +53,14 @@ INSTALLED_APPS = [
     "wagtail.admin",
     "wagtail.api.v2",
     "wagtail.locales",
+    "wagtail.contrib.forms",
+    "wagtail.contrib.redirects",
+    "wagtail.contrib.routable_page",
     "wagtail.contrib.table_block",
     "wagtail.contrib.typed_table_block",
     "wagtail.contrib.modeladmin",
-    "wagtail.contrib.routable_page",
+    "wagtail.contrib.search_promotions",
+    "wagtail.contrib.settings",
     "wagtail.contrib.simple_translation",
     "wagtail.contrib.styleguide",
     "wagtail",
@@ -106,6 +107,7 @@ TEMPLATES = [
                 "django.template.context_processors.request",
                 "django.contrib.auth.context_processors.auth",
                 "django.contrib.messages.context_processors.messages",
+                "wagtail.contrib.settings.context_processors.settings",
             ],
         },
     },

+ 1 - 1
bakerydemo/templates/base.html

@@ -12,7 +12,7 @@
                 {% endif %}
             {% endblock %}
             {% block title_suffix %}
-                | The Wagtail Bakery
+                | {{ settings.base.SiteSettings.title_suffix }}
             {% endblock %}
         </title>
         <meta name="description" content="{% if page.search_description %}{{ page.search_description }}{% endif %}">

+ 36 - 26
bakerydemo/templates/includes/footer.html

@@ -3,32 +3,42 @@
 <footer class="container">
     <div class="row">
         <div class="col-sm-12">
-            <ul class="list-inline">
-                <li class="footer__icon">
-                    <a href="https://github.com/wagtail/wagtail" target="_blank" rel="noreferrer" aria-label="View Wagtail's source code on GitHub">
-                        <span class="fa-stack fa-lg">
-                            <i class="fa fa-circle fa-stack-2x"></i>
-                            <i class="fa fa-github fa-stack-1x fa-inverse"></i>
-                        </span>
-                    </a>
-                </li>
-                <li class="footer__icon">
-                    <a href="https://twitter.com/wagtailcms" target="_blank" rel="noreferrer" aria-label="Wagtail's official Twitter account">
-                        <span class="fa-stack fa-lg">
-                            <i class="fa fa-circle fa-stack-2x"></i>
-                            <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
-                        </span>
-                    </a>
-                </li>
-                <li class="footer__icon">
-                    <a href="https://wagtail.org/" target="_blank" rel="noreferrer" aria-label="Wagtail's official website">
-                        <span class="fa-stack fa-lg">
-                            <i class="fa fa-circle fa-stack-2x"></i>
-                            <i class="fa fa-link fa-stack-1x fa-inverse"></i>
-                        </span>
-                    </a>
-                </li>
-            </ul>
+            {% with twitter_url=settings.base.GenericSettings.twitter_url github_url=settings.base.GenericSettings.github_url organisation_url=settings.base.GenericSettings.organisation_url %}
+                {% if twitter_url or github_url or organisation_url %}
+                    <ul class="list-inline">
+                        {% if github_url %}
+                            <li class="footer__icon">
+                                <a href="{{ github_url }}" target="_blank" rel="noreferrer" aria-label="View Wagtail's source code on GitHub">
+                                    <span class="fa-stack fa-lg">
+                                        <i class="fa fa-circle fa-stack-2x"></i>
+                                        <i class="fa fa-github fa-stack-1x fa-inverse"></i>
+                                    </span>
+                                </a>
+                            </li>
+                        {% endif %}
+                        {% if twitter_url %}
+                            <li class="footer__icon">
+                                <a href="{{ twitter_url }}" target="_blank" rel="noreferrer" aria-label="Wagtail's official Twitter account">
+                                    <span class="fa-stack fa-lg">
+                                        <i class="fa fa-circle fa-stack-2x"></i>
+                                        <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
+                                    </span>
+                                </a>
+                            </li>
+                        {% endif %}
+                        {% if organisation_url %}
+                            <li class="footer__icon">
+                                <a href="{{ organisation_url }}" target="_blank" rel="noreferrer" aria-label="Wagtail's official website">
+                                    <span class="fa-stack fa-lg">
+                                        <i class="fa fa-circle fa-stack-2x"></i>
+                                        <i class="fa fa-link fa-stack-1x fa-inverse"></i>
+                                    </span>
+                                </a>
+                            </li>
+                        {% endif %}
+                    </ul>
+                {% endif %}
+            {% endwith %}
             {% get_footer_text %}
         </div>
     </div>