Skip to content

Commit

Permalink
Merge pull request #263 from joshyu/feat/django-4-2-supprt
Browse files Browse the repository at this point in the history
Feat/django 4 2 support  Bugfix
  • Loading branch information
fsbraun authored Mar 15, 2024
2 parents 9b3b505 + 3e6ffc0 commit 25d4477
Show file tree
Hide file tree
Showing 41 changed files with 373 additions and 249 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
os: [
ubuntu-20.04,
]
exclude:
- requirements-file: "dj42_cms40.txt"
python-version: "3.12" #cms40 not support py3.12 yet
- requirements-file: "dj32_cms40.txt"
python-version: "3.12"

steps:
- uses: actions/checkout@v4
Expand Down
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,42 @@ repos:
rev: v2.31.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
args: ["--py310-plus"]

- repo: https://github.com/adamchainz/django-upgrade
rev: '1.4.0'
hooks:
- id: django-upgrade
args: [--target-version, "2.2"]
args: [--target-version, "4.0"]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.5.0
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: mixed-line-ending
- id: trailing-whitespace

# upgrade the isort version to fix compatiable issue withe peotry: https://stackoverflow.com/questions/75269700/pre-commit-fails-to-install-isort-5-11-4-with-error-runtimeerror-the-poetry-co
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
exclude: >
(?x)^(
.*\.(js|po)
)$
2 changes: 1 addition & 1 deletion djangocms_moderation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def form_submission(self, obj):

opts = ConfirmationFormSubmission._meta
url = reverse(
"admin:{}_{}_change".format(opts.app_label, opts.model_name),
f"admin:{opts.app_label}_{opts.model_name}_change",
args=[instance.pk],
)
return format_html(
Expand Down
4 changes: 2 additions & 2 deletions djangocms_moderation/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class ModerationConfig(AppConfig):
verbose_name = _("django CMS Moderation")

def ready(self):
import djangocms_moderation.handlers # noqa: F401
import djangocms_moderation.monkeypatch # noqa: F401
import djangocms_moderation.handlers
import djangocms_moderation.monkeypatch
import djangocms_moderation.signals # noqa: F401
2 changes: 1 addition & 1 deletion djangocms_moderation/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def sequential_number_with_identifier_prefix_backend(**kwargs):
semi-sequential numbers, prefixed with `workflow.identifier` field, if set
"""
moderation_request = kwargs["moderation_request"]
return "{}{}".format(moderation_request.workflow.identifier, moderation_request.pk)
return f"{moderation_request.workflow.identifier}{moderation_request.pk}"
4 changes: 2 additions & 2 deletions djangocms_moderation/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _add_moderation_buttons(self):
opts = ModerationRequest._meta
codename = get_permission_codename("add", opts)
if not self.request.user.has_perm(
"{app_label}.{codename}".format(app_label=opts.app_label, codename=codename)
f"{opts.app_label}.{codename}"
):
return
version = Version.objects.get_for_content(self.toolbar.obj)
Expand All @@ -91,7 +91,7 @@ def _add_moderation_menu(self):
opts = ModerationCollection._meta
codename = get_permission_codename("change", opts)
if not self.request.user.has_perm(
"{app_label}.{codename}".format(app_label=opts.app_label, codename=codename)
f"{opts.app_label}.{codename}"
):
return
admin_menu = self.toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

CORE_COMPLIANCE_NUMBER_BACKENDS = (
(UUID_BACKEND, _("Unique alpha-numeric string")),
(UUID_BACKEND, _("Unique alphanumeric string")),
(SEQUENTIAL_NUMBER_BACKEND, _("Sequential number")),
(
SEQUENTIAL_NUMBER_WITH_IDENTIFIER_PREFIX_BACKEND,
Expand Down
4 changes: 2 additions & 2 deletions djangocms_moderation/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _send_email(
"job_id": collection.job_id,
"by_user": by_user,
}
template = "djangocms_moderation/emails/moderation-request/{}".format(template)
template = f"djangocms_moderation/emails/moderation-request/{template}"

# TODO What language should the email be sent in? e.g. `with force_language(lang):`
subject = force_str(subject)
Expand All @@ -61,7 +61,7 @@ def notify_collection_author(collection, moderation_requests, action, by_user):
moderation_requests=moderation_requests,
recipients=[collection.author.email],
subject=email_subjects[action],
template="{}.txt".format(action),
template=f"{action}.txt",
by_user=by_user,
)
return status
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def moderation_confirmation_form_submission(
sender, page, language, user, form_data, **kwargs
):
for field_data in form_data:
if not set(("label", "value")).issubset(field_data):
if not {"label", "value"}.issubset(field_data):
raise ValueError("Each field dict should contain label and value keys.")

# TODO Confirmation pages are not used/working in 1.0.x yet
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_active_moderation_request(content_object):
If this returns None, it means there is no active_moderation request for this
object, and it means it can be submitted for new moderation
"""
from djangocms_moderation.models import ModerationRequest # noqa
from djangocms_moderation.models import ModerationRequest

version = Version.objects.get_for_content(content_object)

Expand Down
10 changes: 5 additions & 5 deletions djangocms_moderation/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class Migration(migrations.Migration):
models.CharField(
blank=True,
default="",
help_text="Identifier is a 'free' field you could use for internal purposes. For example, it could be used as a workflow specific prefix of a compliance number",
help_text="Identifier is a 'free' field you could use for internal purposes. For example, it could be used as a workflow specific prefix of a compliance number", # noqa: E501
max_length=128,
verbose_name="identifier",
),
Expand All @@ -320,7 +320,7 @@ class Migration(migrations.Migration):
"requires_compliance_number",
models.BooleanField(
default=False,
help_text="Does the Compliance number need to be generated before the moderation request is approved? Please select the compliance number backend below",
help_text="Does the Compliance number need to be generated before the moderation request is approved? Please select the compliance number backend below", # noqa: E501
verbose_name="requires compliance number?",
),
),
Expand Down Expand Up @@ -454,14 +454,14 @@ class Migration(migrations.Migration):
),
),
migrations.AlterUniqueTogether(
name="workflowstep", unique_together=set([("role", "workflow")])
name="workflowstep", unique_together={("role", "workflow")}
),
migrations.AlterUniqueTogether(
name="moderationrequest",
unique_together=set([("collection", "object_id", "content_type")]),
unique_together={("collection", "object_id", "content_type")},
),
migrations.AlterUniqueTogether(
name="confirmationformsubmission",
unique_together=set([("request", "for_step")]),
unique_together={("request", "for_step")},
),
]
2 changes: 1 addition & 1 deletion djangocms_moderation/migrations/0003_auto_20180903_1206.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
preserve_default=False,
),
migrations.AlterUniqueTogether(
name="moderationrequest", unique_together=set([("collection", "version")])
name="moderationrequest", unique_together={("collection", "version")}
),
migrations.RemoveField(model_name="moderationrequest", name="content_type"),
migrations.RemoveField(model_name="moderationrequest", name="object_id"),
Expand Down
4 changes: 1 addition & 3 deletions djangocms_moderation/migrations/0011_auto_20181008_1328.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Generated by Django 1.11.13 on 2018-10-08 12:28
from django.conf import settings
from django.db import migrations
from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -13,7 +11,7 @@ class Migration(migrations.Migration):
# AlterUniqueTogether needs to happen before removing field
migrations.AlterUniqueTogether(
name="confirmationformsubmission",
unique_together=set([("moderation_request", "for_step")]),
unique_together={("moderation_request", "for_step")},
),
migrations.RemoveField(model_name="confirmationformsubmission", name="request"),
migrations.RemoveField(model_name="moderationrequestaction", name="request"),
Expand Down
7 changes: 6 additions & 1 deletion djangocms_moderation/migrations/0014_auto_20190315_1723.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterModelOptions(
name='moderationcollection',
options={'permissions': (('can_change_author', 'Can change collection author'), ('cancel_moderationcollection', 'Can cancel collection')), 'verbose_name': 'collection'},
options={'permissions': (
('can_change_author', 'Can change collection author'),
('cancel_moderationcollection', 'Can cancel collection')
),
'verbose_name': 'collection'
},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class Migration(migrations.Migration):
('path', models.CharField(max_length=255, unique=True)),
('depth', models.PositiveIntegerField()),
('numchild', models.PositiveIntegerField(default=0)),
('moderation_request', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djangocms_moderation.ModerationRequest', verbose_name='moderation_request')),
('moderation_request', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to='djangocms_moderation.ModerationRequest',
verbose_name='moderation_request')
), # noqa: E124
],
options={
'ordering': ('id',),
Expand Down
10 changes: 5 additions & 5 deletions djangocms_moderation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def __str__(self):

@property
def job_id(self):
return "{}".format(self.pk)
return f"{self.pk}"

@property
def author_name(self):
Expand Down Expand Up @@ -445,7 +445,7 @@ class Meta:
ordering = ["id"]

def __str__(self):
return "{} {}".format(self.pk, self.version_id)
return f"{self.pk} {self.version_id}"

@cached_property
def workflow(self):
Expand Down Expand Up @@ -652,7 +652,7 @@ class Meta:
verbose_name_plural = _("Actions")

def __str__(self):
return "{} - {}".format(self.moderation_request_id, self.get_action_display())
return f"{self.moderation_request_id} - {self.get_action_display()}"

def get_by_user_name(self):
if not self.to_user:
Expand Down Expand Up @@ -687,7 +687,7 @@ def save(self, **kwargs):

if next_step:
self.to_role_id = next_step.role_id
super(ModerationRequestAction, self).save(**kwargs)
super().save(**kwargs)


class AbstractComment(models.Model):
Expand Down Expand Up @@ -744,7 +744,7 @@ class ConfirmationFormSubmission(models.Model):
)

