Skip to content

Commit

Permalink
Add django 4.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Mar 12, 2024
1 parent e303bab commit fd77632
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 181 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9 ] # latest release minus two
python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two
requirements-file: [
dj22_cms40.txt,
dj42_cms41.txt,
dj32_cms40.txt,
]
os: [
Expand Down
1 change: 0 additions & 1 deletion djangocms_moderation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
__version__ = "2.1.6"

Check warning on line 2 in djangocms_moderation/__init__.py

View workflow job for this annotation

GitHub Actions / flake8

blank line at end of file
default_app_config = "djangocms_moderation.apps.ModerationConfig"
82 changes: 56 additions & 26 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 SortableInlineAdminMixin, SortableAdminMixin
from treebeard.admin import TreeAdmin

from . import constants, signals
Expand Down Expand Up @@ -73,12 +73,17 @@ 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(

Check failure on line 84 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
description=_("Form Submission")
)
def form_submission(self, obj):
instance = get_form_submission_for_step(
obj.moderation_request, obj.step_approved
Expand All @@ -96,7 +101,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):

Check failure on line 105 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
if obj.user_can_moderate(request.user) or obj.user_is_author(request.user):
Expand All @@ -107,6 +111,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,14 +182,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):

Check failure on line 196 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
actions = []
Expand All @@ -210,6 +217,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 +229,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 +272,10 @@ def get_preview_link(self, obj):
object_preview_url,
)

get_preview_link.short_description = _("Preview")

@admin.display(

Check failure on line 276 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
description=_('Reviewer')
)
def get_reviewer(self, obj):
last_action = obj.moderation_request.get_last_action()
if not last_action:
Expand All @@ -264,7 +284,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 +485,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 +833,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,17 +922,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):

Check failure on line 940 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
data = {"author": request.user}
Expand Down Expand Up @@ -990,7 +1015,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 +1028,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,19 +1060,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):

Check failure on line 1081 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
actions = [self.get_edit_link, self.get_requests_link]
Expand Down Expand Up @@ -1136,6 +1167,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 +1185,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 +1211,23 @@ 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(

Check failure on line 1221 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
description=_("By User")
)
def show_user(self, obj):
return obj.get_by_user_name()

show_user.short_description = _("By User")

@admin.display(

Check failure on line 1228 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

too many blank lines (2)
description=_("Form Data")
)
def form_data(self, obj):
data = obj.get_form_data()
return format_html_join(
Expand All @@ -1199,15 +1239,5 @@ def form_data(self, obj):
),
)

form_data.short_description = _("Form Data")


Check warning on line 1243 in djangocms_moderation/admin.py

View workflow job for this annotation

GitHub Actions / flake8

blank line at end of file
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
1 change: 1 addition & 0 deletions djangocms_moderation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Workflow(models.Model):
class Meta:
verbose_name = _("Workflow")
verbose_name_plural = _("Workflows")
ordering = ("name",)

def __str__(self):
return self.name
Expand Down
Loading

0 comments on commit fd77632

Please sign in to comment.