Skip to content

Commit

Permalink
Upgrade to django 4.2 / django CMS 3.11 (#722)
Browse files Browse the repository at this point in the history
* Fix pre-commit flake8 repo url
* Reformat for black update
* Remove python 3.6 from test matrix
* Replace flake8 with ruff

---------

Co-authored-by: Adrien Delhorme <ad@kapt.mobi>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 20, 2023
1 parent 6a3224e commit 8b83fad
Show file tree
Hide file tree
Showing 48 changed files with 231 additions and 311 deletions.
25 changes: 25 additions & 0 deletions .bumpversion.cfg
@@ -0,0 +1,25 @@
[bumpversion]
current_version = 1.2.3
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.?)(?P<release>[a-z]*)(?P<relver>\d*)
serialize =
{major}.{minor}.{patch}.{release}{relver}
{major}.{minor}.{patch}
commit = True
tag = True
sign_tags = True
tag_name = {new_version}
message = Release {new_version}

[bumpversion:part:release]
optional_value = gamma
values =
dev
a
b
rc
gamma

[bumpversion:part:relver]
first_value = 1

[bumpversion:file:djangocms_blog/__init__.py]
12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Expand Up @@ -8,26 +8,26 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
python-version: [3.8]
toxenv: [pep8, isort, black, pypi-description, docs, towncrier]
python-version: ["3.11.x"]
toxenv: [ruff, isort, black, pypi-description, docs, towncrier]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Cache tox
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .tox
key: ${{ runner.os }}-lint-${{ matrix.toxenv }}-${{ hashFiles('setup.cfg') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Expand Up @@ -8,20 +8,20 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Cache tox
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .tox
key: ${{ runner.os }}-tox-release-${{ hashFiles('setup.cfg') }}
Expand Down
27 changes: 11 additions & 16 deletions .github/workflows/test.yml
Expand Up @@ -8,34 +8,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, 3.8, 3.7]
django: [31, 30, 22]
cms: [38, 37]
python-version: ["3.11", "3.10", "3.9"]
django: [42, 41, 32]
cms: [311, 39]
exclude:
- django: 31
cms: 37
include:
- python-version: 3.8
django: 22
cms: no-search-37
- python-version: 3.8
django: 31
cms: no-search-38
- django: 41
cms: 39
- django: 42
cms: 39
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Cache tox
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .tox
key: ${{ runner.os }}-tox-${{ format('{{py{0}-django{1}-cms{2}}}', matrix.python-version, matrix.django, matrix.cms) }}-${{ hashFiles('setup.cfg') }}
Expand Down
35 changes: 11 additions & 24 deletions .pre-commit-config.yaml
Expand Up @@ -6,6 +6,7 @@ repos:
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: "setup.cfg"
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
Expand All @@ -16,42 +17,29 @@ repos:
- id: fix-encoding-pragma
args:
- --remove
- repo: https://github.com/timothycrosley/isort
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.262'
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line
- flake8-bugbear
- flake8-builtins
- flake8-coding
- flake8-commas
- flake8-comprehensions
- flake8-eradicate
- flake8-quotes
- flake8-tidy-imports
- pep8-naming
- repo: https://github.com/econchick/interrogate
rev: 1.5.0
hooks:
- id: interrogate
args:
- "-cpyproject.toml"
- "--quiet"
- id: ruff
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py3-plus
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.13.0"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: local
hooks:
- id: towncrier
Expand All @@ -60,7 +48,6 @@ repos:
language: system
pass_filenames: false
always_run: true

ci:
skip:
- towncrier
2 changes: 1 addition & 1 deletion .readthedocs.yml
Expand Up @@ -9,7 +9,7 @@ formats:
- pdf

python:
version: 3.7
version: 3.8
install:
- requirements: requirements-test.txt
- method: pip
Expand Down
10 changes: 2 additions & 8 deletions README.rst
Expand Up @@ -8,16 +8,11 @@ django CMS blog application - Support for multilingual posts, placeholders, soci

Supported Django versions:

* Django 2.2, 3.0, 3.1
* Django 3.2 - 4.2

Supported django CMS versions:

* django CMS 3.7, 3.8+

.. warning:: For Django<2.2, django CMS<3.7 versions support, use djangocms-blog 1.1x.

.. warning:: Version 1.2 introduce a breaking change for customized ``BLOG_PERMALINK_URLS``.
Check the `permalinks`_ documentation for update information.
* django CMS 3.9 - 3.11+

************
Installation
Expand Down Expand Up @@ -45,7 +40,6 @@ See `features documentation`_ for all the features details
* Auto Apphook setup
* Django sitemap framework
* django CMS Wizard integration
* Haystack index
* Desktop notifications
* Liveblog

Expand Down
1 change: 1 addition & 0 deletions changes/720.feature
@@ -0,0 +1 @@
Port to django 3.2/4.1 - django CMS 3.11
2 changes: 0 additions & 2 deletions djangocms_blog/__init__.py
@@ -1,5 +1,3 @@
__author__ = "Iacopo Spalletti"
__email__ = "i.spalletti@nephila.it"
__version__ = "1.2.3"

default_app_config = "djangocms_blog.apps.BlogAppConfig"
22 changes: 10 additions & 12 deletions djangocms_blog/admin.py
Expand Up @@ -85,6 +85,7 @@ def queryset(self, request, queryset):
raise admin.options.IncorrectLookupParameters(e)


@admin.register(BlogCategory)
class BlogCategoryAdmin(ModelAppHookConfig, TranslatableAdmin):
form = CategoryAdminForm
list_display = [
Expand All @@ -104,6 +105,7 @@ class Media:
css = {"all": ("{}djangocms_blog/css/{}".format(settings.STATIC_URL, "djangocms_blog_admin.css"),)}


@admin.register(Post)
class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin, ModelAppHookConfig, TranslatableAdmin):
form = PostAdminForm
list_display = ["title", "author", "date_published", "app_config", "all_languages_column", "date_published_end"]
Expand Down Expand Up @@ -167,6 +169,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin, ModelAppHookC
_sites = None

# Bulk actions for post admin
@admin.action(description=_("Publish selection"))
def make_published(self, request, queryset):
"""
Bulk action to mark selected posts as published.
Expand All @@ -188,6 +191,7 @@ def make_published(self, request, queryset):
% {"updates": cnt1 + cnt2},
)

@admin.action(description=_("Unpublish selection"))
def make_unpublished(self, request, queryset):
"""
Bulk action to mark selected posts as unpublished.
Expand All @@ -200,6 +204,7 @@ def make_unpublished(self, request, queryset):
__("%(updates)d entry unpublished.", "%(updates)d entries unpublished.", updates) % {"updates": updates},
)

