Esempio n. 1
0
    def get_fieldsets(self, request, obj=None):
        """
        Add fieldsets of placeholders to the list of already existing
        fieldsets.
        """
        template = get_template_from_request(request, obj)
        
        if obj: # edit
            given_fieldsets = deepcopy(self.fieldsets)
            if not obj.has_publish_permission(request):
                l = list(given_fieldsets[0][1]['fields'][2])
                l.remove('published')
                given_fieldsets[0][1]['fields'][2] = tuple(l)
            for placeholder_name in get_placeholders(request, template):
                if placeholder_name not in self.mandatory_placeholders:
                    if placeholder_name in settings.CMS_PLACEHOLDER_CONF and "name" in settings.CMS_PLACEHOLDER_CONF[placeholder_name]:
                        name = settings.CMS_PLACEHOLDER_CONF[placeholder_name]["name"]
                    else:
                        name = placeholder_name
                    given_fieldsets += [(title(name), {'fields':[placeholder_name], 'classes':['plugin-holder']})]
            advanced = given_fieldsets.pop(3)
            if obj.has_advanced_settings_permission(request):
                given_fieldsets.append(advanced)
            if settings.CMS_SEO_FIELDS:
                seo = given_fieldsets.pop(3)
                given_fieldsets.append(seo) 
        else: # new page
            given_fieldsets = deepcopy(self.add_fieldsets)

        return given_fieldsets
Esempio n. 2
0
    def get_fieldsets(self, request, obj=None):
        """
        Add fieldsets of placeholders to the list of already existing
        fieldsets.
        """
        template = get_template_from_request(request, obj)

        if obj:  # edit
            given_fieldsets = deepcopy(self.fieldsets)
            if not obj.has_publish_permission(request):
                l = list(given_fieldsets[0][1]['fields'][2])
                l.remove('published')
                given_fieldsets[0][1]['fields'][2] = tuple(l)
            for placeholder_name in get_placeholders(request, template):
                if placeholder_name not in self.mandatory_placeholders:
                    if placeholder_name in settings.CMS_PLACEHOLDER_CONF and "name" in settings.CMS_PLACEHOLDER_CONF[
                            placeholder_name]:
                        name = settings.CMS_PLACEHOLDER_CONF[placeholder_name][
                            "name"]
                    else:
                        name = placeholder_name
                    given_fieldsets += [(title(name), {
                        'fields': [placeholder_name],
                        'classes': ['plugin-holder']
                    })]
            advanced = given_fieldsets.pop(3)
            if obj.has_advanced_settings_permission(request):
                given_fieldsets.append(advanced)
            if settings.CMS_SEO_FIELDS:
                seo = given_fieldsets.pop(3)
                given_fieldsets.append(seo)
        else:  # new page
            given_fieldsets = deepcopy(self.add_fieldsets)

        return given_fieldsets
