-
-
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 26 commits
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
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, | ||
) | ||
from cms.plugin_pool import plugin_pool | ||
from cms.signals.apphook import set_restart_trigger | ||
from cms.utils.conf import get_cms_setting | ||
|
@@ -36,6 +41,9 @@ | |
) | ||
from menus.menu_pool import menu_pool | ||
|
||
# FIXME: REMOVEME: | ||
from attrdict import AttrDict | ||
|
||
|
||
def get_permission_accessor(obj): | ||
User = get_user_model() | ||
|
@@ -131,6 +139,9 @@ class BasePageForm(forms.ModelForm): | |
help_text=_('A description of the page used by search engines.'), | ||
max_length=320) | ||
|
||
# FIXME: REMOVEME: Waiting for request to be passed through, temp hack for testing in the UI | ||
request = AttrDict({'user': {'pk': 1 }}) | ||
|
||
class Meta: | ||
model = Page | ||
fields = [] | ||
|
@@ -261,6 +272,11 @@ 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, | ||
operation=ADD_PAGE_TRANSLATION, | ||
) | ||
|
||
if source: | ||
new_page = self.from_source(source, parent=parent) | ||
|
||
|
@@ -294,6 +310,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, | ||
operation=ADD_PAGE_TRANSLATION, | ||
token=operation_token, | ||
obj=new_page, | ||
) | ||
|
||
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 +467,12 @@ 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, | ||
operation=CHANGE_PAGE, | ||
) | ||
|
||
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 +497,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, | ||
operation=CHANGE_PAGE, | ||
token=operation_token, | ||
obj=cms_page, | ||
) | ||
|
||
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,15 +3,13 @@ | |
import copy | ||
import json | ||
import sys | ||
import uuid | ||
|
||
|
||
import django | ||
from django.contrib.admin.helpers import AdminForm | ||
from django.conf import settings | ||
from django.conf.urls import url | ||
from django.contrib import admin, messages | ||
from django.contrib.admin.models import LogEntry, CHANGE | ||
from django.contrib.admin.models import LogEntry | ||
from django.contrib.admin.options import IS_POPUP_VAR | ||
from django.contrib.admin.utils import get_deleted_objects | ||
from django.contrib.contenttypes.models import ContentType | ||
|
@@ -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 | ||
|
@@ -120,6 +118,18 @@ class BasePageAdmin(PlaceholderAdminMixin, admin.ModelAdmin): | |
|
||
inlines = PERMISSION_ADMIN_INLINES | ||
|
||
def log_addition(self, request, object, object_repr): | ||
# Block the admin log for addition. A signal takes care of this! | ||
return | ||
|
||
def log_deletion(self, request, object, object_repr): | ||
# Block the admin log for deletion. A signal takes care of this! | ||
return | ||
|
||
def log_change(self, request, object, message): | ||
# Block the admin log for change. A signal takes care of this! | ||
return | ||
|
||
def get_admin_url(self, action, *args): | ||
url_name = "{}_{}_{}".format( | ||
self.opts.app_label, | ||
|
@@ -200,22 +210,18 @@ 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. 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 | ||
) | ||
|
||
|
@@ -900,6 +906,7 @@ def move_page(self, request, page_id, extra_context=None): | |
token=operation_token, | ||
obj=page, | ||
) | ||
|
||
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. no newline 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 jsonify_request(HttpResponse(status=200)) | ||
|
||
def get_permissions(self, request, page_id): | ||
|
@@ -1153,13 +1160,6 @@ def publish_page(self, request, page_id, language): | |
messages.warning(request, _("Page not published! A parent page is not published yet.")) | ||
else: | ||
messages.info(request, _('The content was successfully published.')) | ||
LogEntry.objects.log_action( | ||
user_id=request.user.id, | ||
content_type_id=ContentType.objects.get_for_model(Page).pk, | ||
object_id=page_id, | ||
object_repr=page.get_title(language), | ||
action_flag=CHANGE, | ||
) | ||
else: | ||
if page.get_publisher_state(language) == PUBLISHER_STATE_PENDING: | ||
messages.warning(request, _("Page not published! A parent page is not published yet.")) | ||
|
@@ -1222,14 +1222,7 @@ def unpublish(self, request, page_id, language): | |
message = _('The %(language)s page "%(page)s" was successfully unpublished') % { | ||
'language': language_name, 'page': page} | ||
messages.info(request, message) | ||
LogEntry.objects.log_action( | ||
user_id=request.user.id, | ||
content_type_id=ContentType.objects.get_for_model(Page).pk, | ||
object_id=page_id, | ||
object_repr=page.get_title(), | ||
action_flag=CHANGE, | ||
change_message=message, | ||
) | ||
|
||
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 |
||
except RuntimeError: | ||
exc = sys.exc_info()[1] | ||
messages.error(request, exc.message) | ||
|
@@ -1614,7 +1607,24 @@ class Meta: | |
if not cancel_clicked and request.method == 'POST': | ||
form = PageTitleForm(instance=translation, data=request.POST) | ||
if form.is_valid(): | ||
|
||
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.CHANGE_PAGE_TRANSLATION, | ||
obj=page, | ||
translation=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 |
||
form.save() | ||
|
||
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 |
||
self._send_post_page_operation( | ||
request, | ||
operation=operations.CHANGE_PAGE_TRANSLATION, | ||
token=operation_token, | ||
obj=page, | ||
translation=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 |
||
saved_successfully = True | ||
else: | ||
form = PageTitleForm(instance=translation) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- 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, operation, sender=Page, **kwargs): | ||
token = str(uuid.uuid4()) | ||
pre_obj_operation.send( | ||
sender=sender, | ||
operation=operation, | ||
request=request, | ||
token=token, | ||
**kwargs | ||
) | ||
return token | ||
|
||
|
||
def send_post_page_operation(request, operation, token, sender=Page, **kwargs): | ||
post_obj_operation.send( | ||
sender=sender, | ||
operation=operation, | ||
request=request, | ||
token=token, | ||
**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: