Skip to content

Commit

Permalink
slqite fixed, mysql fixed (except too many queries)
Browse files Browse the repository at this point in the history
  • Loading branch information
digi604 committed Nov 16, 2012
1 parent 7b3d65a commit 8f4d4ab
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 140 deletions.
8 changes: 5 additions & 3 deletions cms/models/pagemodel.py
Expand Up @@ -393,9 +393,10 @@ def publish(self):

# publish, but only if all parents are published!!
published = None

if not self.pk:
self.save()
if not self.parent_id:
self.clear_home_pk_cache()
if self._publisher_can_publish():
########################################################################
# Assign the existing public page in old_public and mark it as
Expand All @@ -409,6 +410,7 @@ def publish(self):
self.old_public = old_public
# remove the one-to-one references between public and draft
old_public.publisher_public = None
old_public.parent = None #unique constraint
old_public.save()

# we hook into the modified copy_page routing to do the heavy lifting of copying the draft page to a new public page
Expand All @@ -429,8 +431,7 @@ 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:
Expand Down Expand Up @@ -898,6 +899,7 @@ def get_home_pk_cache(self):
return getattr(self, attr)

def set_home_pk_cache(self, value):

attr = "%s_home_pk_cache_%s" % (self.publisher_is_draft and "draft" or "public", self.site_id)
setattr(self, attr, value)
home_pk_cache = property(get_home_pk_cache, set_home_pk_cache)
Expand Down
2 changes: 1 addition & 1 deletion cms/models/query.py
Expand Up @@ -77,7 +77,7 @@ def get_all_pages_with_application(self):

def get_home(self, site=None):
try:
home = self.published().all_root().order_by("tree_id")[0]
home = self.published(site).all_root().order_by("tree_id")[0]
except IndexError:
raise NoHomeFound('No Root page found. Publish at least one page!')
return home
11 changes: 7 additions & 4 deletions cms/test_utils/testcases.py
Expand Up @@ -10,6 +10,7 @@
from django.test import testcases
from django.test.client import RequestFactory
from django.utils.translation import activate
from django.contrib.sites.models import Site
from menus.menu_pool import menu_pool
from urlparse import urljoin
import sys
Expand Down Expand Up @@ -75,20 +76,22 @@ class CMSTestCase(testcases.TestCase):
counter = 1

def _fixture_setup(self):
Page.objects.all().delete()
User.objects.all().delete()
CMSPlugin.objects.all().delete()
Site.objects.exclude(pk=1).delete()
super(CMSTestCase, self)._fixture_setup()
self.create_fixtures()
activate("en")


def create_fixtures(self):
pass

def _post_teardown(self):
# Needed to clean the menu keys cache, see menu.menu_pool.clear()
menu_pool.clear()
super(CMSTestCase, self)._post_teardown()
#Page.objects.all().delete()
#User.objects.all().delete()
#CMSPlugin.objects.all().delete()
super(CMSTestCase, self)._post_teardown()
set_current_user(None)

def login_user_context(self, user):
Expand Down
2 changes: 2 additions & 0 deletions cms/tests/admin.py
Expand Up @@ -732,6 +732,8 @@ def test_preview_page(self):
site = Site.objects.create(domain='django-cms.org', name='django-cms')
page.site = site
page.save()
page.publish()
self.assertTrue(page.is_home())
response = self.admin_class.preview_page(request, page.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'],
Expand Down

0 comments on commit 8f4d4ab

Please sign in to comment.