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

Snippet and template tag for footer text

Scot Hacker 8 жил өмнө
parent
commit
b0db0bba66

+ 23 - 0
bakerydemo/base/migrations/0003_footertext.py

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-10 13:38
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import wagtail.wagtailcore.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0002_auto_20170210_1217'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='FooterText',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('body', wagtail.wagtailcore.fields.RichTextField()),
+            ],
+        ),
+    ]

+ 15 - 0
bakerydemo/base/models.py

@@ -55,6 +55,21 @@ class People(ClusterableModel):
         verbose_name_plural = 'People'
 
 
+@register_snippet
+class FooterText(models.Model):
+    body = RichTextField()
+
+    panels = [
+        FieldPanel('body'),
+    ]
+
+    def __str__(self):
+        return "Footer text"
+
+    class Meta:
+        verbose_name_plural = 'Footer Text'
+
+
 class AboutLocationRelationship(Orderable, models.Model):
     """
     This defines the relationship between the `LocationPage` within the `locations`

+ 11 - 2
bakerydemo/base/templatetags/navigation_tags.py

@@ -1,7 +1,7 @@
 from django import template
-from django.template import Template
-from django.utils.http import urlencode
 from wagtail.wagtailcore.models import Page
+from bakerydemo.base.models import FooterText
+
 
 register = template.Library()
 # https://docs.djangoproject.com/en/1.9/howto/custom-template-tags/
@@ -87,3 +87,12 @@ def breadcrumbs(context):
         'ancestors': ancestors,
         'request': context['request'],
     }
+
+
+@register.inclusion_tag('base/include/footer.html', takes_context=True)
+def get_footer_text(context):
+    footer_text = FooterText.objects.first().body
+
+    return {
+        'footer_text': footer_text,
+    }

+ 1 - 1
bakerydemo/templates/base.html

@@ -165,7 +165,7 @@
                             </a>
                         </li>
                     </ul>
-                    <p class="copyright text-muted">Copyright &copy; Your Website 2016</p>
+                    <p class="copyright text-muted">{% get_footer_text %}</p>
                 </div>
             </div>
         </div>

+ 4 - 0
bakerydemo/templates/base/include/footer.html

@@ -0,0 +1,4 @@
+{% load wagtailcore_tags %}
+
+
+{{ footer_text|richtext }}