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: Django 4.2 support #262

Merged
merged 29 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd77632
Add django 4.2 support
fsbraun Mar 12, 2024
9916e64
Update test settings
fsbraun Mar 12, 2024
52eb8d5
More flake8 linting
fsbraun Mar 12, 2024
1685a78
Fix test for django CMS 4.0 toolbar
fsbraun Mar 12, 2024
2980c12
add django 5.0 for tests
fsbraun Mar 12, 2024
e313846
Add Django 4.2 plus CMS 4.0 for testing
fsbraun Mar 12, 2024
f3c31de
Update test dependencies
fsbraun Mar 12, 2024
56811e0
Undo tooling changes
fsbraun Mar 12, 2024
310c13d
fix: fix check errors
joshyu Mar 14, 2024
57ee74c
fix: test.yml
joshyu Mar 14, 2024
a2d1fa2
fix: test.yml 2
joshyu Mar 14, 2024
1c50da3
fix: update pre-commit-config versions
joshyu Mar 15, 2024
ec35312
fix: update code styles using pre-commit run
joshyu Mar 15, 2024
3a3dd39
fix: test_views.py
joshyu Mar 15, 2024
185b43a
fix: flake8 issue
joshyu Mar 15, 2024
2e4c97e
fix: pre-commit-config related errors
joshyu Mar 15, 2024
877085d
fix: pre-commit-config related errors
joshyu Mar 15, 2024
66dc28a
fix: typo
joshyu Mar 15, 2024
9b3b505
Fix isort precommit
fsbraun Mar 15, 2024
3e6ffc0
Merge branch 'feat/django-4-2-supprt' into feat/django-4-2-supprt
fsbraun Mar 15, 2024
25d4477
Merge pull request #263 from joshyu/feat/django-4-2-supprt
fsbraun Mar 15, 2024
b0b9fbb
feat: added issue template (#261)
raffaellasuardini Mar 12, 2024
1bb3c16
fix: Squash migrations to remove intermediate state with auto field =…
fsbraun Mar 12, 2024
47304d4
Reformat squashed migration
fsbraun Mar 15, 2024
f85afca
Merge branch 'master' into feat/django-4-2-supprt
fsbraun Mar 15, 2024
1872132
Fix codespell
fsbraun Mar 15, 2024
1585488
Adjust tests for version_locking in both django CMS 4.0 and 4.1
fsbraun Mar 15, 2024
88a68dd
Test adjustments for django CMS 4.0
fsbraun Mar 15, 2024
21e755a
Add tests that locked versions do not get included in collections
fsbraun Mar 15, 2024
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
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ 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: [
Expand Down
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"
93 changes: 56 additions & 37 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 @@ -96,8 +100,6 @@ def form_submission(self, obj):
'<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
Empty file.
Empty file.
32 changes: 0 additions & 32 deletions djangocms_moderation/contrib/moderation_forms/cms_plugins.py

This file was deleted.

This file was deleted.

Empty file.
10 changes: 0 additions & 10 deletions djangocms_moderation/contrib/moderation_forms/models.py

This file was deleted.

8 changes: 6 additions & 2 deletions djangocms_moderation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
User = get_user_model()

try:
from djangocms_version_locking.helpers import content_is_unlocked_for_user
from djangocms_versioning.helpers import content_is_unlocked_for_user
except ImportError:
content_is_unlocked_for_user = None
try:
# Before djangocms-versioning 2.0.0, version locking was in a separate package
from djangocms_version_locking.helpers import content_is_unlocked_for_user
except ImportError:
content_is_unlocked_for_user = None


def get_page_or_404(obj_id, language):
Expand Down
Loading
Loading