Esempio n. 3
0
    def get_form(self, request, obj=None, **kwargs):
        """
        Get PageForm for the Page model and modify its fields depending on
        the request.
        """
        if obj:
            if not obj.has_publish_permission(request):
                self.exclude.append('status')
            else:
                if 'status' in self.exclude:
                    self.exclude.remove('status')
            if not obj.has_softroot_permission(request):
                self.exclude.append('soft_root')
            else:
                if 'soft_root' in self.exclude:
                    self.exclude.remove('soft_root')
        version_id = None
        versioned = False
        if "history" in request.path or 'recover' in request.path:
            versioned = True
            version_id = request.path.split("/")[-2]
        form = super(PageAdmin, self).get_form(request, obj, **kwargs)
        language = get_language_from_request(request, obj)
        form.base_fields['language'].initial = force_unicode(language)
        if obj:
            initial_slug = obj.get_slug(language=language, fallback=False, version_id=version_id, force_reload=True)
            initial_title = obj.get_title(language=language, fallback=False, version_id=version_id)
            form.base_fields['slug'].initial = initial_slug
            form.base_fields['title'].initial = initial_title
        else:
            # Clear out the customisations made above
            # TODO - remove this hack, this is v ugly
            form.base_fields['slug'].initial = u''
            form.base_fields['title'].initial = u''

        template = get_template_from_request(request, obj)
        if settings.CMS_TEMPLATES:
            template_choices = list(settings.CMS_TEMPLATES)
            form.base_fields['template'].choices = template_choices
            form.base_fields['template'].initial = force_unicode(template)
        for placeholder in get_placeholders(request, template):
            if placeholder.name not in self.mandatory_placeholders:
                installed_plugins = plugin_pool.get_all_plugins(placeholder.name)
                plugin_list = []
                if obj:
                    if versioned:
                        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()]
                        plugin_list = []
                        for rev in revs:
                            obj = rev.object
                            if obj.__class__ == CMSPlugin:
                                if obj.language == language and obj.placeholder == placeholder.name:
                                    plugin_list.append(rev.object)
                    else:
                        plugin_list = CMSPlugin.objects.filter(page=obj, language=language, placeholder=placeholder.name).order_by('position')
                widget = PluginEditor(attrs={'installed':installed_plugins, 'list':plugin_list})
                form.base_fields[placeholder.name] = CharField(widget=widget, required=False)
        return form
 def get_fieldsets(self, request, obj=None):
     """
     Add fieldsets of placeholders to the list of already existing
     fieldsets.
     """
     template = get_template_from_request(request, obj)
     given_fieldsets = deepcopy(self.fieldsets)
     if obj:
         if not obj.has_publish_permission(request):
             given_fieldsets[1][1]['fields'].remove('status')
         if settings.CMS_SOFTROOT and not obj.has_softroot_permission(request):
             given_fieldsets[2][1]['fields'].remove('soft_root')
     for placeholder in get_placeholders(request, template):
         if placeholder.name not in self.mandatory_placeholders:
             given_fieldsets += [(title(placeholder.name), {'fields':[placeholder.name], 'classes':['plugin-holder']})]        
     return given_fieldsets
Esempio n. 5
0
    def change_view(self, request, object_id, extra_context=None):
        """
        The 'change' admin view for the Page model.
        """

        try:
            obj = self.model.objects.get(pk=object_id)
        except self.model.DoesNotExist:
            # Don't raise Http404 just yet, because we haven't checked
            # permissions yet. We don't want an unauthenticated user to be able
            # to determine whether a given object exists.
            obj = None
        else:
            template = get_template_from_request(request, obj)
            moderation_level, moderation_required = get_test_moderation_level(obj, request.user)
            
            # if there is a delete request for this page
            moderation_delete_request = (settings.CMS_MODERATOR and
                    obj.pagemoderatorstate_set.get_delete_actions(
                    ).count())

            language = get_language_from_request(request, obj)
            #activate(user_lang_set)
            extra_context = {
                'placeholders': get_placeholders(request, template),
                'language': language,
                'traduction_language': settings.CMS_LANGUAGES,
                'show_language_tabs': len(settings.CMS_LANGUAGES) > 1,
                'page': obj,
                'CMS_PERMISSION': settings.CMS_PERMISSION,
                'CMS_MODERATOR': settings.CMS_MODERATOR,
                'has_change_permissions_permission': obj.has_change_permissions_permission(request),
                'has_moderate_permission': obj.has_moderate_permission(request),
                
                'moderation_level': moderation_level,
                'moderation_required': moderation_required,
                'moderator_should_approve': moderator_should_approve(request, obj),
                
                'moderation_delete_request': moderation_delete_request,
            }
        tab_language = request.GET.get("language", None)
        response = super(PageAdmin, self).change_view(request, object_id, extra_context)
        
        if tab_language and response.status_code == 302 and response._headers['location'][1] == request.path :
            location = response._headers['location']
            response._headers['location'] = (location[0], "%s?language=%s" % (location[1], tab_language))
        return response
