Permalink
Browse files

Merge branch 'yml-feature/remove_transaction_page_publish' into develop

  • Loading branch information...
2 parents 795a7fe + 5f028c1 commit f05717f8afc1ae4fa8af2bf50e0576ff66dc5994 Jonas Obrist committed Aug 18, 2011
Showing with 29 additions and 27 deletions.
  1. +10 −0 cms/models/managers.py
  2. +11 −25 cms/models/pagemodel.py
  3. +8 −2 cms/utils/page.py
View
@@ -21,6 +21,16 @@ def get_query_set(self):
"""
return PageQuerySet(self.model)
+ def drafts(self):
+ return super(PageManager, self).drafts().exclude(
+ publisher_state=self.model.PUBLISHER_STATE_DELETE
+ )
+
+ def public(self):
+ return super(PageManager, self).public().exclude(
+ publisher_state=self.model.PUBLISHER_STATE_DELETE
+ )
+
# !IMPORTANT: following methods always return access to draft instances,
# take care on what you do one them. use Page.objects.public() for accessing
View
@@ -13,9 +13,8 @@
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
-from django.db import models, transaction
+from django.db import models
from django.db.models import Q
-from django.db.models.fields.related import OneToOneRel
from django.shortcuts import get_object_or_404
from django.utils.translation import get_language, ugettext_lazy as _
from menus.menu_pool import menu_pool
@@ -391,20 +390,16 @@ def save_base(self, *args, **kwargs):
ret = super(Page, self).save_base(*args, **kwargs)
return ret
- @transaction.commit_manually
def publish(self):
"""Overrides Publisher method, because there may be some descendants, which
are waiting for parent to publish, so publish them if possible.
IMPORTANT: @See utils.moderator.approve_page for publishing permissions
- Also added @transaction.commit_manually decorator as delete()
- was removing both draft and public versions
Returns: True if page was successfully published.
"""
# Publish can only be called on moderated and draft pages
if not self.publisher_is_draft:
- transaction.rollback()
return
# publish, but only if all parents are published!!
@@ -414,21 +409,18 @@ def publish(self):
self.save()
if self._publisher_can_publish():
-
########################################################################
- # delete the existing public page using transaction block to ensure save() and delete() do not conflict
- # the draft version was being deleted if I replaced the save() below with a delete()
- try:
- old_public = self.get_public_object()
+ # Assign the existing public page in old_public and mark it as
+ # PUBLISHER_STATE_DELETE
+ # the draft version was being deleted if I replaced the save()
+ # below with a delete() directly so the deletion is handle at the end
+ old_public = self.get_public_object()
+ if old_public:
old_public.publisher_state = self.PUBLISHER_STATE_DELETE
# store old public on self, pass around instead
self.old_public = old_public
old_public.publisher_public = None # remove the reference to the publisher_draft version of the page so it does not get deleted
old_public.save()
- except:
- transaction.rollback()
- else:
- transaction.commit()
# we hook into the modified copy_page routing to do the heavy lifting of copying the draft page to a new public page
new_public = self.copy_page(target=None, site=self.site,
@@ -447,16 +439,15 @@ def publish(self):
self.publisher_public = new_public
self.moderator_state = Page.MODERATOR_APPROVED
self.publisher_state = self.PUBLISHER_STATE_DEFAULT
- self._publisher_keep_state = True
+ self._publisher_keep_state = True
published = True
else:
self.moderator_state = Page.MODERATOR_APPROVED_WAITING_FOR_PARENTS
self.save(change_state=False)
-
+
if not published:
# was not published, escape
- transaction.commit()
return
# clean moderation log
@@ -469,15 +460,12 @@ def publish(self):
for child_page in old_public.children.order_by('lft'):
child_page.move_to(new_public, 'last-child')
child_page.save(change_state=False)
- transaction.commit()
# reload old_public to get correct tree attrs
old_public = Page.objects.get(pk=old_public.pk)
old_public.move_to(None, 'last-child')
# moving the object out of the way berore deleting works, but why?
- # finally delete the old public page
+ # finally delete the old public page
old_public.delete()
- # manually commit the last transaction batch
- transaction.commit()
# page was published, check if there are some childs, which are waiting
# for publishing (because of the parent)
@@ -492,10 +480,8 @@ def publish(self):
import cms.signals as cms_signals
cms_signals.post_publish.send(sender=Page, instance=self)
- transaction.commit()
-
return published
-
+
def delete(self):
"""Mark public instance for deletion and delete draft.
"""
View
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.conf import settings
+from django.db.models import Q
import re
APPEND_TO_SLUG = "-copy"
@@ -9,7 +10,12 @@ def is_valid_page_slug(page, parent, lang, slug, site):
"""Validates given slug depending on settings.
"""
from cms.models import Title
- qs = Title.objects.filter(page__site=site, slug=slug).exclude(page=page).exclude(page=page.publisher_public)
+ # Exclude the page with the publisher_state == page.PUBLISHER_STATE_DELETE
+ qs = Title.objects.filter(page__site=site, slug=slug).exclude(
+ Q(page=page) |
+ Q(page=page.publisher_public) |
+ Q(page__publisher_state=page.PUBLISHER_STATE_DELETE)
+ )
if settings.i18n_installed:
qs = qs.filter(language=lang)
@@ -61,4 +67,4 @@ def check_title_slugs(page):
old_slug = title.slug
title.slug = get_available_slug(title)
if title.slug != old_slug:
- title.save()
+ title.save()

0 comments on commit f05717f

Please sign in to comment.