8

Wagtail 3 changes

This commit is contained in:
Alex Bridge
2022-01-28 11:53:57 +00:00
committed by nick.moreton
parent dd4530203f
commit c7eaec1315
89 changed files with 3003 additions and 1456 deletions

View File

@@ -1,4 +1,4 @@
Django>=2.2,<2.3
wagtail>=2.6,<2.7
django-debug-toolbar==2.0
Django>=2.2,<4.1
wagtail>=2.9,<4.0
django-debug-toolbar==3.5.0
-e .[docs,test]

View File

@@ -2,9 +2,9 @@
# Generated by Django 1.11.1 on 2017-05-31 16:59
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models
class Migration(migrations.Migration):
@@ -12,19 +12,29 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('wagtailcore', '0033_remove_golive_expiry_help_text'),
('wagtail_personalisation', '0011_personalisablepagemetadata'),
("wagtailcore", "0033_remove_golive_expiry_help_text"),
("wagtail_personalisation", "0011_personalisablepagemetadata"),
]
operations = [
migrations.CreateModel(
name='HomePage',
name="HomePage",
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')),
(
"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",
),
),
],
options={
'abstract': False,
"abstract": False,
},
bases=('wagtailcore.page', models.Model),
bases=("wagtailcore.page", models.Model),
),
]

View File

@@ -6,10 +6,10 @@ from django.db import migrations
def create_homepage(apps, schema_editor):
# Get models
ContentType = apps.get_model('contenttypes.ContentType')
Page = apps.get_model('wagtailcore.Page')
Site = apps.get_model('wagtailcore.Site')
HomePage = apps.get_model('home.HomePage')
ContentType = apps.get_model("contenttypes.ContentType")
Page = apps.get_model("wagtailcore.Page")
Site = apps.get_model("wagtailcore.Site")
HomePage = apps.get_model("home.HomePage")
# Delete the default homepage
# If migration is run multiple times, it may have already been deleted
@@ -17,41 +17,41 @@ def create_homepage(apps, schema_editor):
# Create content type for homepage model
homepage_content_type, __ = ContentType.objects.get_or_create(
model='homepage', app_label='home')
model="homepage", app_label="home"
)
# Create a new homepage
homepage = HomePage.objects.create(
title="Home",
slug='home',
slug="home",
content_type=homepage_content_type,
path='00010001',
path="00010001",
depth=2,
numchild=0,
url_path='/home/',
url_path="/home/",
)
# Create a site with the new homepage set as the root
Site.objects.create(
hostname='localhost', root_page=homepage, is_default_site=True)
Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)
def remove_homepage(apps, schema_editor):
# Get models
ContentType = apps.get_model('contenttypes.ContentType')
HomePage = apps.get_model('home.HomePage')
ContentType = apps.get_model("contenttypes.ContentType")
HomePage = apps.get_model("home.HomePage")
# Delete the default homepage
# Page and Site objects CASCADE
HomePage.objects.filter(slug='home', depth=2).delete()
HomePage.objects.filter(slug="home", depth=2).delete()
# Delete content type for homepage model
ContentType.objects.filter(model='homepage', app_label='home').delete()
ContentType.objects.filter(model="homepage", app_label="home").delete()
class Migration(migrations.Migration):
dependencies = [
('home', '0001_initial'),
("home", "0001_initial"),
]
operations = [

View File

@@ -3,28 +3,59 @@
from __future__ import unicode_literals
from django.db import migrations
import wagtail.core.fields
from wagtail import VERSION as WAGTAIL_VERSION
import wagtail_personalisation
if WAGTAIL_VERSION >= (3, 0):
from wagtail import blocks as wagtail_blocks
from wagtail import fields as wagtail_fields
else:
from wagtail.core import blocks as wagtail_blocks
from wagtail.core import fields as wagtail_fields
class Migration(migrations.Migration):
dependencies = [
('home', '0002_create_homepage'),
("home", "0002_create_homepage"),
]
operations = [
migrations.AddField(
model_name='homepage',
name='intro',
field=wagtail.core.fields.RichTextField(
default='<p>Thank you for trying <a href="http://wagxperience.io" target="_blank">Wagxperience</a>!</p>'),
model_name="homepage",
name="intro",
field=wagtail_fields.RichTextField(
default='<p>Thank you for trying <a href="http://wagxperience.io" target="_blank">Wagxperience</a>!</p>'
),
preserve_default=False,
),
migrations.AddField(
model_name='homepage',
name='body',
field=wagtail.core.fields.StreamField((('personalisable_paragraph', wagtail.core.blocks.StructBlock((('segment', wagtail.core.blocks.ChoiceBlock(choices=wagtail_personalisation.blocks.list_segment_choices, help_text='Only show this content block for users in this segment', label='Personalisation segment', required=False)), ('paragraph', wagtail.core.blocks.RichTextBlock())), icon='pilcrow')),), default=''),
model_name="homepage",
name="body",
field=wagtail_fields.StreamField(
(
(
"personalisable_paragraph",
wagtail_blocks.StructBlock(
(
(
"segment",
wagtail_blocks.ChoiceBlock(
choices=wagtail_personalisation.blocks.list_segment_choices,
help_text="Only show this content block for users in this segment",
label="Personalisation segment",
required=False,
),
),
("paragraph", wagtail_blocks.RichTextBlock()),
),
icon="pilcrow",
),
),
),
default="",
),
preserve_default=False,
),
]

View File

@@ -1,23 +1,45 @@
from __future__ import absolute_import, unicode_literals
from wagtail.admin.edit_handlers import RichTextFieldPanel, StreamFieldPanel
from wagtail.core import blocks
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page
from wagtail import VERSION as WAGTAIL_VERSION
if WAGTAIL_VERSION >= (3, 0):
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page
else:
from wagtail.admin.edit_handlers import RichTextFieldPanel, StreamFieldPanel
from wagtail.core import blocks
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page
from wagtail_personalisation.models import PersonalisablePageMixin
from wagtail_personalisation.blocks import PersonalisedStructBlock
from wagtail_personalisation.models import PersonalisablePageMixin
class HomePage(PersonalisablePageMixin, Page):
intro = RichTextField()
body = StreamField([
('personalisable_paragraph', PersonalisedStructBlock([
('paragraph', blocks.RichTextBlock()),
], icon='pilcrow'))
])
body = StreamField(
[
(
"personalisable_paragraph",
PersonalisedStructBlock(
[
("paragraph", blocks.RichTextBlock()),
],
icon="pilcrow",
),
)
]
)
content_panels = Page.content_panels + [
RichTextFieldPanel('intro'),
StreamFieldPanel('body'),
]
if WAGTAIL_VERSION >= (3, 0):
content_panels = Page.content_panels + [
FieldPanel("intro"),
FieldPanel("body"),
]
else:
content_panels = Page.content_panels + [
RichTextFieldPanel("intro"),
StreamFieldPanel("body"),
]

View File

@@ -2,14 +2,19 @@ from __future__ import absolute_import, unicode_literals
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.shortcuts import render
from wagtail import VERSION as WAGTAIL_VERSION
if WAGTAIL_VERSION >= (3, 0):
from wagtail.models import Page
else:
from wagtail.core.models import Page
from wagtail.core.models import Page
from wagtail.search.models import Query
def search(request):
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)
search_query = request.GET.get("query", None)
page = request.GET.get("page", 1)
# Search
if search_query:
@@ -30,7 +35,11 @@ def search(request):
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
return render(request, 'search/search.html', {
'search_query': search_query,
'search_results': search_results,
})
return render(
request,
"search/search.html",
{
"search_query": search_query,
"search_results": search_results,
},
)

View File

@@ -12,31 +12,30 @@ class UserAdmin(BaseUserAdmin):
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ['email']
list_filter = ['is_superuser']
list_display = ["email"]
list_filter = ["is_superuser"]
fieldsets = (
(None, {
'fields': ['email', 'password']
}),
('Personal info', {
'fields': ['first_name', 'last_name']
}),
('Permissions', {
'fields': [
'is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions'
]
}),
(None, {"fields": ["email", "password"]}),
("Personal info", {"fields": ["first_name", "last_name"]}),
(
"Permissions",
{
"fields": [
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
]
},
),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ['email', 'password1', 'password2']
}),
(None, {"classes": ("wide",), "fields": ["email", "password1", "password2"]}),
)
search_fields = ['first_name', 'last_name', 'email']
ordering = ['email']
search_fields = ["first_name", "last_name", "email"]
ordering = ["email"]
filter_horizontal = []

View File