@admin.action(description=_("Enable comments for selection"))
def enable_comments(self, request, queryset):
"""
Bulk action to enable comments for selected posts.
Expand All @@ -213,6 +218,7 @@ def enable_comments(self, request, queryset):
% {"updates": updates},
)

@admin.action(description=_("Disable comments for selection "))
def disable_comments(self, request, queryset):
"""
Bulk action to disable comments for selected posts.
Expand All @@ -226,6 +232,7 @@ def disable_comments(self, request, queryset):
% {"updates": updates},
)

@admin.action(description=_("Enable liveblog for selection"))
def enable_liveblog(self, request, queryset):
"""
Bulk action to enable comments for selected posts.
Expand All @@ -239,6 +246,7 @@ def enable_liveblog(self, request, queryset):
% {"updates": updates},
)

@admin.action(description=_("Disable liveblog for selection "))
def disable_liveblog(self, request, queryset):
"""
Bulk action to disable comments for selected posts.
Expand All @@ -253,12 +261,6 @@ def disable_liveblog(self, request, queryset):
)

# Make bulk action menu entries localizable
make_published.short_description = _("Publish selection")
make_unpublished.short_description = _("Unpublish selection")
enable_comments.short_description = _("Enable comments for selection")
disable_comments.short_description = _("Disable comments for selection ")
enable_liveblog.short_description = _("Enable liveblog for selection")
disable_liveblog.short_description = _("Disable liveblog for selection ")