Esempio n. 6
0
    def change_view(self, request, object_id, extra_context=None):
        """
        The 'change' admin view for the Page model.
        """

        try:
            obj = self.model.objects.get(pk=object_id)
        except self.model.DoesNotExist:
            # Don't raise Http404 just yet, because we haven't checked
            # permissions yet. We don't want an unauthenticated user to be able
            # to determine whether a given object exists.
            obj = None
        else:
            template = get_template_from_request(request, obj)
            moderation_level, moderation_required = get_test_moderation_level(obj, request.user)

            # if there is a delete request for this page
            moderation_delete_request = (
                settings.CMS_MODERATOR and obj.pagemoderatorstate_set.get_delete_actions().count()
            )

            # activate(user_lang_set)
            extra_context = {
                "placeholders": get_placeholders(request, template),
                "page": obj,
                "CMS_PERMISSION": settings.CMS_PERMISSION,
                "CMS_MODERATOR": settings.CMS_MODERATOR,
                "has_change_permissions_permission": obj.has_change_permissions_permission(request),
                "has_moderate_permission": obj.has_moderate_permission(request),
                "moderation_level": moderation_level,
                "moderation_required": moderation_required,
                "moderator_should_approve": moderator_should_approve(request, obj),
                "moderation_delete_request": moderation_delete_request,
                "show_delete_translation": len(obj.get_languages()) > 1,
            }
            extra_context = self.update_language_tab_context(request, obj, extra_context)
        tab_language = request.GET.get("language", None)
        response = super(PageAdmin, self).change_view(request, object_id, extra_context)

        if tab_language and response.status_code == 302 and response._headers["location"][1] == request.path:
            location = response._headers["location"]
            response._headers["location"] = (location[0], "%s?language=%s" % (location[1], tab_language))
        return response
Esempio n. 7
0
    def change_view(self, request, object_id, extra_context=None):
        """
        The 'change' admin view for the Page model.
        """

        try:
            obj = self.model.objects.get(pk=object_id)
        except self.model.DoesNotExist:
            # Don't raise Http404 just yet, because we haven't checked
            # permissions yet. We don't want an unauthenticated user to be able
            # to determine whether a given object exists.
            obj = None
        else:
            template = get_template_from_request(request, obj)
            moderation_level, moderation_required = get_test_moderation_level(obj, request.user)
            
            # if there is a delete request for this page
            moderation_delete_request = (settings.CMS_MODERATOR and
                    obj.pagemoderatorstate_set.get_delete_actions(
                    ).count())

            user_lang_set = request.GET.get('language',
                                            django_settings.LANGUAGE_CODE)
            activate(user_lang_set)
            extra_context = {
                'placeholders': get_placeholders(request, template),
                'language': user_lang_set,
                'traduction_language': settings.CMS_LANGUAGES,
                'page': obj,
                'CMS_PERMISSION': settings.CMS_PERMISSION,
                'CMS_MODERATOR': settings.CMS_MODERATOR,
                'has_change_permissions_permission': obj.has_change_permissions_permission(request),
                'has_moderate_permission': obj.has_moderate_permission(request),
                
                'moderation_level': moderation_level,
                'moderation_required': moderation_required,
                'moderator_should_approve': moderator_should_approve(request, obj),
                
                'moderation_delete_request': moderation_delete_request,
            }
        
        return super(PageAdmin, self).change_view(request, object_id, extra_context)
 def change_view(self, request, object_id, extra_context=None):
     """
     The 'change' admin view for the Page model.
     """
     try:
         obj = self.model.objects.get(pk=object_id)
     except self.model.DoesNotExist:
         # Don't raise Http404 just yet, because we haven't checked
         # permissions yet. We don't want an unauthenticated user to be able
         # to determine whether a given object exists.
         obj = None
     else:
         template = get_template_from_request(request, obj)
         extra_context = {
             'placeholders': get_placeholders(request, template),
             'language': get_language_from_request(request),
             'traduction_language': settings.CMS_LANGUAGES,
             'page': obj,
         }
     return super(PageAdmin, self).change_view(request, object_id, extra_context)
