Skip to content

Commit

Permalink
Merge pull request #262 from django-cms/feat/django-4-2-supprt
Browse files Browse the repository at this point in the history
feat: Django 4.2 support
  • Loading branch information
fsbraun authored Mar 16, 2024
2 parents ba0bed9 + 21e755a commit fcd5a0a
Show file tree
Hide file tree
Showing 60 changed files with 1,027 additions and 456 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
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9 ] # latest release minus two
python-version: [ "3.10", "3.11", "3.12" ] # latest release minus two
requirements-file: [
dj22_cms40.txt,
dj50_cms41.txt,
dj42_cms41.txt,
dj42_cms40.txt,
dj32_cms40.txt,
]
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.10.1
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: 0 additions & 2 deletions djangocms_moderation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
__version__ = "2.1.6"

default_app_config = "djangocms_moderation.apps.ModerationConfig"
95 changes: 57 additions & 38 deletions djangocms_moderation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from cms.toolbar.utils import get_object_preview_url
from cms.utils.helpers import is_editable_model

from adminsortable2.admin import SortableInlineAdminMixin
from adminsortable2.admin import SortableAdminMixin, SortableInlineAdminMixin
from treebeard.admin import TreeAdmin

from . import constants, signals
Expand Down Expand Up @@ -73,12 +73,16 @@ def has_add_permission(self, request):
def has_delete_permission(self, request, obj=None):
return False

@admin.display(
description=_("Status")
)
def show_user(self, obj):
_name = obj.get_by_user_name()
return gettext("By {user}").format(user=_name)

show_user.short_description = _("Status")

