Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure compatibility with Wagtail 3.0 #18

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The current version is tested for compatiblily with the following:

- Wagtail versions 2.7 to 2.15
- Django versions 2.2 to 3.2
- Python versions 3.6 and 3.9
- Python versions 3.7 to 3.10

Authored by `Basil Shubin <https://github.com/bashu>`_, and some great
`contributors <https://github.com/bashu/wagtail-metadata-mixin/contributors>`_.
Expand Down Expand Up @@ -74,7 +74,7 @@ Usage

# models.py

from wagtail.core.models import Page, PageBase
from wagtail.models import Page, PageBase

from wagtailmetadata.models import MetadataPageMixin

Expand Down
1 change: 0 additions & 1 deletion example/localsite/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "localsite.apps.DefaultConfig"
4 changes: 2 additions & 2 deletions example/localsite/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.template.defaultfilters import truncatewords


def mixin(cls, mixins):
def add_mixins(cls, mixins):
for mixin in mixins:
if mixin not in cls.__bases__:
cls.__bases__ = (mixin,) + cls.__bases__
Expand All @@ -13,7 +13,7 @@ def mixin(cls, mixins):
def handle_blog_model(sender, instance, **kwargs):
from wagtailmetadata.models import MetadataMixin

sender = mixin(sender, [MetadataMixin])
sender = add_mixins(sender, [MetadataMixin])

def get_meta_description(cls):
return cls.search_description or truncatewords(cls.description, 20)
Expand Down
6 changes: 3 additions & 3 deletions example/puput_migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import modelcluster.contrib.taggit
import modelcluster.fields
import puput.routes
import wagtail.core.fields
import wagtail.fields
from django.db import migrations, models