Esempio n. 9
0
 def get_fieldsets(self, request, obj=None):
     """
     Add fieldsets of placeholders to the list of already existing
     fieldsets.
     """
     template = get_template_from_request(request, obj)
     
     if obj: # edit
         given_fieldsets = deepcopy(self.fieldsets)
         if not obj.has_publish_permission(request):
             given_fieldsets[0][1]['fields'].remove('published')
         if settings.CMS_SOFTROOT and not obj.has_softroot_permission(request):
             given_fieldsets[2][1]['fields'].remove('soft_root')
         for placeholder in get_placeholders(request, template):
             if placeholder.name not in self.mandatory_placeholders:
                 if placeholder.name in settings.CMS_PLACEHOLDER_CONF and "name" in settings.CMS_PLACEHOLDER_CONF[placeholder.name]:
                     name = settings.CMS_PLACEHOLDER_CONF[placeholder.name]["name"]
                 else:
                     name = placeholder.name
                 given_fieldsets += [(title(name), {'fields':[placeholder.name], 'classes':['plugin-holder']})]
     else: # new page
         given_fieldsets = deepcopy(self.add_fieldsets)
             
     return given_fieldsets
Esempio n. 10
0
    def get_form(self, request, obj=None, **kwargs):
        """
        Get PageForm for the Page model and modify its fields depending on
        the request.
        """
        
        language = get_language_from_request(request, obj)
        
        if obj:
            self.inlines = PAGE_ADMIN_INLINES
            if not obj.has_publish_permission(request) and not 'published' in self.exclude:
                self.exclude.append('published')
            elif 'published' in self.exclude:
                self.exclude.remove('published')

            if not settings.CMS_SOFTROOT and 'soft_root' in self.exclude:
                self.exclude.remove('soft_root')

            form = super(PageAdmin, self).get_form(request, obj, **kwargs)
            version_id = None
            versioned = False
            if "history" in request.path or 'recover' in request.path:
                versioned = True
                version_id = request.path.split("/")[-2]
        else:
            self.inlines = []
            form = PageAddForm

        if obj:
            try:
                title_obj = obj.get_title_obj(language=language, fallback=False, version_id=version_id, force_reload=True)
            except:
                title_obj = EmptyTitle()
            for name in ['slug',
                         'title',
                         'application_urls',
                         'redirect',
                         'meta_description',
                         'meta_keywords', 
                         'menu_title', 
                         'page_title']:
                form.base_fields[name].initial = getattr(title_obj, name)
            if title_obj.overwrite_url:
                form.base_fields['overwrite_url'].initial = title_obj.path
            else:
                form.base_fields['overwrite_url'].initial = ""
            if settings.CMS_TEMPLATES:
                template = get_template_from_request(request, obj)
                template_choices = list(settings.CMS_TEMPLATES)
                form.base_fields['template'].choices = template_choices
                form.base_fields['template'].initial = force_unicode(template)
            
            for placeholder_name in get_placeholders(request, template):
                if placeholder_name not in self.mandatory_placeholders:
                    installed_plugins = plugin_pool.get_all_plugins(placeholder_name)
                    plugin_list = []
                    if obj:
                        if versioned:
                            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()]
                            plugin_list = []
                            plugins = []
                            bases = {}
                            for rev in revs:
                                obj = rev.object
                                if obj.__class__ == CMSPlugin:
                                    if obj.language == language and obj.placeholder == placeholder_name and not obj.parent_id:
                                        if obj.get_plugin_class() == CMSPlugin:
                                            plugin_list.append(obj)
                                        else:
                                            bases[int(obj.pk)] = obj
                                if hasattr(obj, "cmsplugin_ptr_id"): 
                                    plugins.append(obj)
                            for plugin in plugins:
                                if int(plugin.cmsplugin_ptr_id) in bases:
                                    bases[int(plugin.cmsplugin_ptr_id)].set_base_attr(plugin)
                                    plugin_list.append(plugin)
                        else:
                            plugin_list = CMSPlugin.objects.filter(page=obj, language=language, placeholder=placeholder_name, parent=None).order_by('position')
                    widget = PluginEditor(attrs={'installed':installed_plugins, 'list':plugin_list})
                    form.base_fields[placeholder_name] = CharField(widget=widget, required=False)
        else: 
            for name in ['slug','title']:
                form.base_fields[name].initial = u''
            form.base_fields['parent'].initial = request.GET.get('target', None)
            form.base_fields['site'].initial = request.session.get('cms_admin_site', None)
            form.base_fields['template'].initial = settings.CMS_TEMPLATES[0][0]
        return form