@admin.display(
description=_("Form Submission")
)
def form_submission(self, obj):
instance = get_form_submission_for_step(
obj.moderation_request, obj.step_approved
Expand All @@ -89,15 +93,13 @@ 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(
'<a href="{}" target="_blank">{}</a>', url, obj.step_approved.role.name
)

form_submission.short_description = _("Form Submission")

def get_readonly_fields(self, request, obj=None):
if obj.user_can_moderate(request.user) or obj.user_is_author(request.user):
# Omit 'message' from readonly_fields when current user is a reviewer
Expand All @@ -107,6 +109,7 @@ def get_readonly_fields(self, request, obj=None):
return self.fields


@admin.register(ModerationRequestTreeNode)
class ModerationRequestTreeAdmin(TreeAdmin):
"""
This admin is purely for the change list of Moderation Requests using the treebeard nodes to
Expand Down Expand Up @@ -177,15 +180,16 @@ def get_list_display(self, request):
]
return list_display

@admin.display(
description=_("actions")
)
def list_display_actions(self, obj):
"""Display links to state change endpoints
"""
return format_html_join(
"", "{}", ((action(obj),) for action in self.get_list_display_actions())
)

list_display_actions.short_description = _("actions")

def get_list_display_actions(self):
actions = []
if conf.REQUEST_COMMENTS_ENABLED:
Expand All @@ -210,6 +214,9 @@ def _get_configured_fields(self, request):

return fields

@admin.display(
description=_('ID')
)
def get_id(self, obj):
return format_html(
'<a href="{url}">{id}</a>',
Expand All @@ -219,22 +226,30 @@ def get_id(self, obj):
),
id=obj.moderation_request_id,
)
get_id.short_description = _('ID')

@admin.display(
description=_('Content type')
)
def get_content_type(self, obj):
return ContentType.objects.get_for_model(
obj.moderation_request.version.versionable.grouper_model
)
get_content_type.short_description = _('Content type')

@admin.display(
description=_('Title')
)
def get_title(self, obj):
return obj.moderation_request.version.content
get_title.short_description = _('Title')

@admin.display(
description=_('Author')
)
def get_version_author(self, obj):
return obj.moderation_request.version.created_by
get_version_author.short_description = _('Author')

@admin.display(
description=_("Preview")
)
def get_preview_link(self, obj):
content = obj.moderation_request.version.content
if is_editable_model(content.__class__):
Expand All @@ -254,8 +269,9 @@ def get_preview_link(self, obj):
object_preview_url,
)

get_preview_link.short_description = _("Preview")

@admin.display(
description=_('Reviewer')
)
def get_reviewer(self, obj):
last_action = obj.moderation_request.get_last_action()
if not last_action:
Expand All @@ -264,7 +280,6 @@ def get_reviewer(self, obj):
next_step = obj.moderation_request.get_next_required()
return next_step.role.name
return last_action._get_user_name(last_action.by_user)
get_reviewer.short_description = _('Reviewer')

def get_status(self, obj):
# We can have moderation requests without any action (e.g. the
Expand Down Expand Up @@ -466,6 +481,7 @@ def _traverse_moderation_nodes(node_item):
return HttpResponseRedirect(redirect_url)


@admin.register(ModerationRequest)
class ModerationRequestAdmin(admin.ModelAdmin):
class Media:
js = ('admin/js/jquery.init.js', 'djangocms_moderation/js/actions.js',)
Expand Down Expand Up @@ -813,11 +829,13 @@ def changelist_view(self, request, extra_context=None):
return tree_node_admin.changelist_view(request, extra_context)


@admin.register(Role)
class RoleAdmin(admin.ModelAdmin):
list_display = ["name", "user", "group", "confirmation_page"]
fields = ["name", "user", "group", "confirmation_page"]


@admin.register(CollectionComment)
class CollectionCommentAdmin(admin.ModelAdmin):
list_display = ["date_created", "message", "author"]
fields = ["collection", "message", "author"]
Expand Down Expand Up @@ -900,18 +918,20 @@ def get_readonly_fields(self, request, obj=None):
return self.list_display


@admin.register(RequestComment)
class RequestCommentAdmin(admin.ModelAdmin):
list_display = ["date_created", "message", "get_author"]
fields = ["moderation_request", "message", "author"]

class Media:
css = {"all": ("djangocms_moderation/css/comments_changelist.css",)}

@admin.display(
description=_("User")
)
def get_author(self, obj):
return obj.author_name

get_author.short_description = _("User")

def get_changeform_initial_data(self, request):
data = {"author": request.user}
moderation_request_id = utils.extract_filter_param_from_changelist_url(
Expand Down Expand Up @@ -990,7 +1010,8 @@ def get_extra(self, request, obj=None, **kwargs):
return 1


class WorkflowAdmin(admin.ModelAdmin):
@admin.register(Workflow)
class WorkflowAdmin(SortableAdminMixin, admin.ModelAdmin):
inlines = [WorkflowStepInline]
list_display = ["name", "is_default"]
fields = [
Expand All @@ -1002,6 +1023,7 @@ class WorkflowAdmin(admin.ModelAdmin):
]


@admin.register(ModerationCollection)
class ModerationCollectionAdmin(admin.ModelAdmin):
class Media:
js = ("admin/js/jquery.init.js", "djangocms_moderation/js/actions.js",)
Expand Down Expand Up @@ -1033,20 +1055,23 @@ def get_list_display(self, request):
def job_id(self, obj):
return obj.pk

@admin.display(
description=_('reviewers')
)
def commaseparated_reviewers(self, obj):
reviewers = self.model.objects.reviewers(obj)
return ", ".join(map(get_user_model().get_full_name, reviewers))
commaseparated_reviewers.short_description = _('reviewers')

@admin.display(
description=_("actions")
)
def list_display_actions(self, obj):
"""Display links to state change endpoints
"""
return format_html_join(
"", "{}", ((action(obj),) for action in self.get_list_display_actions())
)

list_display_actions.short_description = _("actions")

def get_list_display_actions(self):
actions = [self.get_edit_link, self.get_requests_link]
if conf.COLLECTION_COMMENTS_ENABLED:
Expand Down Expand Up @@ -1136,6 +1161,7 @@ def has_delete_permission(self, request, obj=None):
return False


@admin.register(ConfirmationPage)
class ConfirmationPageAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
view_on_site = True

Expand All @@ -1153,6 +1179,7 @@ def _url(regex, fn, name, **kwargs):
return url_patterns + super().get_urls()


@admin.register(ConfirmationFormSubmission)
class ConfirmationFormSubmissionAdmin(admin.ModelAdmin):
list_display = ["moderation_request", "for_step", "submitted_at"]
fields = [
Expand All @@ -1178,16 +1205,21 @@ def change_view(self, request, object_id, form_url="", extra_context=None):
request, object_id, form_url, extra_context=extra_context
)

@admin.display(
description=_("Request")
)
def moderation_request(self, obj):
return obj.moderation_request_id

moderation_request.short_description = _("Request")

@admin.display(
description=_("By User")
)
def show_user(self, obj):
return obj.get_by_user_name()

show_user.short_description = _("By User")

@admin.display(
description=_("Form Data")
)
def form_data(self, obj):
data = obj.get_form_data()
return format_html_join(
Expand All @@ -1198,16 +1230,3 @@ def form_data(self, obj):
for d in data
),
)

form_data.short_description = _("Form Data")


admin.site.register(ModerationRequestTreeNode, ModerationRequestTreeAdmin)
admin.site.register(ModerationRequest, ModerationRequestAdmin)
admin.site.register(CollectionComment, CollectionCommentAdmin)
admin.site.register(RequestComment, RequestCommentAdmin)
admin.site.register(ModerationCollection, ModerationCollectionAdmin)
admin.site.register(Role, RoleAdmin)
admin.site.register(Workflow, WorkflowAdmin)
admin.site.register(ConfirmationPage, ConfirmationPageAdmin)
admin.site.register(ConfirmationFormSubmission, ConfirmationFormSubmissionAdmin)
4 changes: 2 additions & 2 deletions djangocms_moderation/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ def add_items_to_collection(modeladmin, request, queryset):
args=(),
),
version_ids=",".join(version_ids),
return_to_url=request.META.get("HTTP_REFERER", ""),
return_to_url=request.headers.get("referer", ""),
)
return HttpResponseRedirect(admin_url)
else:
modeladmin.message_user(
request, _("No suitable items found to add to moderation collection")
)
return HttpResponseRedirect(request.META.get("HTTP_REFERER", ""))
return HttpResponseRedirect(request.headers.get("referer", ""))


add_items_to_collection.short_description = _("Add to moderation collection")
Expand Down
Loading

0 comments on commit fcd5a0a

Please sign in to comment.