Permalink
Browse files

fixed a lot of tests for mysql

  • Loading branch information...
1 parent 8ebdf7c commit 7b3d65ab77eddae277c119e3cc3a29e1039c2468 @digi604 digi604 committed Nov 15, 2012
View
@@ -92,7 +92,7 @@ def get_all_pages_with_application(self):
return self.get_query_set().filter(title_set__application_urls__gt='').distinct()
def get_home(self, site=None):
- return self.get_query_set().get_home(site)
+ return self.get_query_set().public().get_home(site)
def search(self, q, language=None, current_site_only=True):
"""Simple search function
@@ -340,7 +340,7 @@ def for_page(self, page):
"""
# permissions should be managed on the draft page only
page = page.get_draft_object()
- from cms.models import ACCESS_DESCENDANTS, ACCESS_CHILDREN,\
+ from cms.models import ACCESS_DESCENDANTS, ACCESS_CHILDREN, \
ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS
# code taken from
# https://github.com/divio/django-cms/issues/1113#issuecomment-3376790
View
@@ -20,6 +20,7 @@
from menus.menu_pool import menu_pool
from mptt.models import MPTTModel
from os.path import join
+from datetime import timedelta
import copy
@@ -71,7 +72,7 @@ class Page(MPTTModel):
moderator_state = models.SmallIntegerField(_('moderator state'), default=0, blank=True, editable=False)
publisher_is_draft = models.BooleanField(default=1, editable=False, db_index=True)
#This is misnamed - the one-to-one relation is populated on both ends
- publisher_public = models.OneToOneField('self', related_name='publisher_draft', null=True, editable=False)
+ publisher_public = models.OneToOneField('self', related_name='publisher_draft', null=True, editable=False)
publisher_state = models.SmallIntegerField(default=0, editable=False, db_index=True)
# Managers
@@ -133,7 +134,7 @@ def move_page(self, target, position='first-child'):
import cms.signals as cms_signals
cms_signals.page_moved.send(sender=Page, instance=self) # titles get saved before moderation
self.save() # always save the page after move, because of publisher
- moderator.page_changed(self, force_moderation_action = PageModeratorState.ACTION_MOVE)
+ moderator.page_changed(self, force_moderation_action=PageModeratorState.ACTION_MOVE)
# check the slugs
page_utils.check_title_slugs(self)
@@ -342,7 +343,7 @@ def save(self, no_signals=False, commit=True, **kwargs):
# Published pages should always have a publication date
# if the page is published we set the publish date if not set yet.
if self.publication_date is None and self.published:
- self.publication_date = timezone.now()
+ self.publication_date = timezone.now() - timedelta(seconds=5)
if self.reverse_id == "":
self.reverse_id = None
@@ -428,7 +429,8 @@ def publish(self):
else:
# Nothing left to do
pass
-
+ if not self.parent_id:
+ self.clear_home_pk_cache()
if self.publisher_public and self.publisher_public.published:
self.publisher_state = Page.PUBLISHER_STATE_DEFAULT
else:
@@ -891,7 +893,7 @@ def is_home(self):
def get_home_pk_cache(self):
attr = "%s_home_pk_cache_%s" % (self.publisher_is_draft and "draft" or "public", self.site_id)
- if not hasattr(self, attr):
+ if not hasattr(self, attr) or getattr(self, attr) is None:
setattr(self, attr, self.get_object_queryset().get_home(self.site).pk)
return getattr(self, attr)
@@ -900,6 +902,9 @@ def set_home_pk_cache(self, value):
setattr(self, attr, value)
home_pk_cache = property(get_home_pk_cache, set_home_pk_cache)
+ def clear_home_pk_cache(self):
+ self.home_pk_cache = None
+
def get_media_path(self, filename):
"""
Returns path (relative to MEDIA_ROOT/MEDIA_URL) to directory for storing page-scope files.
@@ -956,7 +961,7 @@ def get_object_queryset(self):
"""Returns smart queryset depending on object type - draft / public
"""
qs = self.__class__.objects
- return self.publisher_is_draft and qs.drafts() or qs.public().published()
+ return self.publisher_is_draft and qs.drafts() or qs.public()
def _publisher_can_publish(self):
"""Is parent of this object already published?
View
@@ -68,21 +68,6 @@ def expired(self):
return self.on_site().filter(
publication_end_date__lte=timezone.now())
-# - seems this is not used anymore...
-# def get_pages_with_application(self, path, language):
-# """Returns all pages containing application for current path, or
-# any parrent. Returned list is sorted by path length, longer path first.
-# """
-# paths = levelize_path(path)
-# q = Q()
-# for path in paths:
-# # build q for all the paths
-# q |= Q(title_set__path=path, title_set__language=language)
-# app_pages = self.published().filter(q & Q(title_set__application_urls__gt='')).distinct()
-# # add proper ordering
-# app_pages.query.order_by.extend(('LENGTH(`cms_title`.`path`) DESC',))
-# return app_pages
-
def get_all_pages_with_application(self):
"""Returns all pages containing applications for all sites.
@@ -92,7 +77,7 @@ def get_all_pages_with_application(self):
def get_home(self, site=None):
try:
- home = self.published(site).all_root().order_by("tree_id")[0]
+ home = self.published().all_root().order_by("tree_id")[0]
except IndexError:
raise NoHomeFound('No Root page found. Publish at least one page!')
return home
@@ -40,14 +40,14 @@ def update_path(self):
# Build path from parent page's path and slug
current_path = self.path
parent_page = self.page.parent
-
slug = u'%s' % self.slug
if not self.has_url_overwrite:
self.path = u'%s' % slug
if parent_page:
parent_title = Title.objects.get_title(parent_page, language=self.language, language_fallback=True)
if parent_title:
self.path = u'%s/%s' % (parent_title.path, slug)
+
@property
def overwrite_url(self):
View
@@ -6,7 +6,7 @@
from cms.cache.permissions import (
clear_user_permission_cache, clear_permission_cache)
-from cms.models import (Page, Title, CMSPlugin, PagePermission,
+from cms.models import (Page, Title, CMSPlugin, PagePermission,
GlobalPagePermission, PageUser, PageUserGroup)
from menus.menu_pool import menu_pool
@@ -20,7 +20,7 @@
# 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']
plugins = CMSPlugin.objects.filter(language=plugin.language, placeholder=plugin.placeholder).order_by("position")
@@ -39,14 +39,14 @@ def update_title_paths(instance, **kwargs):
"""
for title in instance.title_set.all():
title.save()
-
+
page_moved.connect(update_title_paths, sender=Page, dispatch_uid="cms.title.update_path")
def update_title(title):
parent_page_id = title.page.parent_id
slug = u'%s' % title.slug
-
+
if title.page.is_home():
title.path = ''
elif not title.has_url_overwrite:
@@ -61,66 +61,66 @@ def update_title(title):
def pre_save_title(instance, raw, **kwargs):
"""Save old state to instance and setup path
"""
-
+
menu_pool.clear(instance.page.site_id)
-
+
instance.tmp_path = None
instance.tmp_application_urls = None
-
+
if instance.id:
try:
tmp_title = Title.objects.get(pk=instance.id)
instance.tmp_path = tmp_title.path
instance.tmp_application_urls = tmp_title.application_urls
except:
pass # no Titles exist for this page yet
-
+
# Build path from parent page's path and slug
if instance.has_url_overwrite and instance.path:
instance.path = instance.path.strip(" /")
else:
update_title(instance)
-
+
signals.pre_save.connect(pre_save_title, sender=Title, dispatch_uid="cms.title.presave")
def post_save_title(instance, raw, created, **kwargs):
# Update descendants only if path changed
application_changed = False
-
- if instance.path != getattr(instance,'tmp_path',None) and not hasattr(instance, 'tmp_prevent_descendant_update'):
+
+ if instance.path != getattr(instance, 'tmp_path', None) and not hasattr(instance, 'tmp_prevent_descendant_update'):
descendant_titles = Title.objects.filter(
- page__lft__gt=instance.page.lft,
- page__rght__lt=instance.page.rght,
+ page__lft__gt=instance.page.lft,
+ page__rght__lt=instance.page.rght,
page__tree_id__exact=instance.page.tree_id,
language=instance.language,
has_url_overwrite=False,
).order_by('page__tree_id', 'page__parent', 'page__lft')
-
+
for descendant_title in descendant_titles:
descendant_title.path = '' # just reset path
descendant_title.tmp_prevent_descendant_update = True
if descendant_title.application_urls:
application_changed = True
descendant_title.save()
-
+
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
application_post_changed.send(sender=Title, instance=instance)
-
+
# remove temporary attributes
- if getattr( instance, 'tmp_path', None):
+ if getattr(instance, 'tmp_path', None):
del(instance.tmp_path)
- if getattr( instance, 'tmp_application_urls' , None):
+ if getattr(instance, 'tmp_application_urls' , None):
del(instance.tmp_application_urls)
-
+
try:
del(instance.tmp_prevent_descendant_update)
except AttributeError:
pass
-signals.post_save.connect(post_save_title, sender=Title, dispatch_uid="cms.title.postsave")
+signals.post_save.connect(post_save_title, sender=Title, dispatch_uid="cms.title.postsave")
def post_save_user(instance, raw, created, **kwargs):
@@ -135,23 +135,11 @@ def post_save_user(instance, raw, created, **kwargs):
creator = get_current_user()
if not creator or not created or not hasattr(creator, 'pk'):
return
- from django.db import connection
-
- # i'm not sure if there is a workaround for this, somebody any ideas? What
- # we are doing here is creating PageUser on Top of existing user, i'll do it
- # through plain SQL, its not nice, but...
-
- # TODO: find a better way than an raw sql !!
-
- cursor = connection.cursor()
- query = "INSERT INTO %s (user_ptr_id, created_by_id) VALUES (%d, %d)" % (
- PageUser._meta.db_table,
- instance.pk,
- creator.pk
- )
- cursor.execute(query)
- cursor.close()
-
+ page_user = PageUser(user_ptr_id=instance.pk, created_by=creator)
+ page_user.__dict__.update(instance.__dict__)
+ page_user.save()
+
+
def post_save_user_group(instance, raw, created, **kwargs):
"""The same like post_save_user, but for Group, required only when
CMS_PERMISSION.
@@ -166,18 +154,18 @@ def post_save_user_group(instance, raw, created, **kwargs):
if not creator or not created or creator.is_anonymous():
return
from django.db import connection
-
+
# TODO: same as in post_save_user - raw sql is just not nice - workaround...?
-
+
cursor = connection.cursor()
query = "INSERT INTO %s (group_ptr_id, created_by_id) VALUES (%d, %d)" % (
PageUserGroup._meta.db_table,
- instance.pk,
+ instance.pk,
creator.pk
)
- cursor.execute(query)
+ cursor.execute(query)
cursor.close()
-
+
if settings.CMS_PERMISSION:
# only if permissions are in use
from django.contrib.auth.models import User, Group
@@ -196,7 +184,7 @@ def pre_save_page(instance, raw, **kwargs):
pass
-def post_save_page_moderator(instance, raw, created, **kwargs):
+def post_save_page_moderator(instance, raw, created, **kwargs):
"""Helper post save signal.
"""
old_page = instance.old_page
@@ -205,7 +193,7 @@ def post_save_page_moderator(instance, raw, created, **kwargs):
from cms.utils.moderator import page_changed
if not old_page:
page_changed(instance, old_page)
-
+
def post_save_page(instance, **kwargs):
if instance.old_page is None or instance.old_page.parent_id != instance.parent_id:
for page in instance.get_descendants():
@@ -268,18 +256,18 @@ def pre_save_delete_page(instance, **kwargs):
signals.pre_save.connect(pre_save_user, sender=PageUser)
signals.pre_delete.connect(pre_delete_user, sender=PageUser)
-
+
signals.pre_save.connect(pre_save_group, sender=Group)
signals.pre_delete.connect(pre_delete_group, sender=Group)
signals.pre_save.connect(pre_save_group, sender=PageUserGroup)
signals.pre_delete.connect(pre_delete_group, sender=PageUserGroup)
-
+
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)
Oops, something went wrong.

0 comments on commit 7b3d65a

Please sign in to comment.