From 9a20df438375dd3c0aea2301523212d387f591a6 Mon Sep 17 00:00:00 2001 From: Wesley van Lee <32985132+leewesleyv@users.noreply.github.com> Date: Wed, 22 May 2024 13:36:16 +0200 Subject: [PATCH] Adds support up to Wagtail 5.2 (#286) * Adds Python3.12 and Wagtail 5.0, 5.1 and 5.2 to Tox and remove support for Wagtail <4.1 * Update requirements and tox * fix typo in tox.ini * Remove dependencies (django-social-share and django-colorful) since they are no longer actively maintained --------- Co-authored-by: Marco Badan Co-authored-by: Carlos Salom Oliver --- .github/workflows/tests.yml | 2 +- docs/setup.rst | 7 +-- puput/__init__.py | 1 - puput/abstracts.py | 4 +- puput/fields.py | 17 +++++++ puput/migrations/0005_blogpage_main_color.py | 4 +- puput/templates/puput/blog_page.html | 13 ++---- puput/templates/puput/entry_links.html | 2 + puput/templates/puput/entry_page.html | 14 ++---- puput/templates/puput/share_links.html | 21 +++++++++ .../puput/tags/post_to_linkedin.html | 3 -- puput/templatetags/puput_tags.py | 18 -------- puput/widgets.py | 5 +++ requirements-test.txt | 10 ++--- setup.py | 14 +++--- tox.ini | 45 +++++++++---------- 16 files changed, 91 insertions(+), 89 deletions(-) create mode 100644 puput/fields.py create mode 100644 puput/templates/puput/share_links.html delete mode 100644 puput/templates/puput/tags/post_to_linkedin.html create mode 100644 puput/widgets.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 713d057..18f47d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/docs/setup.rst b/docs/setup.rst index ea593f4..32c8871 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -26,7 +26,7 @@ If you are already referencing one of these apps in your :code:`INSTALLED_APPS` INSTALLED_APPS = ( ... 'wagtail.contrib.legacy.richtext', - 'wagtail.core', + 'wagtail', 'wagtail.admin', 'wagtail.documents', 'wagtail.snippets', @@ -41,7 +41,6 @@ If you are already referencing one of these apps in your :code:`INSTALLED_APPS` 'wagtail.contrib.routable_page', 'taggit', 'modelcluster', - 'django_social_share', 'puput', ) @@ -127,7 +126,7 @@ Installation on top of Wagtail pip install --upgrade pip pip install wheel - pip install wagtail django-colorful django-el-pagination django-social-share + pip install wagtail django-el-pagination pip install --no-deps puput wagtail start mysite cd mysite @@ -141,9 +140,7 @@ Installation on top of Wagtail 'wagtail.contrib.sitemaps', 'wagtail.contrib.routable_page', - 'django_social_share', 'puput', - 'colorful', 3. In the same file, also add the line :code:`PUPUT_AS_PLUGIN = True` to the very bottom diff --git a/puput/__init__.py b/puput/__init__.py index 9b2e170..d925942 100644 --- a/puput/__init__.py +++ b/puput/__init__.py @@ -21,7 +21,6 @@ # Third-party apps "taggit", "modelcluster", - "django_social_share", # Puput apps "puput", "wagtailmarkdown", diff --git a/puput/abstracts.py b/puput/abstracts.py index 2fb50e2..3b6edb9 100644 --- a/puput/abstracts.py +++ b/puput/abstracts.py @@ -12,8 +12,8 @@ from wagtail.fields import RichTextField from modelcluster.contrib.taggit import ClusterTaggableManager from wagtailmarkdown.fields import MarkdownField -from colorful.fields import RGBColorField +from .fields import ColorField from .utils import get_image_model_path import markdown @@ -34,7 +34,7 @@ class BlogAbstract(models.Model): related_name="+", ) - main_color = RGBColorField(_("Blog Main Color"), default="#4D6AE0") + main_color = ColorField(_("Blog Main Color"), default="#4D6AE0") display_comments = models.BooleanField(default=False, verbose_name=_("Display comments")) display_categories = models.BooleanField(default=True, verbose_name=_("Display categories")) diff --git a/puput/fields.py b/puput/fields.py new file mode 100644 index 0000000..f702c63 --- /dev/null +++ b/puput/fields.py @@ -0,0 +1,17 @@ +from django.db import models + +from puput.widgets import ColorPickerWidget + + +class ColorField(models.CharField): + """ + A CharField which uses the HTML5 color picker widget. + """ + + def __init__(self, *args, **kwargs): + kwargs["max_length"] = 255 + super().__init__(*args, **kwargs) + + def formfield(self, **kwargs): + kwargs["widget"] = ColorPickerWidget + return super().formfield(**kwargs) diff --git a/puput/migrations/0005_blogpage_main_color.py b/puput/migrations/0005_blogpage_main_color.py index 52f06b4..8c7e250 100644 --- a/puput/migrations/0005_blogpage_main_color.py +++ b/puput/migrations/0005_blogpage_main_color.py @@ -2,7 +2,7 @@ # Generated by Django 1.11.4 on 2018-04-09 18:57 from __future__ import unicode_literals -import colorful.fields +import puput.fields from django.db import migrations @@ -16,6 +16,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='blogpage', name='main_color', - field=colorful.fields.RGBColorField(default='#4D6AE0', verbose_name='Blog Main Color'), + field=puput.fields.ColorField(default='#4D6AE0', verbose_name='Blog Main Color'), ), ] diff --git a/puput/templates/puput/blog_page.html b/puput/templates/puput/blog_page.html index a0a7d69..ce8b75f 100644 --- a/puput/templates/puput/blog_page.html +++ b/puput/templates/puput/blog_page.html @@ -1,6 +1,6 @@ {% extends "puput/base.html" %} -{% load static i18n wagtailcore_tags wagtailimages_tags puput_tags social_share %} +{% load static i18n wagtailcore_tags wagtailimages_tags puput_tags %} {% block title %} {% if search_term %} @@ -69,16 +69,9 @@ {{ entry.body|richtext|truncatewords_html:70 }} {% endif %}
+ {% canonical_url entry as share_url %}
{% trans 'Continue reading' %} » diff --git a/puput/templates/puput/entry_links.html b/puput/templates/puput/entry_links.html index dacea3a..3f44076 100644 --- a/puput/templates/puput/entry_links.html +++ b/puput/templates/puput/entry_links.html @@ -1,12 +1,14 @@ {% load wagtailroutablepage_tags puput_tags %}
- {% entry_url self blog_page as post_url %} + {% canonical_url self as share_url %}
diff --git a/puput/templates/puput/share_links.html b/puput/templates/puput/share_links.html new file mode 100644 index 0000000..ad0d97a --- /dev/null +++ b/puput/templates/puput/share_links.html @@ -0,0 +1,21 @@ + + + diff --git a/puput/templates/puput/tags/post_to_linkedin.html b/puput/templates/puput/tags/post_to_linkedin.html deleted file mode 100644 index 89e031d..0000000 --- a/puput/templates/puput/tags/post_to_linkedin.html +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/puput/templatetags/puput_tags.py b/puput/templatetags/puput_tags.py index 57fefa1..0940ea4 100644 --- a/puput/templatetags/puput_tags.py +++ b/puput/templatetags/puput_tags.py @@ -1,8 +1,6 @@ from django.template import Library from django.urls import resolve -from django.template.defaultfilters import urlencode from django.template.loader import render_to_string -from django_social_share.templatetags.social_share import _build_url from el_pagination.templatetags.el_pagination_tags import show_pages, paginate from ..conf import settings @@ -109,19 +107,3 @@ def show_comments(context): # Avoid to import endless_pagination in installed_apps and in the templates register.tag("show_paginator", show_pages) register.tag("paginate", paginate) - - -@register.simple_tag(takes_context=True) -def post_to_linkendin_url(context, obj_or_url=None): - request = context.get("request") - if request: - url = _build_url(request, obj_or_url) - context["linkendin_url"] = "https://www.linkedin.com/shareArticle?url={}".format(urlencode(url)) - return context - - -@register.inclusion_tag("puput/tags/post_to_linkedin.html", takes_context=True) -def post_to_linkendin(context, obj_or_url=None, link_text="Post to LinkedIn"): - context = post_to_linkendin_url(context, obj_or_url) - context["link_text"] = link_text - return context diff --git a/puput/widgets.py b/puput/widgets.py new file mode 100644 index 0000000..b3a3cff --- /dev/null +++ b/puput/widgets.py @@ -0,0 +1,5 @@ +from django import forms + + +class ColorPickerWidget(forms.TextInput): + input_type = "color" diff --git a/requirements-test.txt b/requirements-test.txt index a1705e9..4cf56f9 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,6 @@ -pytest==7.1.2 -pytest-django==4.1.0 +pytest==8.0.0 +pytest-django==4.8.0 requests==2.32.0 -model-bakery==1.5.0 -ipdb==0.13.9 -tox==3.27.1 +model-bakery==1.17.0 +ipdb==0.13.13 +tox==4.12.1 \ No newline at end of file diff --git a/setup.py b/setup.py index d3d604b..481c365 100644 --- a/setup.py +++ b/setup.py @@ -25,13 +25,10 @@ def get_metadata(package, field): description='A Django blog app implemented in Wagtail.', long_description=codecs.open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8').read(), install_requires=[ - 'Django>=3.2,<4.3', - 'wagtail>=4.0,<5.1', + 'wagtail>=5.2', 'django-el-pagination==4.0.0', - 'django-social-share>=1.3.0', - 'django-colorful>=1.3', 'django-taggit>=3.1.0,<4.1', - 'wagtail-markdown==0.11.0' + 'wagtail-markdown==0.11.1' ], url='http://github.com/APSL/puput', author=get_metadata('puput', 'author'), @@ -40,10 +37,10 @@ def get_metadata(package, field): classifiers=[ 'Environment :: Web Environment', 'Framework :: Django', - 'Framework :: Django :: 3.2', - 'Framework :: Django :: 4.0', - 'Framework :: Django :: 4.1', 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', + 'Framework :: Wagtail', + 'Framework :: Wagtail :: 5', 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: 3', @@ -51,6 +48,7 @@ def get_metadata(package, field): 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Operating System :: OS Independent', 'Topic :: Software Development' ] diff --git a/tox.ini b/tox.ini index 6762727..966d942 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,18 @@ [tox] -envlist = py{38,39,310,311}-dj{32,40,41,42}, flake8, black +envlist = + py{38,39,310}-dj{42}-wt52 + py311-dj{42,50}-wt52 + py312-dj{42,50}-wt52 + flake8 + black [gh-actions] python = - 3.8: py38-dj{32,40,41,42}, flake8, black - 3.9: py39-dj{32,40,41,42} - 3.10: py310-dj{32,40,41,42} - 3.11: py311-dj{32,40,41,42} - + 3.8: py38-dj42-wt52 + 3.9: py38-dj42-wt52 + 3.10: py310-dj{42,50}-wt52 + 3.11: py311-dj{42,50}-wt52 + 3.12: py312-dj{42,50}-wt52, flake8, black [flake8] max-line-length = 120 @@ -21,29 +26,23 @@ commands = pytest --create-db --no-migrations deps = - pytest==7.1.2 - pytest-django==4.1.0 - requests==2.28.1 - model-bakery==1.5.0 - ipdb==0.13.9 - + pytest==8.0.0 + pytest-django==4.8.0 + requests==2.31.0 + model-bakery==1.17.0 + ipdb==0.13.13 django-el-pagination==4.0 - django-social-share>=1.3.0 - django-colorful>=1.3 tapioca-disqus==0.1.2 - - dj32: Django>=3.2,<3.3 - dj40: Django>=4.0,<4.1 - dj41: Django>=4.1,<4.2 dj42: Django>=4.2,<4.3 - + dj50: Django>=5.0,<5.1 + wt52: wagtail>=5.2,<5.3 [testenv:flake8] -basepython = python3.10 -deps = flake8==4.0.1 +basepython = python3.12 +deps = flake8==7.0.0 commands = flake8 puput tests --exclude=migrations [testenv:black] -basepython = python3.10 -deps = black==22.3.0 +basepython = python3.12 +deps = black==24.1.1 commands = black puput tests -l 120 --check --extend-exclude=/migrations/