def get_list_filter(self, request):
filters = ["app_config", "publish", "date_published"]
Expand Down Expand Up @@ -319,7 +321,7 @@ def publish_post(self, request, pk):
return HttpResponseRedirect(post.get_absolute_url(language))
except Exception:
try:
return HttpResponseRedirect(request.META["HTTP_REFERER"])
return HttpResponseRedirect(request.headers["referer"])
except KeyError:
return HttpResponseRedirect(reverse("djangocms_blog:posts-latest"))

Expand Down Expand Up @@ -453,6 +455,7 @@ class Media:
css = {"all": ("{}djangocms_blog/css/{}".format(settings.STATIC_URL, "djangocms_blog_admin.css"),)}


@admin.register(BlogConfig)
class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
@property
def declared_fieldsets(self):
Expand Down Expand Up @@ -551,8 +554,3 @@ def save_model(self, request, obj, form, change):

menu_pool.clear(all=True)
return super().save_model(request, obj, form, change)


admin.site.register(BlogCategory, BlogCategoryAdmin)
admin.site.register(Post, PostAdmin)
admin.site.register(BlogConfig, BlogConfigAdmin)
7 changes: 4 additions & 3 deletions djangocms_blog/cms_wizards.py
Expand Up @@ -115,7 +115,8 @@ class PostWizard(Wizard):
raise
else:
warnings.warn(
"Wizard {} cannot be registered. Please make sure that "
"BlogConfig.namespace {} and BlogConfig.app_title {} are"
"unique together".format(seed, config.namespace, config.app_title)
f"Wizard {seed} cannot be registered. Please make sure that "
f"BlogConfig.namespace {config.namespace} and BlogConfig.app_title {config.app_title} are"
"unique together",
stacklevel=2,
)
1 change: 0 additions & 1 deletion djangocms_blog/liveblog/__init__.py
@@ -1 +0,0 @@
default_app_config = "djangocms_blog.liveblog.apps.LiveBlogAppConfig"
4 changes: 1 addition & 3 deletions djangocms_blog/liveblog/cms_plugins.py
Expand Up @@ -7,6 +7,7 @@
from .models import Liveblog


@plugin_pool.register_plugin
class LiveblogPlugin(TextPlugin):
module = get_setting("PLUGIN_MODULE_NAME")
name = _("Liveblog item")
Expand All @@ -24,6 +25,3 @@ def render(self, context, instance, placeholder):
instance.content = context["body"]
context["instance"] = instance
return context


plugin_pool.register_plugin(LiveblogPlugin)
3 changes: 3 additions & 0 deletions djangocms_blog/liveblog/consumers.py
Expand Up @@ -26,3 +26,6 @@ def get_groups(self):
return [post.liveblog_group]
else:
return []

def send_json(self, content, close=False):
return super().send_json(content, close)
3 changes: 2 additions & 1 deletion djangocms_blog/liveblog/models.py
Expand Up @@ -78,7 +78,8 @@ def send(self, request):
"type": "send.json",
}
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(self.liveblog_group, notification)
group = self.liveblog_group
async_to_sync(channel_layer.group_send)(group, notification)


class Liveblog(LiveblogInterface, AbstractText):
Expand Down
2 changes: 1 addition & 1 deletion djangocms_blog/liveblog/routing.py
Expand Up @@ -3,4 +3,4 @@

from .consumers import LiveblogConsumer

channel_routing = URLRouter([path("<str:apphook>/<str:lang>/<str:post>/", LiveblogConsumer)])
channel_routing = URLRouter([path("<str:apphook>/<str:lang>/<str:post>/", LiveblogConsumer.as_asgi())])
Empty file.

0 comments on commit 8b83fad

Please sign in to comment.