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

Feat: add django cms 4.1 support #57

Open
wants to merge 11 commits into
base: master
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
7 changes: 0 additions & 7 deletions .circleci/Dockerfile

This file was deleted.

135 changes: 0 additions & 135 deletions .circleci/config.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: django CMS References linters.yml

on: [pull_request, push]

jobs:
flake8:
name: flake8
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- run: pip install --upgrade flake8
- name: flake8
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: flake8
run: |
flake8
isort:
name: isort
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: isort
run: isort -c -rc -df ./

39 changes: 39 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: django CMS references test.yml

on: [pull_request, push]

jobs:
database-sqlite:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.8, 3.9, '3.10'] # latest release minus two
requirements-file: [
dj32_cms40.txt,
dj42_cms40.txt,
dj42_cms41.txt,
]
exclude:
- requirements-file: dj42_cms41.txt
python-version: 3.8

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt install gettext gcc -y
python -m pip install --upgrade pip
pip install pytest
pip install -r tests/requirements/${{ matrix.requirements-file }}
python setup.py install
- name: Test with python test runner
run: |
python setup.py test
env:
DATABASE_URL: sqlite://localhost/testdb.sqlite
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog

Unreleased
==========
* Django CMS 4.1 support added


1.5.0 (2024-05-16)
==================
Expand Down
12 changes: 12 additions & 0 deletions djangocms_references/compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from cms import __version__ as cms_version


try:
from packaging.version import Version
except ModuleNotFoundError:
from distutils.version import LooseVersion as Version


def is_versioning_installed():
try:
import djangocms_versioning # noqa: F401
Expand All @@ -7,4 +16,7 @@ def is_versioning_installed():
return True


DJANGO_CMS_4_1 = Version(cms_version) >= Version('4.1')


VERSIONING_INSTALLED = is_versioning_installed()
35 changes: 23 additions & 12 deletions djangocms_references/monkeypatch/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from djangocms_alias import admin as AliasOriginalAdmin
from djangocms_snippet import admin as SnippetOriginalAdmin

from djangocms_references.compat import DJANGO_CMS_4_1

def generate_get_references_link(content_grouper):

def generate_get_references_link(content_grouper=None):
def _get_references_link(self, obj, request):
obj_grouper = getattr(obj, content_grouper)
obj_grouper = obj if not content_grouper else getattr(obj, content_grouper)
_obj_grouper_meta = obj_grouper._meta
content_type = ContentType.objects.get(
app_label=_obj_grouper_meta.app_label,
Expand All @@ -24,7 +26,7 @@ def _get_references_link(self, obj, request):
return _get_references_link


def get_list_actions(func):
def _get_actions_list(func):
"""
Add references action to alias list display
"""
Expand All @@ -35,12 +37,21 @@ def inner(self, *args, **kwargs):
return inner


AliasOriginalAdmin.AliasContentAdmin._get_references_link = generate_get_references_link('alias')
AliasOriginalAdmin.AliasContentAdmin.get_list_actions = get_list_actions(
AliasOriginalAdmin.AliasContentAdmin.get_list_actions
)

SnippetOriginalAdmin.SnippetAdmin._get_references_link = generate_get_references_link('snippet_grouper')
SnippetOriginalAdmin.SnippetAdmin.get_list_actions = get_list_actions(
SnippetOriginalAdmin.SnippetAdmin.get_list_actions
)
if not DJANGO_CMS_4_1:
AliasOriginalAdmin.AliasContentAdmin._get_references_link = generate_get_references_link('alias')
AliasOriginalAdmin.AliasContentAdmin.get_list_actions = _get_actions_list(
AliasOriginalAdmin.AliasContentAdmin.get_list_actions
)

SnippetOriginalAdmin.SnippetAdmin._get_references_link = generate_get_references_link('snippet_grouper')
SnippetOriginalAdmin.SnippetAdmin.get_list_actions = _get_actions_list(
SnippetOriginalAdmin.SnippetAdmin.get_list_actions
)
else:
AliasOriginalAdmin.AliasAdmin._get_references_link = generate_get_references_link()
AliasOriginalAdmin.AliasAdmin.get_actions_list = _get_actions_list(AliasOriginalAdmin.AliasAdmin.get_actions_list)

SnippetOriginalAdmin.SnippetAdmin._get_references_link = generate_get_references_link('snippet_grouper')
SnippetOriginalAdmin.SnippetAdmin.get_actions_list = _get_actions_list(
SnippetOriginalAdmin.SnippetAdmin.get_actions_list
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
<style>
#changelist-form .results {
width: auto;
}
</style>
{% endblock %}

{% block extrahead %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{% load static i18n %}
<a class="btn cms-versioning-action-btn cms-form-get-method js-versioning-action" href="{{ url }}" title="{% trans "Show References" %}"><img src="{% static 'djangocms_references/svg/references.svg' %}"></a>
<a class="btn cms-action-btn cms-form-get-method js-action" href="{{ url }}" title="{% trans "Show References" %}">
<img src="{% static 'djangocms_references/svg/references.svg' %}" style="width: 16.8px; height: 16.8px; margin-right: unset;">
</a>
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% load i18n djangocms_references_tags %}

{% get_versioning_filer_references_url file as references_url %}
<a href="{{ references_url }}"
title="{% blocktrans %}Show references{% endblocktrans %}" class="action-button cms-form-get-method"><span class="fa fa-code-fork"></span></a>

<a href="{{ references_url }}" title="{% blocktrans %}Show references{% endblocktrans %}" class="action-button cms-form-get-method">
<span class="fa fa-link filer-icon filer-icon-reference">
<img src="{% static 'djangocms_references/svg/references.svg' %}">
</span>
</a>
2 changes: 2 additions & 0 deletions tests/requirements/dj32_cms40.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Django>=3.2,<4.0

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/django-cms/djangocms-snippet/tarball/support/django-cms-4.0.x#egg=djangocms-snippet
https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning
https://github.com/django-cms/djangocms-alias/tarball/1.11.0#egg=djangocms-alias
2 changes: 2 additions & 0 deletions tests/requirements/dj42_cms40.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

Django>=4.2,<5.0

https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/django-cms/djangocms-snippet/tarball/support/django-cms-4.0.x#egg=djangocms-snippet
https://github.com/django-cms/djangocms-versioning/tarball/support/django-cms-4.0.x#egg=djangocms-versioning
https://github.com/django-cms/djangocms-alias/tarball/support/django-cms-4.0.x#egg=djangocms-alias
8 changes: 8 additions & 0 deletions tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-r ./requirements_base.txt

Django>=4.2,<5.0
djangocms-versioning==2.1.0
django-cms>=4.1.0

https://github.com/django-cms/djangocms-snippet/tarball/master#egg=djangocms-snippet
https://github.com/django-cms/djangocms-alias/tarball/master#egg=djangocms-alias
3 changes: 0 additions & 3 deletions tests/requirements/requirements_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ factory-boy
flake8
isort
tox

https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/django-cms/djangocms-snippet/tarball/support/django-cms-4.0.x#egg=djangocms-snippet
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField",
"ROOT_URLCONF": "tests.urls",
"VERSIONING_ALIAS_MODELS_ENABLED": True,
}


Expand Down
Loading