Skip to content

Commit

Permalink
add alias edit btn
Browse files Browse the repository at this point in the history
  • Loading branch information
FreemanPancake committed Oct 25, 2024
1 parent c3a2d27 commit abbad0d
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions djangocms_version_locking/monkeypatch/djangocms_alias/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from django.contrib import admin
from django.http import HttpRequest
from django.urls import reverse
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.constants import DRAFT, PUBLISHED
from djangocms_versioning.helpers import (
get_latest_admin_viewable_content,
proxy_model,
version_list_url,
)

Expand All @@ -14,8 +17,10 @@ class AliasAdmin(OriginalAliasAdmin):
def get_actions_list(self) -> list:
"""Add alias 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_manage_versions_link)
settings_link_index = original_list.index(self._get_settings_action)
preview_link_index = original_list.index(self._get_view_action)
original_list.insert(settings_link_index, self._get_manage_versions_link)
original_list.insert(preview_link_index+1, self._get_edit_link)
return original_list

def _get_content_obj(self, obj: Alias):
Expand All @@ -26,6 +31,40 @@ def _get_content_obj(self, obj: Alias):
else: # Content Model
content_obj = obj
return content_obj

Check warning on line 34 in djangocms_version_locking/monkeypatch/djangocms_alias/admin.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
def _get_edit_link(self, obj: Alias, request: HttpRequest, disabled: bool =False):

Check failure on line 35 in djangocms_version_locking/monkeypatch/djangocms_alias/admin.py

View workflow job for this annotation

GitHub Actions / flake8

missing whitespace around parameter equals
version = proxy_model(self._get_content_obj(obj).versions.all()[0], self._get_content_obj(obj))

if version.state not in (DRAFT, PUBLISHED):
# Don't display the link if it can't be edited
return ""
if not version.check_edit_redirect.as_bool(request.user):
disabled = True

if version.state == PUBLISHED:
icon = "edit-new"
title = "New Draft"
else:
icon = "pencil"
title = "Edit"

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=icon,
title=_(title),
name="edit",
disabled=disabled,
action="post",
keepsideframe=False,
)

def _get_manage_versions_link(self, obj: Alias, request: HttpRequest, disabled: bool = False):
url = version_list_url(self._get_content_obj(obj))
Expand Down

0 comments on commit abbad0d

Please sign in to comment.