-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Log operations #6419
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
Log operations #6419
Changes from 1 commit
c393d73
8309bac
3365d4f
e18af96
41af0c5
8ca4740
e39fbb5
d7677df
721948e
d92ba32
8b79b72
27bb832
2c0df27
801a901
32a91db
322181d
467ea74
b0d90be
84c6aa5
6ccfb02
d707ce8
c5c032d
9bd9902
ccc6354
e741e04
e723bd1
81f9024
9f0a770
6030a71
b82416d
8bed9d0
c192dce
89b0249
4e4d331
b57802c
3b4e002
4bf6ce9
153a60b
2c0a1c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,11 @@ | |
from cms.models import (CMSPlugin, Page, PageType, PagePermission, PageUser, PageUserGroup, Title, | ||
Placeholder, GlobalPagePermission, TreeNode) | ||
from cms.models.permissionmodels import User | ||
from cms.operations import ( | ||
helpers as operation_helpers, | ||
ADD_PAGE_TRANSLATION, | ||
CHANGE_PAGE_TRANSLATION, | ||
) | ||
from cms.plugin_pool import plugin_pool | ||
from cms.signals.apphook import set_restart_trigger | ||
from cms.utils.conf import get_cms_setting | ||
|
@@ -261,6 +266,12 @@ def save(self, *args, **kwargs): | |
source = self.cleaned_data.get('source') | ||
parent = self.cleaned_data.get('parent_node') | ||
|
||
operation_token = operation_helpers.send_pre_page_operation( | ||
request=self.request, | ||
sender=self.model, | ||
operation=ADD_PAGE_TRANSLATION, | ||
) | ||
|
||
if source: | ||
new_page = self.from_source(source, parent=parent) | ||
|
||
|
@@ -294,6 +305,14 @@ def save(self, *args, **kwargs): | |
# its the first page. publish it right away | ||
new_page.publish(translation.language) | ||
new_page.set_as_homepage(self._user) | ||
|
||
operation_helpers.send_post_page_operation( | ||
request=self.request, | ||
sender=self.model, | ||
operation=ADD_PAGE_TRANSLATION, | ||
token=operation_token, | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
return new_page | ||
|
||
|
||
|
@@ -443,6 +462,13 @@ def clean(self): | |
return data | ||
|
||
def save(self, commit=True): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
operation_token = operation_helpers.send_pre_page_operation( | ||
request=self.request, | ||
sender=self.model, | ||
operation=CHANGE_PAGE_TRANSLATION | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
data = self.cleaned_data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move |
||
cms_page = super(ChangePageForm, self).save(commit=False) | ||
|
||
|
@@ -467,6 +493,14 @@ def save(self, commit=True): | |
else: | ||
cms_page._update_title_path_recursive(self._language) | ||
cms_page.clear_cache(menu=True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
operation_helpers.send_post_page_operation( | ||
request=self.request, | ||
sender=self.model, | ||
operation=CHANGE_PAGE_TRANSLATION, | ||
token=operation_token | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
return cms_page | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
import copy | ||
import json | ||
import sys | ||
import uuid | ||
|
||
|
||
import django | ||
from django.contrib.admin.helpers import AdminForm | ||
|
@@ -60,8 +58,8 @@ | |
Title, CMSPlugin, PagePermission, | ||
GlobalPagePermission, StaticPlaceholder, | ||
) | ||
from cms.operations.helpers import send_post_page_operation, send_pre_page_operation | ||
from cms.plugin_pool import plugin_pool | ||
from cms.signals import pre_obj_operation, post_obj_operation | ||
from cms.signals.apphook import set_restart_trigger | ||
from cms.toolbar_pool import toolbar_pool | ||
from cms.utils import permissions, get_current_site, get_language_from_request, copy_plugins | ||
|
@@ -76,6 +74,7 @@ | |
from cms.utils.conf import get_cms_setting | ||
from cms.utils.urlutils import admin_reverse | ||
|
||
|
||
require_POST = method_decorator(require_POST) | ||
|
||
|
||
|
@@ -212,22 +211,19 @@ def get_urls(self): | |
return url_patterns + super(BasePageAdmin, self).get_urls() | ||
|
||
def _send_pre_page_operation(self, request, operation, **kwargs): | ||
token = str(uuid.uuid4()) | ||
pre_obj_operation.send( | ||
sender=self.__class__, | ||
operation=operation, | ||
|
||
return send_pre_page_operation( | ||
request=request, | ||
token=token, | ||
**kwargs | ||
) | ||
return token | ||
operation=operation, | ||
sender=self.__class__, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change sender to self.model token = call_the_function(
arg1='test',
arg2='test',
etc..
)
return token There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. < 1356 form class="js-timeline-comment-minimize d-md-inline-block d-flex" data-turbo="false" action="/django-cms/django-cms/pull/6419/review_comment/198410932/minimize" accept-charset="UTF-8" method="post">I had initially tried self.model but it wasn't available for some reason. It's possible that one failed so I removed them all for consistency. I'll add them back and test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope that I've interpreted your comment correctly. I've removed the private class methods and just used the functions directly. This required changing a lot of the calls to fire a signal. |
||
**kwargs) | ||
|
||
def _send_post_page_operation(self, request, operation, token, **kwargs): | ||
post_obj_operation.send( | ||
sender=self.__class__, | ||
send_post_page_operation( | ||
operation=operation, | ||
request=request, | ||
token=token, | ||
sender=self.__class__, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change sender to self.model |
||
**kwargs | ||
) | ||
|
||
|
@@ -493,6 +489,7 @@ def delete_view(self, request, object_id, extra_context=None): | |
return self.render_delete_form(request, context) | ||
|
||
def delete_model(self, request, obj): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
operation_token = self._send_pre_page_operation( | ||
request, | ||
operation=operations.DELETE_PAGE, | ||
|
@@ -1613,11 +1610,7 @@ class Meta: | |
if not cancel_clicked and request.method == 'POST': | ||
form = PageTitleForm(instance=translation, data=request.POST) | ||
if form.is_valid(): | ||
|
||
|
||
form.save() | ||
|
||
|
||
saved_successfully = True | ||
else: | ||
form = PageTitleForm(instance=translation) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
import uuid | ||
|
||
from cms.models import Page | ||
from cms.signals import pre_obj_operation, post_obj_operation | ||
|
||
|
||
def send_pre_page_operation(request, sender, operation, obj=Page, **kwargs): | ||
token = str(uuid.uuid4()) | ||
pre_obj_operation.send( | ||
sender=sender, | ||
operation=operation, | ||
request=request, | ||
token=token, | ||
obj=obj, | ||
**kwargs | ||
) | ||
return token | ||
|
||
|
||
def send_post_page_operation(request, sender, operation, token, obj=Page, **kwargs): | ||
post_obj_operation.send( | ||
sender=sender, | ||
operation=operation, | ||
request=request, | ||
token=token, | ||
obj=obj, | ||
**kwargs | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest: