1
Fork 0

Add home page model and base template

This commit is contained in:
Jake Howard 2018-07-24 20:56:38 +01:00
parent 781276c7c7
commit 510daf113d
Signed by: jake
GPG Key ID: 57AFB45680EDD477
8 changed files with 117 additions and 57 deletions

33
project/common/models.py Normal file
View File

@ -0,0 +1,33 @@
from wagtail.core.models import Page
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
class Entity(MetadataPageMixin, Page):
is_home = False
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
post_date = models.DateTimeField(null=True, blank=True)
promote_panels = [
MultiFieldPanel([
FieldPanel('slug'),
FieldPanel('seo_title'),
FieldPanel('post_date'),
FieldPanel('search_description'),
ImageChooserPanel('search_image'),
], 'Common page configuration'),
]
@property
def image(self):
return self.search_image
def get_meta_description(self):
return self.search_description or self.short_body
class Meta:
abstract = True

View File

@ -0,0 +1,44 @@
# Generated by Django 2.0.7 on 2018-07-24 19:34
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import wagtail.core.fields
class Migration(migrations.Migration):
dependencies = [
('wagtailimages', '0020_add-verbose-name'),
('home', '0002_create_homepage'),
]
operations = [
migrations.AddField(
model_name='homepage',
name='body',
field=wagtail.core.fields.RichTextField(default=''),
preserve_default=False,
),
migrations.AddField(
model_name='homepage',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='homepage',
name='modified',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='homepage',
name='post_date',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='homepage',
name='search_image',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
),
]

View File

@ -1,7 +1,14 @@
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from project.common.models import Entity
class HomePage(Page):
pass
class HomePage(Entity):
is_home = True
body = RichTextField()
content_panels = Entity.content_panels + [
FieldPanel('body', classname="full")
]

View File

@ -1,11 +0,0 @@
{% extends "base.html" %}
{% block body_class %}template-homepage{% endblock %}
{% block content %}
<h1>Welcome to your new Wagtail site!</h1>
<p>You can access the admin interface <a href="{% url 'wagtailadmin_home' %}">here</a> (make sure you have run "./manage.py createsuperuser" in the console first).</p>
<p>If you haven't already given the documentation a read, head over to <a href="http://docs.wagtail.io/">http://docs.wagtail.io</a> to start building on Wagtail</p>
{% endblock %}

View File

@ -27,6 +27,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'project.home',
'project.search',
'project.common',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
@ -43,6 +44,8 @@ INSTALLED_APPS = [
'modelcluster',
'taggit',
'wagtailmetadata',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',

View File

@ -1,9 +1,3 @@
{% extends "base.html" %}
<h1>Page not found</h1>
{% block body_class %}template-404{% endblock %}
{% block content %}
<h1>Page not found</h1>
<h2>Sorry, this page could not be found.</h2>
{% endblock %}
<h2>Sorry, this page could not be found.</h2>

View File

@ -1,40 +1,25 @@
{% load static wagtailuserbar %}
{% load static wagtailuserbar wagtailmetadata_tags %}
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8" />
<title>
{% block title %}
{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}
{% endblock %}
{% block title_suffix %}
{% with self.get_site.site_name as site_name %}
{% if site_name %}- {{ site_name }}{% endif %}
{% endwith %}
{% endblock %}
</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!DOCTYPE HTML>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
<meta name="superfish" content="nofish" />
<meta name="application-name" content="{{ self.title }}" />
<link rel="icon" type="image/png" href='{% static "img/logo-transparent.png" %}'/>
<link rel="stylesheet" href='{% static "css/style.css" %}' />
{# Global stylesheets #}
<link rel="stylesheet" type="text/css" href="{% static 'css/project.css' %}">
{% meta_tags %}
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
{% endblock %}
</head>
<title>{{ self.title }}</title>
</head>
<body>
{% wagtailuserbar %}
<body class="{% block body_class %}{% endblock %}">
{% wagtailuserbar %}
{% block content %}{% endblock %}
{% block content %}{% endblock %}
{# Global javascript #}
<script type="text/javascript" src="{% static 'js/project.js' %}"></script>
{% block extra_js %}
{# Override this in templates to add extra javascript #}
{% endblock %}
</body>
<script src='{% static "js/mermaid.min.js" %}'></script>
<script src='{% static "js/app.js" %}'></script>
</body>
</html>

View File

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
{{ self.body }}
{% endblock %}