コード例 #1
0
ファイル: manifest.py プロジェクト: ionyse/ionyweb
    def get(self, request):
        """
        Change and preview the layout of a placeholder
        """
        layout_section_slug = request.GET.get('layout_section_slug', None)
        layout_template_slug = request.GET.get('layout_template_slug', None)
        plugin_relation_default = request.GET.getlist('plugin_relation_default[]')
        plugin_relation_default_placeholder = request.GET.getlist('plugin_relation_default_placeholder[]')

        if not layout_section_slug:
            raise _400_BAD_REQUEST

        rendering_context = RenderingContext(request)
        html_layout_rendering = rendering_context.get_html_layout(layout_section_slug,
                                                                  template_file_preview=layout_template_slug)
        
        # Make data for refresh default
        plugin_relation_default_data = []
        for i in xrange(len(plugin_relation_default)):
            plugin_relation_default_data.append({
                    'id': plugin_relation_default[i],
                    'layout_slug': plugin_relation_default_placeholder[i].split(settings.HTML_ID_PLACEHOLDER)[0]})
        # Refresh of default layout section
        layout_default_infos_refresh = rendering_context.refresh_default(layout_section_slug,
                                                                         plugin_relation_default_data)
        
        response = Response(status.HTTP_200_OK,
                            {"msg": MESSAGES.get('layout_edit_succes', ""), 
                             'default_to_add': layout_default_infos_refresh['add'],
                             'default_to_delete': layout_default_infos_refresh['delete'],
                             'layout_section_slug': layout_section_slug,
                             'html': html_layout_rendering})
        return self.render(response)
コード例 #2
0
ファイル: plugin.py プロジェクト: manlan2/ionyweb
    def post(self, request, relation_html_id):
        """
        Update plugin modifications.

        If modifications are correct return confirmation message
        and the new render of the layout section;
        if not, return the plugin form with error messages

        Parameters :
          - relation_html_id : PluginRelation Id

        POST parameters :
          - form fields
          - csrf token
        """
        pk = check_object_html_id(relation_html_id)[1]
        try:
            plugin_relation = PluginRelation.objects.filter(
                pages__website__exact=request.website, 
                id__exact=pk)[0]
        except IndexError:
            raise Http404
        # Create the plugin form
        plugin = plugin_relation.content_object
        PluginFormClass = plugin.get_admin_form()
        form = PluginFormClass(request.POST, instance=plugin)

        if form.is_valid():
            plugin = form.save()
            placeholder_slug_items = check_placeholder_html_id(
                plugin_relation.placeholder_slug)
            layout_section_slug = placeholder_slug_items[0]
            rendering_context = RenderingContext(request)
            html_rendering = rendering_context.get_html_layout(layout_section_slug)

            response = Response(status.HTTP_200_OK,
                                {"msg": MESSAGES.get('item_edit_success',""),
                                 'html': html_rendering,
                                 'layout_section_slug': layout_section_slug})

            return self.render(response)
        
        else:            
            # Invalid form => 400 BAD REQUEST
            # with forms (and errors..)
            html = render_to_string('administration/plugin/plugin-edit.html',
                                    {'form': form,
                                     'plugin': plugin,
                                     'plugin_relation_html_id': relation_html_id},
                                    context_instance = RequestContext(request))
            
            raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                {'msg': MESSAGES.get('invalid_data', ""),
                                 'html': html})
コード例 #3
0
ファイル: page.py プロジェクト: ionyse/ionyweb
    def get(self, request):

        layout_section_slug = request.GET.get('layout_section_slug', None)

        if not layout_section_slug:            
            response = Response(status.HTTP_400_BAD_REQUEST,
                                {"msg": MESSAGES.get('default_error', "")})
            return self.render(response)

        rendering_context = RenderingContext(request)
        html_rendering = rendering_context.get_html_layout(layout_section_slug)

        response = Response(status.HTTP_200_OK,
                            {'html': html_rendering,
                             'msg': MESSAGES.get('items_edit_success', "")})

        return self.render(response)
コード例 #4
0
ファイル: page.py プロジェクト: manlan2/ionyweb
    def get(self, request):

        layout_section_slug = request.GET.get('layout_section_slug', None)

        if not layout_section_slug:
            response = Response(status.HTTP_400_BAD_REQUEST,
                                {"msg": MESSAGES.get('default_error', "")})
            return self.render(response)

        rendering_context = RenderingContext(request)
        html_rendering = rendering_context.get_html_layout(layout_section_slug)

        response = Response(status.HTTP_200_OK, {
            'html': html_rendering,
            'msg': MESSAGES.get('items_edit_success', "")
        })

        return self.render(response)