def __str__(self):
return "{} - {}".format(self.request_id, self.for_step)
return f"{self.request_id} - {self.for_step}"

class Meta:
verbose_name = _("Confirmation Form Submission")
Expand Down
10 changes: 5 additions & 5 deletions djangocms_moderation/static/djangocms_moderation/css/actions.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ a.btn.cms-moderation-action-btn span {
display: inline-block;
}
span.svg-juxtaposed-font {
text-rendering: auto;
display: inline-block;
line-height: 1rem;
vertical-align: 20%;
margin-top: -2px !important;
text-rendering: auto;
display: inline-block;
line-height: 1rem;
vertical-align: 20%;
margin-top: -2px !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ var diffview = {
var botrows = [];

for (var i = 0; i < rowcnt; i++) {
// jump ahead if we've alredy provided leading context or if this is the first range
// jump ahead if we've already provided leading context or if this is the first range
if (
contextSize &&
opcodes.length > 1 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

{% block post_content %}{% endblock %}
</div>

{% render_block "js" %}
{% block extrajs %}{% endblock %}
</body>
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_absolute_url(location, site=None):
scheme = "https"
else:
scheme = "http"
domain = "{}://{}".format(scheme, site.domain)
domain = f"{scheme}://{site.domain}"
return urljoin(domain, location)


Expand Down
2 changes: 1 addition & 1 deletion docs/comment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Comment
================================================
Comments may be added to various moderation entities:
Comments may be added to various moderation entities:
* :ref:`moderation_collection`
* :ref:`moderation_request`
* :ref:`moderation_request_action`
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down
6 changes: 3 additions & 3 deletions docs/lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Moderation Review Lock
================================================
As soon as a :ref:`moderation_collection` status becomes in review then its drafts are automatically locked, in the sense that their content can no longer be edited (not at all, not by anyone, not even the collection author). Also once a collection is in Review then content versions cannot be added to the collection. This means that once you’ve clicked “Submit for review”:
As soon as a :ref:`moderation_collection` status becomes in review then its drafts are automatically locked, in the sense that their content can no longer be edited (not at all, not by anyone, not even the collection author). Also once a collection is in Review then content versions cannot be added to the collection. This means that once you’ve clicked “Submit for review”:
* Collection Lock: New drafts cannot be added to the :ref:`moderation_collection`
* Version Lock: Drafts in the :ref:`moderation_collection` cannot be edited unless rejected
Once a version is published the Moderation Version Lock is removed automatically.

Once a version is published the Moderation Version Lock is removed automatically.
Loading

0 comments on commit 25d4477

Please sign in to comment.