Skip to content

Commit

Permalink
Register revert-to-live as page translation operation (#5838)
Browse files Browse the repository at this point in the history
  • Loading branch information
czpython committed Jan 6, 2017
1 parent 105fe2a commit 097fe82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
30 changes: 27 additions & 3 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,38 @@ def revert_to_live(self, request, page_id, language):
"""
Resets the draft version of the page to match the live one
"""
page = get_object_or_404(self.model, id=page_id)
page = get_object_or_404(
self.model,
pk=page_id,
publisher_is_draft=True,
title_set__language=language,
)

# ensure user has permissions to publish this page
if not self.has_revert_to_live_permission(request, language, obj=page):
return HttpResponseForbidden(force_text(_("You do not have permission to revert this page.")))

translation = page.get_title_obj(language=language)
operation_token = self._send_pre_page_operation(
request,
operation=operations.REVERT_PAGE_TRANSLATION_TO_LIVE,
obj=page,
translation=translation,
)

page.revert_to_live(language)

# Fetch updated translation
translation.refresh_from_db()

self._send_post_page_operation(
request,
operation=operations.REVERT_PAGE_TRANSLATION_TO_LIVE,
token=operation_token,
obj=page,
translation=translation,
)

messages.info(request, _('"%s" was reverted to the live version.') % page)

path = page.get_absolute_url(language=language)
Expand All @@ -933,9 +957,9 @@ def publish_page(self, request, page_id, language):

try:
page = Page.objects.get(
id=page_id,
title_set__language=language,
pk=page_id,
publisher_is_draft=True,
title_set__language=language,
)
except Page.DoesNotExist:
page = None
Expand Down
7 changes: 6 additions & 1 deletion cms/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
# Page translation operations
DELETE_PAGE_TRANSLATION = 'delete_page_translation'
PUBLISH_PAGE_TRANSLATION = 'publish_page_translation'
REVERT_PAGE_TRANSLATION_TO_LIVE = 'revert_page_translation_to_live'

# Static placeholder operations
PUBLISH_STATIC_PLACEHOLDER = 'publish_static_placeholder'

PAGE_OPERATIONS = [MOVE_PAGE, DELETE_PAGE]
PAGE_TRANSLATION_OPERATIONS = [DELETE_PAGE_TRANSLATION, PUBLISH_PAGE_TRANSLATION]
PAGE_TRANSLATION_OPERATIONS = [
DELETE_PAGE_TRANSLATION,
PUBLISH_PAGE_TRANSLATION,
REVERT_PAGE_TRANSLATION_TO_LIVE,
]
STATIC_PLACEHOLDER_OPERATIONS = [PUBLISH_STATIC_PLACEHOLDER]

0 comments on commit 097fe82

Please sign in to comment.