コード例 #5
0
ファイル: apps.py プロジェクト: ionyse/ionyweb
    def post(self, request, page_pk=None):
        """
        Save App Page modifications.

        If correct return confirmation message
        if not, return the form with error messages
        """
        if page_pk is not None:
            try:
                page = request.website.pages.select_related()\
                    .get(pk=page_pk)
                app_page = page.app_page_object
            except Page.DoesNotExist:
                raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                    {'msg': MESSAGES.get('default_error', "")})
        else:
            app_page = request.page.app_page_object
            page = request.page

        # Page App Admin Form
        PageAppForm = app_page.get_admin_form()
        form = PageAppForm(request.POST, instance=app_page)
            
        if form.is_valid():
            new_app_page = form.save()
            # If page is the current page,
            # refresh the layout section
            if request.page == page:
                # Get layout slug
                placeholder_slug_items = check_placeholder_html_id(
                    page.placeholder_slug)
                layout_section_slug = placeholder_slug_items[0]
                # Rendering layout section
                rendering_context = RenderingContext(request)
                html_rendering = rendering_context.get_html_layout(
                    layout_section_slug)
                # Send response
                data_context = {'msg': MESSAGES.get('app_edit_success', ""),
                                'html': html_rendering,
                                'layout_section_slug': layout_section_slug}
                # Check if the page manager have to be displayed
                if page_pk:
                    data_context['refresh_pages_list'] = True
                    
                response = Response(status.HTTP_200_OK,
                                    data_context)
            else:
                data_context = {'msg': MESSAGES.get('app_edit_success', "")}
                # Check if the page manager have to be displayed
                if page_pk:
                    data_context['refresh_pages_list'] = True
                response = Response(status.HTTP_200_OK,
                                    data_context)
            return self.render(response)
            # render_page = page.render_page(request)

            # if render_page.status_code == 200:
            #     response = Response(status.HTTP_200_OK,
            #                         {"msg": MESSAGES.get('app_edit_success', ""),
            #                          'html': render_page.content,
            #                          'medias': render_page.medias})
            # elif render_page.status_code in [301, 302]:
            #     response = Response(status.HTTP_202_ACCEPTED,
            #                         {"msg": MESSAGES.get('redirection', ""),
            #                          'location': render_page['location']})

        # If form not valid => reload the edit form with messages
        else:
            data_context = {'form': form,
                            'object': app_page}
            if page_pk:
                data_context['page'] = page

            html = render_to_string('administration/app/app-edit.html',
                                    data_context,
                                    context_instance=RequestContext(request))
            raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                {'msg': MESSAGES.get('invalid_data', ""),
                                 'html': html})
