feat: add footer, header and improve layout
This commit is contained in:
parent
72bf6bffb8
commit
6fd74833a3
17 changed files with 305 additions and 30 deletions
0
base/__init__.py
Normal file
0
base/__init__.py
Normal file
3
base/admin.py
Normal file
3
base/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
base/apps.py
Normal file
6
base/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BaseConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'base'
|
26
base/migrations/0001_initial.py
Normal file
26
base/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 5.0.2 on 2024-02-29 20:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='NavigationSettings',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('linkedin_url', models.URLField(blank=True, verbose_name='LinkedIn URL')),
|
||||
('github_url', models.URLField(blank=True, verbose_name='GitHub URL')),
|
||||
('mastodon_url', models.URLField(blank=True, verbose_name='Mastodon URL')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
42
base/migrations/0002_footertext.py
Normal file
42
base/migrations/0002_footertext.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Generated by Django 5.0.2 on 2024-02-29 21:00
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
import wagtail.fields
|
||||
import wagtail.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0001_initial'),
|
||||
('wagtailcore', '0091_remove_revision_submitted_for_moderation'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FooterText',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('translation_key', models.UUIDField(default=uuid.uuid4, editable=False)),
|
||||
('live', models.BooleanField(default=True, editable=False, verbose_name='live')),
|
||||
('has_unpublished_changes', models.BooleanField(default=False, editable=False, verbose_name='has unpublished changes')),
|
||||
('first_published_at', models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='first published at')),
|
||||
('last_published_at', models.DateTimeField(editable=False, null=True, verbose_name='last published at')),
|
||||
('go_live_at', models.DateTimeField(blank=True, null=True, verbose_name='go live date/time')),
|
||||
('expire_at', models.DateTimeField(blank=True, null=True, verbose_name='expiry date/time')),
|
||||
('expired', models.BooleanField(default=False, editable=False, verbose_name='expired')),
|
||||
('body', wagtail.fields.RichTextField()),
|
||||
('latest_revision', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.revision', verbose_name='latest revision')),
|
||||
('live_revision', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.revision', verbose_name='live revision')),
|
||||
('locale', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='wagtailcore.locale')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Footer Text',
|
||||
'abstract': False,
|
||||
'unique_together': {('translation_key', 'locale')},
|
||||
},
|
||||
bases=(wagtail.models.PreviewableMixin, models.Model),
|
||||
),
|
||||
]
|
0
base/migrations/__init__.py
Normal file
0
base/migrations/__init__.py
Normal file
65
base/models.py
Normal file
65
base/models.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
from django.db import models
|
||||
from modelcluster.models import ClusterableModel
|
||||
from wagtail.admin.panels import (
|
||||
FieldPanel,
|
||||
MultiFieldPanel,
|
||||
PublishingPanel
|
||||
)
|
||||
from wagtail.fields import RichTextField
|
||||
from wagtail.models import (
|
||||
DraftStateMixin,
|
||||
PreviewableMixin,
|
||||
RevisionMixin,
|
||||
TranslatableMixin,
|
||||
)
|
||||
from wagtail.snippets.models import register_snippet
|
||||
|
||||
from wagtail.contrib.settings.models import (
|
||||
BaseGenericSetting,
|
||||
register_setting,
|
||||
)
|
||||
|
||||
@register_setting
|
||||
class NavigationSettings(BaseGenericSetting):
|
||||
linkedin_url = models.URLField(verbose_name="LinkedIn URL", blank=True)
|
||||
github_url = models.URLField(verbose_name="GitHub URL", blank=True)
|
||||
mastodon_url = models.URLField(verbose_name="Mastodon URL", blank=True)
|
||||
|
||||
panels = [
|
||||
MultiFieldPanel(
|
||||
[
|
||||
FieldPanel("linkedin_url"),
|
||||
FieldPanel("github_url"),
|
||||
FieldPanel("mastodon_url"),
|
||||
],
|
||||
"Social settings",
|
||||
)
|
||||
]
|
||||
|
||||
@register_snippet
|
||||
class FooterText(
|
||||
DraftStateMixin,
|
||||
RevisionMixin,
|
||||
PreviewableMixin,
|
||||
TranslatableMixin,
|
||||
models.Model,
|
||||
):
|
||||
|
||||
body = RichTextField()
|
||||
|
||||
panels = [
|
||||
FieldPanel("body"),
|
||||
PublishingPanel(),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return "Footer text"
|
||||
|
||||
def get_preview_template(self, request, mode_name):
|
||||
return "base.html"
|
||||
|
||||
def get_preview_context(self, request, mode_name):
|
||||
return {"footer_text": self.body}
|
||||
|
||||
class Meta(TranslatableMixin.Meta):
|
||||
verbose_name_plural = "Footer Text"
|
5
base/templates/base/includes/footer_text.html
Normal file
5
base/templates/base/includes/footer_text.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% load wagtailcore_tags %}
|
||||
|
||||
<div>
|
||||
{{ footer_text|richtext }}
|
||||
</div>
|
0
base/templatetags/__init__.py
Normal file
0
base/templatetags/__init__.py
Normal file
23
base/templatetags/navigation_tags.py
Normal file
23
base/templatetags/navigation_tags.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from django import template
|
||||
from wagtail.models import Site
|
||||
from base.models import FooterText
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.inclusion_tag("base/includes/footer_text.html", takes_context=True)
|
||||
def get_footer_text(context):
|
||||
footer_text = context.get("footer_text", "")
|
||||
|
||||
if not footer_text:
|
||||
instance = FooterText.objects.filter(live=True).first()
|
||||
footer_text = instance.body if instance else ""
|
||||
|
||||
return {
|
||||
"footer_text": footer_text,
|
||||
}
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def get_site_root(context):
|
||||
return Site.find_for_request(context["request"]).root_page
|
3
base/tests.py
Normal file
3
base/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
base/views.py
Normal file
3
base/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Add table
Add a link
Reference in a new issue