Skip to content
Browse files

Several publisher fixes to work with reversions.

Reversion simplifiing.
  • Loading branch information...
1 parent 1dca4bc commit 31e75d94aca6256a9bf945c566c629b79d222079 @pcicman pcicman committed Sep 9, 2009
View
5 cms/admin/pageadmin.py
@@ -190,9 +190,6 @@ def get_urls(self):
# helper for url pattern generation
pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
- # helper for url pattern generation
- pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
-
url_patterns = patterns('',
pat(r'^.+/add-plugin/$', add_plugin),
@@ -669,7 +666,7 @@ def render_revision_form(self, request, obj, version, context, revert=False, rec
page_changed(obj, force_moderation_action=PageModeratorState.ACTION_CHANGED)
# revert plugins
- revert_plugins(request, version.pk)
+ revert_plugins(request, version.pk, obj)
return response
View
8 cms/admin/views.py
@@ -247,23 +247,25 @@ def save_all_plugins(request, page, excludes=None):
else:
plugin.save()
-def revert_plugins(request, version_id):
+def revert_plugins(request, version_id, obj):
from reversion.models import Version
version = get_object_or_404(Version, pk=version_id)
revs = [related_version.object_version for related_version in version.revision.version_set.all()]
cms_plugin_list = []
plugin_list = []
titles = []
others = []
- page = None
+ page = obj
for rev in revs:
obj = rev.object
+
if obj.__class__ == CMSPlugin:
cms_plugin_list.append(obj)
elif hasattr(obj, 'cmsplugin_ptr_id'):
plugin_list.append(obj)
elif obj.__class__ == Page:
- page = Page.objects.get(pk=obj.pk)
+ pass
+ #page = obj #Page.objects.get(pk=obj.pk)
elif obj.__class__ == Title:
titles.append(obj)
else:
View
11 cms/models/pagemodel.py
@@ -6,6 +6,7 @@
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
from django.shortcuts import get_object_or_404
+from django.core.exceptions import ObjectDoesNotExist
from publisher import MpttPublisher
from publisher.errors import PublisherCantPublish
from cms.utils.urlutils import urljoin
@@ -14,8 +15,7 @@
from cms.models import signals as cms_signals
from cms.utils.page import get_available_slug
from cms.exceptions import NoHomeFound
-from django.core.exceptions import ObjectDoesNotExist
-
+from cms.utils.helpers import reversion_register
class Page(MpttPublisher):
@@ -696,9 +696,4 @@ def get_moderation_value(self, user):
return moderation_value
-
-
-
-if 'reversion' in settings.INSTALLED_APPS:
- import reversion
- reversion.register(Page, follow=["title_set", "cmsplugin_set", "pagepermission_set"])
+reversion_register(Page, follow=["title_set", "cmsplugin_set", "pagepermission_set"])
View
6 cms/models/permissionmodels.py
@@ -8,7 +8,7 @@
from django.contrib.sites.models import Site
from django.db import models
from django.utils.translation import ugettext_lazy as _
-
+from cms.utils.helpers import reversion_register
class AbstractPagePermission(models.Model):
"""Abstract page permissions
@@ -105,6 +105,4 @@ class Meta:
#__unicode__ = lambda self: unicode(self.group)
-if 'reversion' in settings.INSTALLED_APPS:
- import reversion
- reversion.register(PagePermission)
+reversion_register(PagePermission)
View
8 cms/models/pluginmodel.py
@@ -10,6 +10,7 @@
from publisher import MpttPublisher
from django.template.context import Context
from cms import settings
+from cms.utils.helpers import reversion_register
class PluginModelBase(ModelBase):
"""
@@ -156,8 +157,5 @@ def _publisher_get_public_copy(self):
setattr(public_copy, field.name, value)
public_copy.publisher_is_draft=False
return public_copy
-
-
-if 'reversion' in settings.INSTALLED_APPS:
- import reversion
- reversion.register(CMSPlugin)
+
+reversion_register(CMSPlugin)
View
6 cms/models/titlemodels.py
@@ -5,7 +5,7 @@
from cms import settings
from cms.models.managers import TitleManager
from cms.models.pagemodel import Page
-
+from cms.utils.helpers import reversion_register
class Title(Publisher):
language = models.CharField(_("language"), max_length=5, db_index=True)
@@ -86,6 +86,4 @@ def overwrite_url(self):
return None
-if 'reversion' in settings.INSTALLED_APPS:
- import reversion
- reversion.register(Title)
+reversion_register(Title)
View
5 cms/plugin_pool.py
@@ -2,7 +2,7 @@
from django.conf import settings
from cms import settings as cms_settings
from cms.plugin_base import CMSPluginBase
-
+from cms.utils.helpers import reversion_register
class PluginPool(object):
def __init__(self):
@@ -25,13 +25,12 @@ def register_plugin(self, plugin):
self.plugins[plugin.__name__] = plugin
if 'reversion' in settings.INSTALLED_APPS:
- import reversion
try:
from reversion.registration import RegistrationError
except ImportError:
from reversion.revisions import RegistrationError
try:
- reversion.register(plugin.model, follow=["cmsplugin_ptr"])
+ reversion_register(plugin.model, follow=["cmsplugin_ptr"])
except RegistrationError:
pass
View
9 cms/plugins/snippet/models.py
@@ -2,9 +2,7 @@
from django.utils.translation import ugettext_lazy as _
from cms.models import CMSPlugin
from django.conf import settings
-
-if 'reversion' in settings.INSTALLED_APPS:
- import reversion
+from cms.utils.helpers import reversion_register
# Stores the actual data
class Snippet(models.Model):
@@ -31,7 +29,6 @@ class SnippetPtr(CMSPlugin):
class Meta:
verbose_name = _("Snippet")
-if 'reversion' in settings.INSTALLED_APPS:
- # We don't both with SnippetPtr, since all the data is actually in Snippet
- reversion.register(Snippet)
+# We don't both with SnippetPtr, since all the data is actually in Snippet
+reversion_register(Snippet)
View
23 publisher/models.py
@@ -1,3 +1,4 @@
+from django.conf import settings
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields.related import RelatedField, OneToOneRel
@@ -131,8 +132,12 @@ def publish(self, excluded_models=None, first_instance=True):
# perform saving
# publish copy - all behind this requires public instance to have pk
+ self._publisher_pre_save_public(public_copy)
+
self._publisher_save_public(public_copy)
+ self._publisher_post_save_public(public_copy)
+
# store public model relation for current instance (only) for newly
# created items
@@ -225,13 +230,29 @@ def publish(self, excluded_models=None, first_instance=True):
# existing instances
public_copy._publisher_delete_marked()
return public_copy
-
+
+ def _publisher_pre_save_public(self, obj):
+ """We dont wanna public object to be under reversions. If they are
+ installed, just stop reversioning.
+ """
+ if 'reversion' in settings.INSTALLED_APPS:
+ import reversion
+ reversion.revision.start()
+
+
def _publisher_save_public(self, obj):
"""Save method for object which should be published. obj is a instance
of the same class as self.
"""
return obj.save()
+ def _publisher_post_save_public(self, obj):
+ """Public objects were saved, start reversioning.
+ """
+ if 'reversion' in settings.INSTALLED_APPS:
+ import reversion
+ reversion.revision.start()
+
def _collect_delete_marked_sub_objects(self, seen_objs, parent=None, nullable=False, excluded_models=None):
if excluded_models is None:

0 comments on commit 31e75d9

Please sign in to comment.
Something went wrong with that request. Please try again.