コード例 #6
0
ファイル: plugin.py プロジェクト: manlan2/ionyweb
    def put(self, request):
        """
        Create a new plugin.

        If modifications are correct return confirmation message
        and the new render of the layout section;
        if not, return the plugin form with error messages

        PUT parameters :
          - placeholder_id : Html ID of the placeholder, e.g. 'content-placeholder-1'.
          - plugin_type    : Content type ID of the new plugin.
          - form fields
          - csrf token
        """
        # Get PUT parameters
        request.PUT = self.DATA.copy() 

        placeholder_html_id = request.PUT.get('placeholder_id', None)
        plugin_type    = request.PUT.get('plugin_type', None)

        if placeholder_html_id and plugin_type:
            # Check if placeholder ID is valid
            placeholder_slug_items = check_placeholder_html_id(placeholder_html_id)
            layout_section_slug = placeholder_slug_items[0]
            # Get form of the plugin type
            try:
                content_type = CTA().get_for_pk(plugin_type)
            except ContentType.DoesNotExist:
                raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                    {'msg': MESSAGES.get('default_error', "")})

            PluginClass     = content_type.model_class()
            plugin          = PluginClass()
            PluginFormClass = plugin.get_admin_form()
            form            = PluginFormClass(request.PUT, instance=plugin)

            if form.is_valid():
                # Creation of the new plugin
                new_plugin = form.save()
                # Creation of the relation
                display_on_new_pages = (not is_page_placeholder_html_id(placeholder_html_id))
                relation = PluginRelation.objects.create(content_object=new_plugin,
                                                         placeholder_slug= placeholder_html_id,
                                                         display_on_new_pages=display_on_new_pages)
                relation.pages.add(request.page)

                # At the moment, we displayed it on everypage
                if display_on_new_pages:
                    for page in request.website.pages.all():
                        relation.pages.add(page)
                
                # Set right order
                try:
                    last_relation = PluginRelation.objects.filter(
                        pages=request.page,
                        placeholder_slug=placeholder_html_id).order_by('-plugin_order')[0]
                    plugin_order = last_relation.plugin_order + 10
                except IndexError:
                    plugin_order = 0
                relation.plugin_order = plugin_order
                # Saving modifications
                relation.save()

                rendering_context = RenderingContext(request)
                plugin_html_medias = rendering_context\
                    .get_html_medias_for_plugin_relation(relation)
                html_rendering = rendering_context.get_html_layout(layout_section_slug)
                
                # Sending response
                response = Response(status.HTTP_200_OK,
                                    {'msg': MESSAGES.get('item_edit_success', ''),
                                     'html': html_rendering,
                                     'layout_section_slug': layout_section_slug,
                                     'medias': plugin_html_medias})
                return self.render(response)
            
            # Invalid Form => 400 BAD REQUEST
            else:
                html = render_to_string('administration/plugin/plugin-create.html',
                                        {'form': form,
                                         'placeholder_id': placeholder_html_id,
                                         'plugin_type': plugin_type},
                                       context_instance=RequestContext(request))
                raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                    {'msg': MESSAGES.get('invalid_data', ""),
                                     'html': html})
        # Bad parameters => 400 BAD REQUEST
        else:
            raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                {'msg': MESSAGES.get('default_error', "")})
コード例 #7
0
    def post(self, request, page_pk=None):
        """
        Save App Page modifications.

        If correct return confirmation message
        if not, return the form with error messages
        """
        if page_pk is not None:
            try:
                page = request.website.pages.select_related()\
                    .get(pk=page_pk)
                app_page = page.app_page_object
            except Page.DoesNotExist:
                raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
                                    {'msg': MESSAGES.get('default_error', "")})
        else:
            app_page = request.page.app_page_object
            page = request.page

        # Page App Admin Form
        PageAppForm = app_page.get_admin_form()
        form = PageAppForm(request.POST, instance=app_page)

        if form.is_valid():
            new_app_page = form.save()
            # If page is the current page,
            # refresh the layout section
            if request.page == page:
                # Get layout slug
                placeholder_slug_items = check_placeholder_html_id(
                    page.placeholder_slug)
                layout_section_slug = placeholder_slug_items[0]
                # Rendering layout section
                rendering_context = RenderingContext(request)
                html_rendering = rendering_context.get_html_layout(
                    layout_section_slug)
                # Send response
                data_context = {
                    'msg': MESSAGES.get('app_edit_success', ""),
                    'html': html_rendering,
                    'layout_section_slug': layout_section_slug
                }
                # Check if the page manager have to be displayed
                if page_pk:
                    data_context['refresh_pages_list'] = True

                response = Response(status.HTTP_200_OK, data_context)
            else:
                data_context = {'msg': MESSAGES.get('app_edit_success', "")}
                # Check if the page manager have to be displayed
                if page_pk:
                    data_context['refresh_pages_list'] = True
                response = Response(status.HTTP_200_OK, data_context)
            return self.render(response)
            # render_page = page.render_page(request)

            # if render_page.status_code == 200:
            #     response = Response(status.HTTP_200_OK,
            #                         {"msg": MESSAGES.get('app_edit_success', ""),
            #                          'html': render_page.content,
            #                          'medias': render_page.medias})
            # elif render_page.status_code in [301, 302]:
            #     response = Response(status.HTTP_202_ACCEPTED,
            #                         {"msg": MESSAGES.get('redirection', ""),
            #                          'location': render_page['location']})

        # If form not valid => reload the edit form with messages
        else:
            data_context = {'form': form, 'object': app_page}
            if page_pk:
                data_context['page'] = page

            html = render_to_string('administration/app/app-edit.html',
                                    data_context,
                                    context_instance=RequestContext(request))
            raise ErrorResponse(status.HTTP_400_BAD_REQUEST, {
                'msg': MESSAGES.get('invalid_data', ""),
                'html': html
            })