Esempio n. 11
0
 def get_form(self, request, obj=None, **kwargs):
     """
     Get PageForm for the Page model and modify its fields depending on
     the request.
     """
     if obj:
         if not obj.has_publish_permission(request):
             self.exclude.append('status')
         else:
             if 'status' in self.exclude:
                 self.exclude.remove('status')
         if not obj.has_softroot_permission(request):
             self.exclude.append('soft_root')
         else:
             if 'soft_root' in self.exclude:
                 self.exclude.remove('soft_root')
     version_id = None
     versioned = False
     if "history" in request.path or 'recover' in request.path:
         versioned = True
         version_id = request.path.split("/")[-2]
     form = super(PageAdmin, self).get_form(request, obj, **kwargs)
     language = get_language_from_request(request, obj)
     form.base_fields['language'].initial = force_unicode(language)
     if 'site' in request.GET.keys():
         form.base_fields['sites'].initial = [int(request.GET['site'])]
     else:
         form.base_fields['sites'].initial = Site.objects.all().values_list('id', flat=True)
     if obj:
         try:
             title_obj = obj.get_title_obj(language=language, fallback=False, version_id=version_id, force_reload=True)
         except:
             title_obj = EmptyTitle()
         for name in ['slug',
                      'title',
                      'application_urls',
                      'overwrite_url',
                      'redirect',
                      'meta_description',
                      'meta_keywords', 
                      'menu_title', 
                      'page_title']:
             form.base_fields[name].initial = getattr(title_obj, name)
     else:
         # Clear out the customisations made above
         # TODO - remove this hack, this is v ugly
         for name in ['slug','title','application_urls','overwrite_url','meta_description','meta_keywords']:
             form.base_fields[name].initial = u''
         form.base_fields['parent'].initial = request.GET.get('target', None)
     form.base_fields['parent'].widget = HiddenInput() 
     template = get_template_from_request(request, obj)
     if settings.CMS_TEMPLATES:
         template_choices = list(settings.CMS_TEMPLATES)
         form.base_fields['template'].choices = template_choices
         form.base_fields['template'].initial = force_unicode(template)
     for placeholder in get_placeholders(request, template):
         if placeholder.name not in self.mandatory_placeholders:
             installed_plugins = plugin_pool.get_all_plugins(placeholder.name)
             plugin_list = []
             if obj:
                 if versioned:
                     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()]
                     plugin_list = []
                     for rev in revs:
                         obj = rev.object
                         if obj.__class__ == CMSPlugin:
                             if obj.language == language and obj.placeholder == placeholder.name and not obj.parent_id:
                                 plugin_list.append(rev.object)
                 else:
                     plugin_list = CMSPlugin.objects.filter(page=obj, language=language, placeholder=placeholder.name, parent=None).order_by('position')
             widget = PluginEditor(attrs={'installed':installed_plugins, 'list':plugin_list})
             form.base_fields[placeholder.name] = CharField(widget=widget, required=False)
     return form
Esempio n. 12
0
    def change_view(self, request, object_id, extra_context=None):
        """
        The 'change' admin view for the Page model.
        """

        try:
            obj = self.model.objects.get(pk=object_id)
        except self.model.DoesNotExist:
            # Don't raise Http404 just yet, because we haven't checked
            # permissions yet. We don't want an unauthenticated user to be able
            # to determine whether a given object exists.
            obj = None
        else:
            template = get_template_from_request(request, obj)
            moderation_level, moderation_required = get_test_moderation_level(
                obj, request.user)

            # if there is a delete request for this page
            moderation_delete_request = (
                settings.CMS_MODERATOR
                and obj.pagemoderatorstate_set.get_delete_actions().count())

            #activate(user_lang_set)
            extra_context = {
                'placeholders':
                get_placeholders(request, template),
                'page':
                obj,
                'CMS_PERMISSION':
                settings.CMS_PERMISSION,
                'CMS_MODERATOR':
                settings.CMS_MODERATOR,
                'ADMIN_MEDIA_URL':
                settings.ADMIN_MEDIA_PREFIX,
                'has_change_permissions_permission':
                obj.has_change_permissions_permission(request),
                'has_moderate_permission':
                obj.has_moderate_permission(request),
                'moderation_level':
                moderation_level,
                'moderation_required':
                moderation_required,
                'moderator_should_approve':
                moderator_should_approve(request, obj),
                'moderation_delete_request':
                moderation_delete_request,
                'show_delete_translation':
                len(obj.get_languages()) > 1
            }
            extra_context = self.update_language_tab_context(
                request, obj, extra_context)
        tab_language = request.GET.get("language", None)
        response = super(PageAdmin, self).change_view(request, object_id,
                                                      extra_context)

        if tab_language and response.status_code == 302 and response._headers[
                'location'][1] == request.path:
            location = response._headers['location']
            response._headers['location'] = (location[0], "%s?language=%s" %
                                             (location[1], tab_language))
        return response
