-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make state indicator readonly, and add more function to alias action …
…list
- Loading branch information
1 parent
6d9d4eb
commit 152e980
Showing
4 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
Check failure on line 1 in djangocms_version_locking/monkeypatch/admin.py GitHub Actions / flake8
|
||
|
||
from django.template.loader import render_to_string | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from djangocms_versioning.admin import StateIndicatorMixin | ||
from djangocms_versioning.constants import INDICATOR_DESCRIPTIONS | ||
from djangocms_versioning.indicators import content_indicator, content_indicator_menu | ||
from djangocms_versioning.helpers import get_latest_admin_viewable_content | ||
|
||
def _get_indicator_column(func): | ||
''' | ||
Change the State Indicator to readonly, publish process will be take over by djangocms-moderation. | ||
''' | ||
def inner(self, request): | ||
def indicator(obj): | ||
if self._extra_grouping_fields is not None: # Grouper Model | ||
content_obj = get_latest_admin_viewable_content(obj, include_unpublished_archived=True, **{ | ||
field: getattr(self, field) for field in self._extra_grouping_fields | ||
}) | ||
else: # Content Model | ||
content_obj = obj | ||
status = content_indicator(content_obj) | ||
return render_to_string( | ||
"admin/djangocms_versioning/indicator.html", | ||
{ | ||
"state": status or "empty", | ||
"description": INDICATOR_DESCRIPTIONS.get(status, _("Empty")), | ||
"menu_template": "admin/cms/page/tree/indicator_menu.html", | ||
} | ||
) | ||
indicator.short_description = self.indicator_column_label | ||
return indicator | ||
return inner | ||
|
||
|
||
StateIndicatorMixin.get_indicator_column = _get_indicator_column(StateIndicatorMixin.get_indicator_column) |
Empty file.
67 changes: 67 additions & 0 deletions
67
djangocms_version_locking/monkeypatch/djangocms_alias/admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.contrib import admin | ||
from django.urls import reverse | ||
from django.http import HttpRequest | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from djangocms_alias.admin import AliasAdmin as OriginalAliasAdmin | ||
from djangocms_alias.models import Alias | ||
from djangocms_versioning.helpers import get_latest_admin_viewable_content, proxy_model, version_list_url | ||
|
||
|
||
class AliasAdmin(OriginalAliasAdmin): | ||
def get_actions_list(self) -> list: | ||
"""Add alias edit link, manage version link""" | ||
original_list = super().get_actions_list() | ||
usage_link_index = original_list.index(self._get_alias_usage_link) | ||
original_list.insert(usage_link_index-1, self._get_edit_link) | ||
original_list.insert(usage_link_index-1, self._get_manage_versions_link) | ||
|
||
|
||
def _get_content_obj(self, obj: Alias): | ||
if self._extra_grouping_fields is not None: # Grouper Model | ||
content_obj = get_latest_admin_viewable_content(obj, include_unpublished_archived=True, **{ | ||
field: getattr(self, field) for field in self._extra_grouping_fields | ||
}) | ||
else: # Content Model | ||
content_obj = obj | ||
return content_obj | ||
|
||
def _get_manage_versions_link(self, obj: Alias, request: HttpRequest, disabled: bool = False): | ||
url = version_list_url(self._get_content_obj(obj)) | ||
return self.admin_action_button( | ||
url, | ||
icon="copy", | ||
title=_("Manage versions"), | ||
name="manage-versions", | ||
disabled=disabled, | ||
) | ||
|
||
def _get_edit_link(self, obj: Alias, request: HttpRequest, disabled: bool = False): | ||
version = proxy_model(obj, self._get_content_obj(obj)) | ||
# if not version.check_edit_redirect.as_bool(request.user): | ||
# # Don't display the link if it can't be edited | ||
# return "" | ||
if not version.check_edit_redirect.as_bool(request.user): | ||
disabled = True | ||
|
||
url = reverse( | ||
"admin:{app}_{model}_edit_redirect".format( | ||
app=version._meta.app_label, model=version._meta.model_name | ||
), | ||
args=(version.pk,), | ||
) | ||
|
||
# close sideframe as edit will always be on page and not in sideframe | ||
return self.admin_action_button( | ||
url=url, | ||
icon="pencil", | ||
title=_("Edit"), | ||
name="edit", | ||
disabled=disabled, | ||
action="post", | ||
keepsideframe=False, | ||
) | ||
|
||
|
||
admin.site.unregister(Alias) | ||
admin.site.register(Alias, AliasAdmin) |