Example #1
0
    def test_file_persistence(self):
        with revision_manager:
            # 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))

        # 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.revert()

        # reload the reverted instance and check for its content
        file1 = FileModel.objects.all()[0]
        self.assertEqual(file1.test_file.file.read(), 'content1')
Example #2
0
    def test_file_persistence(self):
        with revision_manager:
            # 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))

        # 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.revert()

        # reload the reverted instance and check for its content
        file1 = FileModel.objects.all()[0]
        self.assertEqual(file1.test_file.file.read(), 'content1')
Example #3
0
def make_revision_with_plugins(item, user=None, comment=None):
    assert isinstance(item, NewsItem)
    assert NewsItem in revision._registered_models

    if context.is_active():
        if user:
            context.set_user(user)
        if comment:
            context.set_comment(comment)
        adapter = revision.get_adapter(NewsItem)
        context.add_to_context(revision, item, adapter.get_version_data(item,
            VERSION_CHANGE))
        for plugin in CMSPlugin.objects.filter(placeholder__newsitem=item):
            plugin_instance, admin = plugin.get_plugin_instance()
            if plugin_instance:
                context.add_to_context(revision, plugin_instance,
                        revision.get_adapter(
                            plugin_instance.__class__).get_version_data(
                                plugin_instance, VERSION_CHANGE))
            context.add_to_context(revision, plugin, revision.get_adapter(
                plugin.__class__).get_version_data(plugin, VERSION_CHANGE))