コード例 #1
0
ファイル: views.py プロジェクト: shanx/django-cms-2.0
            position = None
        plugin = CMSPlugin(page=page, language=language, plugin_type=plugin_type, position=position, placeholder=placeholder) 
        if parent:
            plugin.parent = parent
        plugin.save()
        if 'reversion' in settings.INSTALLED_APPS:
            page.save()
            save_all_plugins(page)
            revision.user = request.user
            plugin_name = unicode(plugin_pool.get_plugin(plugin_type).name)
            revision.comment = _(u"%(plugin_name)s plugin added to %(placeholder)s") % {'plugin_name':plugin_name, 'placeholder':placeholder}       
        return HttpResponse(str(plugin.pk))
    raise Http404

if 'reversion' in settings.INSTALLED_APPS:
    add_plugin = revision.create_on_success(add_plugin)

def edit_plugin(request, plugin_id, admin_site):
    plugin_id = int(plugin_id)
    if not 'history' in request.path:
        cms_plugin = get_object_or_404(CMSPlugin, pk=plugin_id)
        instance, admin = cms_plugin.get_plugin_instance(admin_site)
    else:
        # history view with reversion
        from reversion.models import Version
        version_id = request.path.split("/edit-plugin/")[0].split("/")[-1]
        version = get_object_or_404(Version, pk=version_id)
        revs = [related_version.object_version for related_version in version.revision.version_set.all()]
        
        for rev in revs:
            obj = rev.object
コード例 #2
0
ファイル: pageadmin.py プロジェクト: maximbo/django-cms-2.0
        instance = page = get_object_or_404(Page, id=object_id)
        attrs = "?preview=1"
        if request.REQUEST.get('public', None):
            if not page.publisher_public_id:
                raise Http404
            instance = page.publisher_public
        else:
            attrs += "&draft=1"
        
        url = instance.get_absolute_url() + attrs
        
        site = Site.objects.get_current()
        
        if not site == instance.site:
            url = "http://%s%s" % (instance.site.domain, url)
        return HttpResponseRedirect(url)
        

class PageAdminMixins(admin.ModelAdmin):
    pass

if 'reversion' in settings.INSTALLED_APPS:
    from reversion import revision
    from reversion.admin import VersionAdmin
    # change the inheritance chain to include VersionAdmin
    PageAdminMixins.__bases__ = (PageAdmin, VersionAdmin) + PageAdmin.__bases__
    PageAdminMixins.delete_translation = revision.create_on_success(PageAdminMixins.delete_translation)
    admin.site.register(Page, PageAdminMixins)
else:
    admin.site.register(Page, PageAdmin)
コード例 #3
0
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.signals import post_syncdb
from django.utils.translation import ugettext as _
from django.utils.importlib import import_module

from reversion import models as reversion_app, revision
from reversion.models import Version 


def version_save(obj):
    """Saves the initial version of an object."""
    obj.save()
    revision.user = None
    revision.comment = _(u"Initial version.")
version_save = revision.create_on_success(version_save)


def create_initial_revisions(app, verbosity=2, **kwargs):
    """
    Post-syncdb hook to create an initial revision for all registered models.
    """
    # Import the relevant admin module.
    try:
        import_module("%s.admin" % app.__name__.rsplit(".", 1)[0])
    except ImportError:
        pass
    # Check all models for empty revisions.
    for model_class in models.get_models(app):
        if revision.is_registered(model_class):
            content_type = ContentType.objects.get_for_model(model_class)
コード例 #4
0
ファイル: views.py プロジェクト: bbjunaid/pythoncocoa
        plugin = CMSPlugin(page=page, language=language, plugin_type=plugin_type, position=position, placeholder=placeholder) 

        if parent:
            plugin.parent = parent
        plugin.save()
        if 'reversion' in settings.INSTALLED_APPS:
            page.save()
            save_all_plugins(request, page)
            revision.user = request.user
            plugin_name = unicode(plugin_pool.get_plugin(plugin_type).name)
            revision.comment = _(u"%(plugin_name)s plugin added to %(placeholder)s") % {'plugin_name':plugin_name, 'placeholder':placeholder}
        return HttpResponse(str(plugin.pk))
    raise Http404

if 'reversion' in settings.INSTALLED_APPS:
    add_plugin = revision.create_on_success(add_plugin)

def edit_plugin(request, plugin_id, admin_site):
    plugin_id = int(plugin_id)
    if not 'history' in request.path and not 'recover' in request.path:
        cms_plugin = get_object_or_404(CMSPlugin, pk=plugin_id)
        instance, admin = cms_plugin.get_plugin_instance(admin_site)
        if not cms_plugin.page.has_change_permission(request):
            raise PermissionDenied 
    else:
        # history view with reversion
        from reversion.models import Version
        version_id = request.path.split("/edit-plugin/")[0].split("/")[-1]
        Version.objects.get(pk=version_id)
        version = get_object_or_404(Version, pk=version_id)
        revs = [related_version.object_version for related_version in version.revision.version_set.all()]
コード例 #5
0
ファイル: pageadmin.py プロジェクト: bbjunaid/pythoncocoa
        if request.REQUEST.get('public', None):
            if not page.publisher_public_id:
                raise Http404
            instance = page.publisher_public
        else:
            attrs += "&draft=1"

        url = instance.get_absolute_url() + attrs

        site = Site.objects.get_current()

        if not site == instance.site:
            url = "http://%s%s" % (instance.site.domain, url)
        return HttpResponseRedirect(url)


class PageAdminMixins(admin.ModelAdmin):
    pass


if 'reversion' in settings.INSTALLED_APPS:
    from reversion import revision
    from reversion.admin import VersionAdmin
    # change the inheritance chain to include VersionAdmin
    PageAdminMixins.__bases__ = (PageAdmin, VersionAdmin) + PageAdmin.__bases__
    PageAdminMixins.delete_translation = revision.create_on_success(
        PageAdminMixins.delete_translation)
    admin.site.register(Page, PageAdminMixins)
else:
    admin.site.register(Page, PageAdmin)
コード例 #6
0
from django.db.models.signals import post_syncdb
from django.utils.translation import ugettext as _
from django.utils.importlib import import_module

from reversion import models as reversion_app, revision
from reversion.models import Version


def version_save(obj):
    """Saves the initial version of an object."""
    obj.save()
    revision.user = None
    revision.comment = _(u"Initial version.")


version_save = revision.create_on_success(version_save)


def create_initial_revisions(app, verbosity=2, **kwargs):
    """
    Post-syncdb hook to create an initial revision for all registered models.
    """
    # Import the relevant admin module.
    try:
        import_module("%s.admin" % app.__name__.rsplit(".", 1)[0])
    except ImportError:
        pass
    # Check all models for empty revisions.
    for model_class in models.get_models(app):
        if revision.is_registered(model_class):
            content_type = ContentType.objects.get_for_model(model_class)