Permalink
Browse files

signal refactor, permission bugs, multilingual decode error fix

  • Loading branch information...
1 parent 2ceb7c1 commit 31ff505b1bd8e737b09284e54e12a30b2c4efab6 @digi604 digi604 committed Dec 3, 2009
Showing with 87 additions and 25 deletions.
  1. +5 −4 cms/appresolver.py
  2. +6 −2 cms/middleware/multilingual.py
  3. +0 −1 cms/models/__init__.py
  4. +3 −1 cms/models/pagemodel.py
  5. +0 −11 cms/models/signals.py
  6. +73 −6 cms/signals.py
View
@@ -1,15 +1,15 @@
from django.conf import settings
from django.core.urlresolvers import RegexURLResolver, Resolver404, reverse
-from cms.utils.moderator import get_page_queryset
-from cms.models import Title
-from cms.models.pagemodel import Page
+
+
from cms.exceptions import NoHomeFound
from django.contrib.sites.models import Site
def applications_page_check(request, current_page=None, path=None):
"""Tries to find if given path was resolved over application.
Applications have higher priority than other cms pages.
"""
+ from cms.utils.moderator import get_page_queryset
if current_page:
return current_page
if path is None:
@@ -127,7 +127,8 @@ def urlpatterns(self):
Caches result, so db lookup is required only once, or when the cache
is reseted.
"""
-
+ from cms.models import Title
+ from cms.models.pagemodel import Page
if not self._urlpatterns:
# TODO: will this work with multiple sites? how are they exactly
# implemented ?
@@ -72,8 +72,12 @@ def process_response(self, request, response):
not path.startswith(settings.ADMIN_MEDIA_PREFIX) and \
response.status_code == 200 and \
response._headers['content-type'][1].split(';')[0] == "text/html":
- response.content = SUB.sub(ur'<a\1href="/%s/\3"\4>' % request.LANGUAGE_CODE, response.content.decode('utf-8'))
- response.content = SUB2.sub(ur'<form\1action="/%s/\3"\4>' % request.LANGUAGE_CODE, response.content.decode('utf-8'))
+ try:
+ decoded_response = response.content.decode('utf-8')
+ except UnicodeDecodeError:
+ decoded_response = response.content
+ response.content = SUB.sub(ur'<a\1href="/%s/\3"\4>' % request.LANGUAGE_CODE, decoded_response)
+ response.content = SUB2.sub(ur'<form\1action="/%s/\3"\4>' % request.LANGUAGE_CODE, decoded_response)
if (response.status_code == 301 or response.status_code == 302 ):
location = response._headers['location']
prefix = has_lang_prefix(location[1])
View
@@ -5,7 +5,6 @@
from titlemodels import *
from django.core.exceptions import ImproperlyConfigured
-from cms.models import signals
from cms import signals as s_import
from cms import plugin_pool
View
@@ -12,7 +12,7 @@
from publisher.errors import PublisherCantPublish
from cms.utils.urlutils import urljoin
from cms.models.managers import PageManager, PagePermissionsPermissionManager
-from cms.models import signals as cms_signals
+
from cms.utils.page import get_available_slug, check_title_slugs
from cms.exceptions import NoHomeFound
from cms.utils.helpers import reversion_register
@@ -91,6 +91,7 @@ def move_page(self, target, position='first-child'):
# fire signal
from cms.models.moderatormodels import PageModeratorState
self.force_moderation_action = PageModeratorState.ACTION_MOVE
+ import cms.signals as cms_signals
cms_signals.page_moved.send(sender=Page, instance=self) #titles get saved before moderation
self.save(change_state=True) # always save the page after move, because of publisher
@@ -663,6 +664,7 @@ def publish(self):
page.publish()
# fire signal after publishing is done
+ import cms.signals as cms_signals
cms_signals.post_publish.send(sender=Page, instance=self)
return published
View
@@ -1,11 +0,0 @@
-from django.dispatch import Signal
-
-# fired after page location is changed - is moved from one node to other
-page_moved = Signal(providing_args=["instance"])
-
-# fired when some of nodes (Title) with applications gets saved
-application_post_changed = Signal(providing_args=["instance"])
-
-# fired after page gets published - copied to public model - there may be more
-# than one instances published before this signal gets called
-post_publish = Signal(providing_args=["instance"])
View
@@ -1,11 +1,21 @@
from django.db.models import signals
from django.conf import settings
from cms import appresolver
-from cms.models import signals as cms_signals, Page, Title
+from cms.models import Page, Title
from cms.models import CMSPlugin
from cms.utils.moderator import page_changed
from django.core.exceptions import ObjectDoesNotExist
+from django.dispatch import Signal
+# fired after page location is changed - is moved from one node to other
+page_moved = Signal(providing_args=["instance"])
+
+# fired when some of nodes (Title) with applications gets saved
+application_post_changed = Signal(providing_args=["instance"])
+
+# fired after page gets published - copied to public model - there may be more
+# than one instances published before this signal gets called
+post_publish = Signal(providing_args=["instance"])
def update_plugin_positions(**kwargs):
plugin = kwargs['instance']
@@ -26,7 +36,7 @@ def update_title_paths(instance, **kwargs):
for title in instance.title_set.all():
title.save()
-cms_signals.page_moved.connect(update_title_paths, sender=Page, dispatch_uid="cms.title.update_path")
+page_moved.connect(update_title_paths, sender=Page, dispatch_uid="cms.title.update_path")
def pre_save_title(instance, raw, **kwargs):
@@ -81,7 +91,7 @@ def post_save_title(instance, raw, created, **kwargs):
if not hasattr(instance, 'tmp_prevent_descendant_update') and \
(instance.application_urls != getattr(instance, 'tmp_application_urls', None) or application_changed):
# fire it if we have some application linked to this page or some descendant
- cms_signals.application_post_changed.send(sender=Title, instance=instance)
+ application_post_changed.send(sender=Title, instance=instance)
# remove temporary attributes
if getattr( instance, 'tmp_path', None):
@@ -104,7 +114,7 @@ def clear_appresolver_cache(instance, **kwargs):
if settings.CMS_APPLICATIONS_URLS:
# register this signal only if we have some hookable applications
- cms_signals.application_post_changed.connect(clear_appresolver_cache, sender=Title, dispatch_uid="cms.title.appchanged")
+ application_post_changed.connect(clear_appresolver_cache, sender=Title, dispatch_uid="cms.title.appchanged")
def post_save_user(instance, raw, created, **kwargs):
@@ -201,5 +211,62 @@ def post_save_page(instance, raw, created, **kwargs):
signals.pre_save.connect(pre_save_page, sender=Page, dispatch_uid="cms.page.presave")
signals.post_save.connect(post_save_page, sender=Page, dispatch_uid="cms.page.postsave")
-
-from cache import signals
+
+from cms.models import PagePermission, GlobalPagePermission
+from cms.cache.permissions import clear_user_permission_cache,\
+ clear_permission_cache
+
+
+def pre_save_user(instance, raw, **kwargs):
+ clear_user_permission_cache(instance)
+
+def pre_delete_user(instance, **kwargs):
+ clear_user_permission_cache(instance)
+
+def pre_save_group(instance, raw, **kwargs):
+ if instance.pk:
+ for user in instance.user_set.filter(is_staff=True):
+ clear_user_permission_cache(user)
+
+def pre_delete_group(instance, **kwargs):
+ for user in instance.user_set.filter(is_staff=True):
+ clear_user_permission_cache(user)
+
+def pre_save_pagepermission(instance, raw, **kwargs):
+ if instance.user:
+ clear_user_permission_cache(instance.user)
+
+def pre_delete_pagepermission(instance, **kwargs):
+ if instance.user:
+ clear_user_permission_cache(instance.user)
+
+def pre_save_globalpagepermission(instance, raw, **kwargs):
+ if instance.user:
+ clear_user_permission_cache(instance.user)
+
+def pre_delete_globalpagepermission(instance, **kwargs):
+ if instance.user:
+ clear_user_permission_cache(instance.user)
+
+def pre_save_delete_page(instance, **kwargs):
+ clear_permission_cache()
+
+
+if settings.CMS_PERMISSION:
+ # TODO: will this work also with PageUser and PageGroup??
+ signals.pre_save.connect(pre_save_user, sender=User)
+ signals.pre_delete.connect(pre_delete_user, sender=User)
+
+ signals.pre_save.connect(pre_save_group, sender=Group)
+ signals.pre_delete.connect(pre_delete_group, sender=Group)
+
+ signals.pre_save.connect(pre_save_pagepermission, sender=PagePermission)
+ signals.pre_delete.connect(pre_delete_pagepermission, sender=PagePermission)
+
+ signals.pre_save.connect(pre_save_globalpagepermission, sender=GlobalPagePermission)
+ signals.pre_delete.connect(pre_delete_globalpagepermission, sender=GlobalPagePermission)
+
+ signals.pre_save.connect(pre_save_delete_page, sender=Page)
+ signals.pre_delete.connect(pre_save_delete_page, sender=Page)
+
+

0 comments on commit 31ff505

Please sign in to comment.