@@ -1,6 +1,11 @@
from django import VERSION as DJANGO_VERSION
from django import forms
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.utils.translation import ugettext_lazy as _
if DJANGO_VERSION >= (3, 0):
from django.utils.translation import gettext_lazy as _
else:
from django.utils.translation import ugettext_lazy as _
from sandbox.apps.user import models
@@ -10,21 +15,22 @@ class UserCreationForm(forms.ModelForm):
fields, plus a repeated password.
"""
password1 = forms.CharField(
label='Password', widget=forms.PasswordInput,
required=False)
label="Password", widget=forms.PasswordInput, required=False
)
password2 = forms.CharField(
label='Password confirmation', widget=forms.PasswordInput,
required=False)
label="Password confirmation", widget=forms.PasswordInput, required=False
)
class Meta:
model = models.User
fields = ['email']
fields = ["email"]
def clean_password2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2
@@ -32,7 +38,7 @@ class UserCreationForm(forms.ModelForm):
def save(self, commit=True):
# Save the provided password in hashed format
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data['password1'])
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
@@ -44,20 +50,22 @@ class UserChangeForm(forms.ModelForm):
password hash display field.
"""
password = ReadOnlyPasswordHashField(
label=_("Password"),
help_text=_("Raw passwords are not stored, so there is no way to see "
"this user's password, but you can change the password "
"using <a href=\"password/\">this form</a>."))
help_text=_(
"Raw passwords are not stored, so there is no way to see "
"this user's password, but you can change the password "
'using <a href="password/">this form</a>.'
),
)
class Meta:
model = models.User
fields = [
'email', 'password', 'is_active', 'is_superuser'
]
fields = ["email", "password", "is_active", "is_superuser"]
def clean_password(self):
# Regardless of what the user provides, return the initial value.
# This is done here, rather than on the field, because the
# field does not have access to the initial value
return self.initial['password']
return self.initial["password"]

View File

@@ -3,8 +3,8 @@
from __future__ import unicode_literals
import django.contrib.auth.models
from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
@@ -12,32 +12,109 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0008_alter_user_username_max_length'),
("auth", "0008_alter_user_username_max_length"),
]
operations = [
migrations.CreateModel(
name='User',
name="User",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('first_name', models.CharField(blank=True, max_length=100, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=100, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, unique=True, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=100, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=100, verbose_name="last name"
),
),
(
"email",
models.EmailField(
blank=True,
max_length=254,
unique=True,
verbose_name="email address",
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.Group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.Permission",
verbose_name="user permissions",
),
),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
"verbose_name": "user",
"verbose_name_plural": "users",
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
("objects", django.contrib.auth.models.UserManager()),
],
),
]

View File

@@ -1,20 +1,21 @@
# Generated by Django 2.1.7 on 2019-03-15 12:54
from django.db import migrations
import sandbox.apps.user.models
class Migration(migrations.Migration):
dependencies = [
('user', '0001_initial'),
("user", "0001_initial"),
]
operations = [
migrations.AlterModelManagers(
name='user',
name="user",
managers=[
('objects', sandbox.apps.user.models.UserManager()),
("objects", sandbox.apps.user.models.UserManager()),
],
),
]

View File