Expand Down Expand Up @@ -111,11 +111,11 @@ class Migration(migrations.Migration):
on_delete=models.CASCADE,
),
),
("body", wagtail.core.fields.RichTextField(verbose_name="body")),
("body", wagtail.fields.RichTextField(verbose_name="body")),
("date", models.DateTimeField(default=datetime.datetime.today, verbose_name="Post date")),
(
"excerpt",
wagtail.core.fields.RichTextField(
wagtail.fields.RichTextField(
help_text="Used to display on puput pages list. If this field is not filled, a truncate version of body text will be used.",
verbose_name="excerpt",
blank=True,
Expand Down
4 changes: 2 additions & 2 deletions example/puput_migrations/0002_auto_20150919_0925.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import wagtail.core.fields
import wagtail.fields
from django.db import migrations, models


Expand Down Expand Up @@ -42,7 +42,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="entrypage",
name="excerpt",
field=wagtail.core.fields.RichTextField(
field=wagtail.fields.RichTextField(
help_text="Entry excerpt to be displayed on entries list. If this field is not filled, a truncate version of body text will be used.",
verbose_name="excerpt",
blank=True,
Expand Down
8 changes: 4 additions & 4 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django==3.0.14
wagtail>2.11,<3.0
django-meta>1.7.0 # https://github.com/nephila/django-meta
puput==1.1.1 # https://github.com/APSL/puput
Django == 3.2.*
wagtail == 4.1.*
django-meta >= 2.1.0 # https://github.com/nephila/django-meta
puput == 1.2.0 # https://github.com/APSL/puput
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider going to version 1.2.1. That adds support for Django 4 versions, but drops support for Python 3.7.

12 changes: 10 additions & 2 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# 'django.middleware.security.SecurityMiddleware',
"wagtail.core.middleware.SiteMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]

Expand Down Expand Up @@ -88,7 +87,12 @@
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3")}}
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

MIGRATION_MODULES = {"puput": "example.puput_migrations"}

Expand Down Expand Up @@ -134,3 +138,7 @@

# wagtail
WAGTAIL_SITE_NAME = "Puput Blog"
# Using an empty string is only useful to suppress Wagtail warning for missing
# setting. Set this to something realistic, if necessary. See
# https://docs.wagtail.org/en/latest/reference/settings.html#wagtailadmin-base-url
WAGTAILADMIN_BASE_URL = ''
6 changes: 3 additions & 3 deletions example/templates/puput/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ <h4>{% trans 'Archive' %}</h4>
<div class="footer_bottom">
<div class="copy">
<p>
Powered by <a href="http://www.djangoproject.com" rel="nofollow">Django</a>,
<a href="http://www.wagtail.io" rel="nofollow">Wagtail</a> and
<a href="http://github.com/APSL/puput" rel="nofollow">Puput</a>
Powered by <a href="https://www.djangoproject.com" rel="nofollow">Django</a>,
<a href="https://wagtail.org/" rel="nofollow">Wagtail</a> and
<a href="https://github.com/APSL/puput" rel="nofollow">Puput</a>
</p>
</div>
</div>
Expand Down
15 changes: 7 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = wagtail-metadata-mixin
version = 2.0.2
version = 3.0
description = OpenGraph, Twitter Card and Schema.org snippet tags for Wagtail CMS pages
long_description = file: README.rst, CHANGES.rst
long_description_content_type = text/x-rst
Expand All @@ -17,17 +17,16 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Framework :: Django
Framework :: Django :: 2.2
Framework :: Django :: 3.0
Framework :: Django :: 3.1
Framework :: Django :: 3.2
Framework :: Django :: 4
Framework :: Wagtail
Framework :: Wagtail :: 2
Framework :: Wagtail :: 3
Framework :: Wagtail :: 4
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Software Development :: Libraries :: Python Modules
Expand All @@ -37,8 +36,8 @@ zip_safe = False
include_package_data = True
packages = find:
install_requires =
django-meta>1.7.0
wagtail>1.4,<3.0
django-meta>=2.1.0
wagtail>=3.0

[options.packages.find]
exclude = example*
Expand Down
29 changes: 9 additions & 20 deletions wagtailmetadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from meta import settings as meta_settings
from meta import utils
from meta.models import ModelMeta
from wagtail.core.models import Site
from wagtail.admin.panels import FieldPanel
from wagtail.models import Site
from wagtail.images import get_image_model_string
from wagtail.images.edit_handlers import ImageChooserPanel


class MetadataMixin(ModelMeta):
Expand Down Expand Up @@ -84,16 +84,6 @@ def get_meta_schemaorg_type(self):

def get_meta_site_name(self):
request = utils.get_request()
site = getattr(request, "site", None)
if request and isinstance(site, Site):
if bool(request.site.site_name) is True:
return request.site.site_name

site = self.get_site()
if isinstance(site, Site):
if bool(site.site_name) is True:
return site.site_name

if request:
site = Site.find_for_request(request)
if isinstance(site, Site):
Expand All @@ -120,12 +110,9 @@ def get_meta_custom_namespace(self):

def get_domain(self):
request = utils.get_request()
if request and getattr(request, "site", None):
return request.site.hostname

site = self.get_site()
if site is not None:
if bool(site.hostname) is True:
if request:
site = Site.find_for_request(request)
if isinstance(site, Site):
return site.hostname

if not meta_settings.SITE_DOMAIN:
Expand Down Expand Up @@ -175,7 +162,7 @@ class MetadataPageMixin(MetadataMixin, models.Model):
related_name="+",
)

panels = [ImageChooserPanel("search_image")]
panels = [FieldPanel("search_image")]

_metadata = {
"published_time": "published_time",
Expand Down Expand Up @@ -205,7 +192,9 @@ def get_meta_url(self):
def get_meta_image(self):
if self.search_image is not None:
return self.build_absolute_uri(
self.search_image.get_rendition(getattr(settings, "META_SEARCH_IMAGE_RENDITION", "fill-800x450")).url
self.search_image.get_rendition(
getattr(settings, "META_SEARCH_IMAGE_RENDITION", "fill-800x450")
).url
)
return super().get_meta_image()

Expand Down
2 changes: 1 addition & 1 deletion wagtailmetadata/tests/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from wagtail.core.models import Page
from wagtail.models import Page

from wagtailmetadata.models import MetadataPageMixin

Expand Down
3 changes: 1 addition & 2 deletions wagtailmetadata/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"django.contrib.staticfiles",
"taggit",
"modelcluster",
"wagtail.core",
"wagtail",
"wagtail.users",
"wagtail.images",
"wagtail.admin",
Expand All @@ -34,7 +34,6 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"wagtail.core.middleware.SiteMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]

Expand Down
5 changes: 3 additions & 2 deletions wagtailmetadata/tests/test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from django.test import TestCase
from django.utils import timezone
from meta import settings as meta_settings
from wagtail.core.models import Site
from wagtail.images.models import Image
from wagtail.images.tests.utils import get_test_image_file
from wagtail.models import Site

from wagtailmetadata.tests.models import SimplePage

Expand Down Expand Up @@ -53,7 +53,8 @@ def test_get_meta_image(self):
self.page.search_image = self.image

self.assertEqual(
self.page.get_meta_image(), self.page.build_absolute_uri(self.image.get_rendition("fill-800x450").url)
self.page.get_meta_image(),
self.page.build_absolute_uri(self.image.get_rendition("fill-800x450").url)
)

def test_get_meta_image_with_settings(self):
Expand Down
2 changes: 1 addition & 1 deletion wagtailmetadata/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import include, path
from wagtail.core import urls as wagtail_urls
from wagtail import urls as wagtail_urls

urlpatterns = [path("", include(wagtail_urls))]