Skip to content

Commit

Permalink
Mark pages as dirty when plugins change.
Browse files Browse the repository at this point in the history
  • Loading branch information
adaptivelogic committed Oct 22, 2012
1 parent e398ea1 commit 43417b6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cms/models/pagemodel.py
Expand Up @@ -106,8 +106,8 @@ def is_dirty(self):
def get_absolute_url(self, language=None, fallback=True):
if self.is_home():
return reverse('pages-root')
path = self.get_path(language, fallback)
return reverse('pages-details-by-slug', kwargs={"slug":path})
path = self.get_path(language, fallback) or self.get_slug(language, fallback)
return reverse('pages-details-by-slug', kwargs={"slug": path})

def move_page(self, target, position='first-child'):
"""
Expand Down
3 changes: 2 additions & 1 deletion cms/signals.py
Expand Up @@ -203,7 +203,8 @@ def post_save_page_moderator(instance, raw, created, **kwargs):

# tell moderator something was happen with this page
from cms.utils.moderator import page_changed
page_changed(instance, old_page)
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:
Expand Down
29 changes: 25 additions & 4 deletions cms/tests/publisher.py
Expand Up @@ -2,6 +2,7 @@
from __future__ import with_statement
from django.contrib.auth.models import User
from django.core.management.base import CommandError
from django.core.urlresolvers import reverse

from cms.api import create_page, add_plugin
from cms.management.commands import publisher_publish
Expand Down Expand Up @@ -122,7 +123,9 @@ def test_command_line_publishes_one_page(self):
class PublishingTests(TestCase):

settings_overrides = {'CMS_SHOW_START_DATE': False,
'CMS_SHOW_END_DATE': False}
'CMS_SHOW_END_DATE': False,
# Necessary to trigger an error
'USE_I18N': False}

def create_page(self, title=None, **kwargs):
return create_page(title or self._testMethodName,
Expand Down Expand Up @@ -364,8 +367,9 @@ def test_unpublish_with_descendants(self):
published = Page.objects.public().published()

self.assertEqual(page.get_descendant_count(), 2)
base = reverse('pages-root')

for url in ('/en/', '/en/child/', '/en/child/grandchild/'):
for url in (base, base + 'child/', base + 'child/grandchild/'):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

Expand All @@ -379,7 +383,7 @@ def test_unpublish_with_descendants(self):

self.assertTrue(page.unpublish(), 'Unpublish was not successful')
self.assertFalse(page.published)
for url in ('/en/', '/en/child/', '/en/child/grandchild/'):
for url in (base, base + 'child/', base + 'child/grandchild/'):
response = self.client.get(url)
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -429,11 +433,18 @@ def test_unpublish_with_dirty_descendants(self):
self.assertFalse(gchild.publisher_public.published)

def test_republish_multiple_root(self):
# TODO: The paths do not match expected behaviour
home = self.create_page("Page", published=True)
other = self.create_page("Another Page", published=True)
home = self.reload(home)
child = self.create_page("Child", published=True, parent=home)
child2 = self.create_page("Child", published=True, parent=other)
self.assertTrue(home.is_home())
self.assertTrue(home.publisher_public.is_home())
base = reverse('pages-root')
self.assertEqual(home.get_absolute_url(), base)
self.assertEqual(child.get_absolute_url(), base+'child/')
self.assertEqual(other.get_absolute_url(), base+'another-page/')
self.assertEqual(child2.get_absolute_url(), base+'another-page/child/')

home.unpublish()
home = self.reload(home)
Expand All @@ -442,12 +453,22 @@ def test_republish_multiple_root(self):
self.assertFalse(home.publisher_public.is_home())
self.assertTrue(other.is_home())
self.assertTrue(other.publisher_public.is_home())
self.assertEqual(other.get_absolute_url(), base)
self.assertEqual(home.get_absolute_url(), base+'page/')
# TODO: This should be 'page/child/'
self.assertEqual(child.get_absolute_url(), base+'child/')
# TODO: This should be 'another-page/child/'
self.assertEqual(child2.get_absolute_url(), base+'another-page/child/')

home.publish()
home = self.reload(home)
other = self.reload(other)
self.assertTrue(home.is_home())
self.assertTrue(home.publisher_public.is_home())
self.assertEqual(home.get_absolute_url(), base)
self.assertEqual(child.get_absolute_url(), base+'child/')
self.assertEqual(other.get_absolute_url(), base+'another-page/')
self.assertEqual(child2.get_absolute_url(), base+'another-page/child/')

def test_revert_contents(self):
user = self.get_superuser()
Expand Down
1 change: 1 addition & 0 deletions cms/utils/moderator.py
Expand Up @@ -17,6 +17,7 @@ def page_changed(page, old_page=None, force_moderation_action=None):

if force_moderation_action:
PageModeratorState(user=user, page=page, action=force_moderation_action).save()
page.save() # sets the page to dirty
return

if not old_page:
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/cli.rst
Expand Up @@ -57,9 +57,9 @@ It has two subcommands:



******************
*******************
Moderation commands
******************
*******************

``cms moderator``
=================
Expand Down

0 comments on commit 43417b6

Please sign in to comment.