@@ -0,0 +1,20 @@
# Generated by Django 4.0.5 on 2022-06-30 15:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("user", "0002_auto_20190315_1254"),
]
operations = [
migrations.AlterField(
model_name="user",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
]

View File

@@ -1,9 +1,17 @@
from django import VERSION as DJANGO_VERSION
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin, BaseUserManager)
AbstractBaseUser,
BaseUserManager,
PermissionsMixin,
)
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
if DJANGO_VERSION >= (3, 0):
from django.utils.translation import gettext_lazy as _
else:
from django.utils.translation import ugettext_lazy as _
class UserManager(BaseUserManager):
@@ -14,7 +22,7 @@ class UserManager(BaseUserManager):
Create and save a user with the given username, email, and password.
"""
if not email:
raise ValueError('The given email address must be set')
raise ValueError("The given email address must be set")
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
@@ -22,52 +30,56 @@ class UserManager(BaseUserManager):
return user
def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
if extra_fields.get("is_staff") is not True:
raise ValueError("Superuser must have is_staff=True.")
if extra_fields.get("is_superuser") is not True:
raise ValueError("Superuser must have is_superuser=True.")
return self._create_user(email, password, **extra_fields)
class User(AbstractBaseUser, PermissionsMixin):
"""Customized version of the default `AbstractUser` from Django.
"""Customized version of the default `AbstractUser` from Django."""
"""
first_name = models.CharField(_('first name'), max_length=100, blank=True)
last_name = models.CharField(_('last name'), max_length=100, blank=True)
email = models.EmailField(_('email address'), blank=True, unique=True)
first_name = models.CharField(_("first name"), max_length=100, blank=True)
last_name = models.CharField(_("last name"), max_length=100, blank=True)
email = models.EmailField(_("email address"), blank=True, unique=True)
is_staff = models.BooleanField(
_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
_("staff status"),
default=False,
help_text=_("Designates whether the user can log into this admin " "site."),
)
is_active = models.BooleanField(
_('active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
_("active"),
default=True,
help_text=_(
"Designates whether this user should be treated as "
"active. Unselect this instead of deleting accounts."
),
)
date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
objects = UserManager()
USERNAME_FIELD = 'email'
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
verbose_name = _("user")
verbose_name_plural = _("users")
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
full_name = "%s %s" % (self.first_name, self.last_name)
return full_name.strip()
def get_short_name(self):

View File

@@ -14,7 +14,9 @@ from __future__ import absolute_import, unicode_literals
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from importlib.util import find_spec
from django import VERSION as DJANGO_VERSION
from wagtail import VERSION as WAGTAIL_VERSION
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(PROJECT_DIR)
@@ -22,10 +24,10 @@ BASE_DIR = os.path.dirname(PROJECT_DIR)
DEBUG = True
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^anfvx$i7%wts8j=7u1h5ua$w6c76*333(@h)rrjlak1c&x0r+'
SECRET_KEY = "^anfvx$i7%wts8j=7u1h5ua$w6c76*333(@h)rrjlak1c&x0r+"
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
@@ -35,90 +37,80 @@ SITE_ID = 1
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'wagtail.contrib.modeladmin',
'wagtailfontawesome',
'modelcluster',
'taggit',
'debug_toolbar',
'wagtail_personalisation',
'sandbox.apps.home',
'sandbox.apps.search',
'sandbox.apps.user',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.staticfiles",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
"wagtail.contrib.modeladmin",
"wagtailfontawesome",
"modelcluster",
"taggit",
"debug_toolbar",
"wagtail_personalisation",
"sandbox.apps.home",
"sandbox.apps.search",
"sandbox.apps.user",
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.http.ConditionalGetMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
if find_spec('wagtail.contrib.legacy'):
MIDDLEWARE += ('wagtail.contrib.legacy.sitemiddleware.SiteMiddleware',)
else:
MIDDLEWARE += ('wagtail.core.middleware.SiteMiddleware', )
ROOT_URLCONF = 'sandbox.urls'
ROOT_URLCONF = "sandbox.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_DIR, 'templates'),
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(PROJECT_DIR, "templates"),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = 'sandbox.wsgi.application'
WSGI_APPLICATION = "sandbox.wsgi.application"
AUTH_USER_MODEL = 'user.User'
AUTH_USER_MODEL = "user.User"
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "db.sqlite3",
}
}
@@ -126,9 +118,9 @@ DATABASES = {
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"
USE_I18N = True
@@ -141,19 +133,19 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, 'static'),
os.path.join(PROJECT_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
# Wagtail settings
@@ -162,7 +154,13 @@ WAGTAIL_SITE_NAME = "sandbox"
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
if WAGTAIL_VERSION >= (3, 0):
WAGTAILADMIN_BASE_URL = "http://example.com"
else:
BASE_URL = "http://example.com"
INTERNAL_IPS = ['127.0.0.1']
INTERNAL_IPS = ["127.0.0.1"]
if DJANGO_VERSION >= (3, 0):
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

View File

@@ -2,8 +2,8 @@ from __future__ import absolute_import, unicode_literals
import debug_toolbar
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.urls import include, re_path
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
@@ -11,18 +11,14 @@ from wagtail.documents import urls as wagtaildocs_urls
from sandbox.apps.search import views as search_views
urlpatterns = [
url(r'^django-admin/', admin.site.urls),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^search/$', search_views.search, name='search'),
re_path(r"^django-admin/", admin.site.urls),
re_path(r"^admin/", include(wagtailadmin_urls)),
re_path(r"^documents/", include(wagtaildocs_urls)),
re_path(r"^search/$", search_views.search, name="search"),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
url(r'', include(wagtail_urls)),
re_path(r"", include(wagtail_urls)),
# Alternatively, if you want Wagtail pages to be served from a subpath
# of your site, rather than the site root:
# url(r'^pages/', include(wagtail_urls)),
@@ -38,5 +34,5 @@ if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
re_path(r"^__debug__/", include(debug_toolbar.urls)),
] + urlpatterns