Esempio n. 13
0
    def get_form(self, request, obj=None, **kwargs):
        """
        Get PageForm for the Page model and modify its fields depending on
        the request.
        """

        language = get_language_from_request(request, obj)

        if obj:
            self.inlines = PAGE_ADMIN_INLINES
            if not obj.has_publish_permission(
                    request) and not 'published' in self.exclude:
                self.exclude.append('published')
            elif 'published' in self.exclude:
                self.exclude.remove('published')

            if not settings.CMS_SOFTROOT and 'soft_root' in self.exclude:
                self.exclude.remove('soft_root')

            form = super(PageAdmin, self).get_form(request, obj, **kwargs)
            version_id = None
            versioned = False
            if "history" in request.path or 'recover' in request.path:
                versioned = True
                version_id = request.path.split("/")[-2]
        else:
            self.inlines = []
            form = PageAddForm

        if obj:
            try:
                title_obj = obj.get_title_obj(language=language,
                                              fallback=False,
                                              version_id=version_id,
                                              force_reload=True)
            except:
                title_obj = EmptyTitle()
            for name in [
                    'slug', 'title', 'application_urls', 'redirect',
                    'meta_description', 'meta_keywords', 'menu_title',
                    'page_title'
            ]:
                form.base_fields[name].initial = getattr(title_obj, name)
            if title_obj.overwrite_url:
                form.base_fields['overwrite_url'].initial = title_obj.path
            else:
                form.base_fields['overwrite_url'].initial = ""
            if settings.CMS_TEMPLATES:
                template = get_template_from_request(request, obj)
                template_choices = list(settings.CMS_TEMPLATES)
                form.base_fields['template'].choices = template_choices
                form.base_fields['template'].initial = force_unicode(template)

            for placeholder_name in get_placeholders(request, template):
                if placeholder_name not in self.mandatory_placeholders:
                    installed_plugins = plugin_pool.get_all_plugins(
                        placeholder_name)
                    plugin_list = []
                    if obj:
                        if versioned:
                            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()
                            ]
                            plugin_list = []
                            plugins = []
                            bases = {}
                            for rev in revs:
                                obj = rev.object
                                if obj.__class__ == CMSPlugin:
                                    if obj.language == language and obj.placeholder == placeholder_name and not obj.parent_id:
                                        if obj.get_plugin_class() == CMSPlugin:
                                            plugin_list.append(obj)
                                        else:
                                            bases[int(obj.pk)] = obj
                                if hasattr(obj, "cmsplugin_ptr_id"):
                                    plugins.append(obj)
                            for plugin in plugins:
                                if int(plugin.cmsplugin_ptr_id) in bases:
                                    bases[int(plugin.cmsplugin_ptr_id
                                              )].set_base_attr(plugin)
                                    plugin_list.append(plugin)
                        else:
                            plugin_list = CMSPlugin.objects.filter(
                                page=obj,
                                language=language,
                                placeholder=placeholder_name,
                                parent=None).order_by('position')
                    widget = PluginEditor(attrs={
                        'installed': installed_plugins,
                        'list': plugin_list
                    })
                    form.base_fields[placeholder_name] = CharField(
                        widget=widget, required=False)
        else:
            for name in ['slug', 'title']:
                form.base_fields[name].initial = u''
            form.base_fields['parent'].initial = request.GET.get(
                'target', None)
            form.base_fields['site'].initial = request.session.get(
                'cms_admin_site', None)
            form.base_fields['template'].initial = settings.CMS_TEMPLATES[0][0]
        return form