Permalink
Browse files

Add support for django-reversion 1.7

django-reversion 1.7 removed some deprecated parts of the API. This
commit modifies the Django CMS code to use the new API which is already
supported supported in django-reversion 1.6.x which is required for
Django <1.5 support.
  • Loading branch information...
1 parent d8c4884 commit da2e4ca9be5d3ca8162939cac9b014c2dbd25d85 @bikeshedder bikeshedder committed Mar 26, 2013
Showing with 19 additions and 17 deletions.
  1. +10 −9 cms/admin/pageadmin.py
  2. +2 −2 cms/tests/plugins.py
  3. +7 −6 cms/tests/reversion_tests.py
View
@@ -57,11 +57,12 @@
if 'reversion' in settings.INSTALLED_APPS:
import reversion
+ import reversion.models
from reversion.admin import VersionAdmin as ModelAdmin
- create_on_success = reversion.revision.create_on_success
+ from reversion import create_revision
else: # pragma: no cover
from django.contrib.admin import ModelAdmin
- create_on_success = lambda x: x
+ create_revision = lambda: lambda x: x
if DJANGO_1_3:
"""
@@ -734,7 +735,7 @@ def render_revision_form(self, request, obj, version, context, revert=False, rec
return super(PageAdmin, self).render_revision_form(request, obj, version, context, revert, recover)
@require_POST
- @create_on_success
+ @create_revision()
def change_template(self, request, object_id):
page = get_object_or_404(Page, pk=object_id)
if not page.has_change_permission(request):
@@ -956,7 +957,7 @@ def delete_view(self, request, object_id, *args, **kwargs):
return HttpResponseRedirect("../../../../")
return HttpResponseRedirect("../../")
- @create_on_success
+ @create_revision()
def delete_translation(self, request, object_id, extra_context=None):
language = get_language_from_request(request)
@@ -1127,7 +1128,7 @@ def descendants(self, request, page_id):
template="admin/cms/page/lazy_menu.html")
@require_POST
- @create_on_success
+ @create_revision()
def add_plugin(self, request):
"""
Could be either a page or a parent - if it's a parent we get the page via parent.
@@ -1196,7 +1197,7 @@ def add_plugin(self, request):
return HttpResponse(str(plugin.pk), content_type='text/plain')
@require_POST
- @create_on_success
+ @create_revision()
@transaction.commit_on_success
def copy_plugins(self, request):
if 'history' in request.path or 'recover' in request.path:
@@ -1231,7 +1232,7 @@ def copy_plugins(self, request):
plugin_list = CMSPlugin.objects.filter(language=language, placeholder=placeholder, parent=None).order_by('position')
return render_to_response('admin/cms/page/widgets/plugin_item.html', {'plugin_list':plugin_list}, RequestContext(request))
- @create_on_success
+ @create_revision()
def edit_plugin(self, request, plugin_id):
plugin_id = int(plugin_id)
if not 'history' in request.path and not 'recover' in request.path:
@@ -1356,7 +1357,7 @@ def edit_plugin(self, request, plugin_id):
return response
@require_POST
- @create_on_success
+ @create_revision()
def move_plugin(self, request):
if 'history' in request.path:
return HttpResponseBadRequest(str("error"))
@@ -1423,7 +1424,7 @@ def move_plugin(self, request):
return HttpResponse(str("ok"))
@require_POST
- @create_on_success
+ @create_revision()
def remove_plugin(self, request):
if 'history' in request.path:
raise Http404()
View
@@ -134,7 +134,7 @@ def test_plugin_history_view(self):
"""
Test plugin history view
"""
- from reversion.models import Version
+ import reversion
page_data = self.get_new_page_data()
# two versions created by simply creating the page
response = self.client.post(URL_CMS_PAGE_ADD, page_data)
@@ -148,7 +148,7 @@ def test_plugin_history_view(self):
# page version 5
txt = self._edit_text_plugin(created_plugin_id, "Hello Bar")
self.assertEquals("Hello Bar", txt.body)
- versions = [v.pk for v in Version.objects.get_for_object(page)]
+ versions = [v.pk for v in reversed(reversion.get_for_object(page))]
history_url = '%s%d/' % (
URL_CMS_PLUGIN_HISTORY_EDIT % (page_id, versions[-2]),
created_plugin_id)
@@ -12,8 +12,7 @@
from django.core.files.uploadedfile import SimpleUploadedFile
from os.path import join
from cms.test_utils.project.fileapp.models import FileModel
-from reversion import (revision as revision_manager,
- revision_context_manager as revision_context)
+import reversion
from reversion.models import Revision, Version, VERSION_CHANGE
import shutil
@@ -140,24 +139,26 @@ def tearDown(self):
shutil.rmtree(join(settings.MEDIA_ROOT, 'fileapp'))
def test_file_persistence(self):
- with revision_manager:
+ with reversion.create_revision():
# add a file instance
file1 = FileModel()
file1.test_file.save('file1.txt',
SimpleUploadedFile('file1.txt', 'content1'), False)
file1.save()
# manually add a revision because we use the explicit way
# django-cms uses too.
- adapter = revision_manager.get_adapter(FileModel)
- revision_context.add_to_context(revision_manager, file1, adapter.get_version_data(file1, VERSION_CHANGE))
+ adapter = reversion.get_adapter(FileModel)
+ reversion.revision_context_manager.add_to_context(
+ reversion.default_revision_manager, file1,
+ adapter.get_version_data(file1, VERSION_CHANGE))
# reload the instance from db
file2 = FileModel.objects.all()[0]
# delete the instance.
file2.delete()
# revert the old version
- file_version = Version.objects.get_for_object(file1)[0]
+ file_version = reversion.get_for_object(file1)[0]
file_version.revert()
# reload the reverted instance and check for its content

0 comments on commit da2e4ca

Please sign in to comment.