示例#1
0
文件: page.py 项目: manlan2/ionyweb
    def get(self, request, pk=None):
        """
        Return creation or edition form if pk is provided
        """
        if pk is None:
            default_data = {
                'app_page_type': CTA().get_for_names("page_text",
                                                     "pageapp_text")
            }

            if 'parent' in request.GET and request.GET['parent'] != '0':
                default_data['parent'] = request.GET['parent']
            form = PageWAForm(initial=default_data)

            html = render_to_string('administration/page/page-create.html', {
                'form': form,
            },
                                    context_instance=RequestContext(request))

            response = Response(status.HTTP_200_OK, {"html": html})
            return self.render(response)
        else:
            page = get_object_or_404(request.website.pages, pk=pk)
            form = PageWAForm(instance=page)
            html = render_to_string('administration/page/page-edit.html', {
                'form': form,
                'page': page
            },
                                    context_instance=RequestContext(request))
            response = Response(status.HTTP_200_OK, {"html": html})
            return self.render(response)
示例#2
0
文件: page.py 项目: manlan2/ionyweb
    def put(self, request, pk=None):
        post_values = self.DATA.copy()
        post_values['website'] = request.website.id
        form = PageWAForm(post_values)
        if form.is_valid():
            page = form.save()

            # Add the new page on auto_display PluginRelation
            plugins_relation = PluginRelation.objects.filter(
                display_on_new_pages=True, pages__website=request.website)

            for plugin_relation in plugins_relation:
                plugin_relation.pages.add(page)

            response = Response(
                status.HTTP_202_ACCEPTED, {
                    "msg": MESSAGES.get('redirection', ""),
                    'location': page.get_absolute_url()
                })
        else:
            content = render_to_string(
                'administration/page/page-create.html', {
                    'form': form,
                },
                context_instance=RequestContext(request))
            response = Response(status.HTTP_400_BAD_REQUEST, {
                "html": content,
                "msg": MESSAGES.get('default_error', "")
            })
        return self.render(response)
示例#3
0
文件: page.py 项目: ionyse/ionyweb
    def put(self, request, pk=None):
        post_values = self.DATA.copy()
        post_values['website'] = request.website.id
        form = PageWAForm(post_values)
        if form.is_valid():
            page = form.save()

            # Add the new page on auto_display PluginRelation
            plugins_relation = PluginRelation.objects.filter(display_on_new_pages=True, pages__website=request.website)

            for plugin_relation in plugins_relation:
                plugin_relation.pages.add(page)

            response = Response(status.HTTP_202_ACCEPTED,
                                {"msg": MESSAGES.get('redirection', ""),
                                 'location': page.get_absolute_url()})
        else:
            content = render_to_string('administration/page/page-create.html',
                                    {'form': form,},
                                    context_instance = RequestContext(request))
            response = Response(status.HTTP_400_BAD_REQUEST,
                                {"html": content,
                                 "msg": MESSAGES.get('default_error', "")})
        return self.render(response)
示例#4
0
文件: page.py 项目: ionyse/ionyweb
    def post(self, request, pk):
        """
        Modify the page
        """
        # Get page which is currently updated
        page = get_object_or_404(request.website.pages, pk=pk)
        # Saving url of current page
        old_url_current_page = request.page.get_absolute_url()
        # Settings Refresh
        refresh_manager = False
        refresh_page = False
        msg_user = None
        # ----------------------
        # Moving Page Management
        # ----------------------
        if 'move' in request.POST:
            if 'previous' in request.POST:
                page_top = get_object_or_404(request.website.pages, pk=request.POST['previous'])
                page.move_to(page_top, 'right')
            else:
                if 'next' in request.POST:
                    page_top = get_object_or_404(request.website.pages, pk=request.POST['next'])
                    page.move_to(page_top, 'left')
                else:
                    if 'parent' in request.POST:
                        page_top = get_object_or_404(request.website.pages, pk=request.POST['parent'])
                        page.move_to(page_top, 'first-child')
            # We save updates.
            page.save()
            # Ask refresh manager
            refresh_manager = True
            # Messgae fo user
            msg_user = MESSAGES.get('items_move_success', '')
        # ----------------------
        # Settings page as draft
        # ----------------------
        elif 'draft' in request.POST:
            page.draft = not page.draft
            page.save()
            refresh_manager = True
            msg_user = MESSAGES.get('page_draft_toggle', '') 
        # ----------------------
        # Updating settings page
        # ----------------------
        else:
            # Get POST values
            post_values = request.POST.copy()
            post_values['website'] = request.website.id
            # Creation of form
            form = PageWAForm(post_values, instance=page)
            if form.is_valid():
                page = form.save()
                # We ask content updating
                if page == request.page:
                    refresh_page = True
                # Message for user
                msg_user = MESSAGES.get('app_edit_success', '')
            else:
                # We reload the edit form with errors
                content = render_to_string('administration/page/page-edit.html',
                                           {'form': form, 
                                            'page': page},
                                           context_instance = RequestContext(request))
                response = Response(status.HTTP_203_NON_AUTHORITATIVE_INFORMATION,
                                    {"html": content,
                                     "msg": MESSAGES.get('default_error', "")})
                return self.render(response)
        # ---------------
        # Refresh Website
        # ---------------
        # Update cache for current page displayed.
        request.page = get_object_or_404(request.website.pages, pk=request.page.id)
        # Check if we need reload current page
        # if current url changed or refresh content asked.
        new_url_current_page = request.page.get_absolute_url()
        if old_url_current_page != new_url_current_page or refresh_page:
            response = Response(status.HTTP_202_ACCEPTED,
                                {'location': new_url_current_page})
            return self.render(response)
        # Else we refresh only page manager and navigation.
        # Page manager:
        if refresh_manager:
            pages_list = request.website.pages.all()
            page_manager_html = render_to_string('administration/page/page-list.html',
                                                 {'pages': pages_list,},
                                                 context_instance = RequestContext(request))
        else:
            page_manager_html = None

        navigation_html = RenderingContext(request).html_navigation
        # Response
        response = Response(status.HTTP_200_OK,
                            {"manager_html": page_manager_html,
                             "navigation_html": navigation_html,
                             # "page_html": page_content_html,
                             "msg": msg_user})
        return self.render(response)
示例#5
0
文件: page.py 项目: manlan2/ionyweb
    def post(self, request, pk):
        """
        Modify the page
        """
        # Get page which is currently updated
        page = get_object_or_404(request.website.pages, pk=pk)
        # Saving url of current page
        old_url_current_page = request.page.get_absolute_url()
        # Settings Refresh
        refresh_manager = False
        refresh_page = False
        msg_user = None
        # ----------------------
        # Moving Page Management
        # ----------------------
        if 'move' in request.POST:
            if 'previous' in request.POST:
                page_top = get_object_or_404(request.website.pages,
                                             pk=request.POST['previous'])
                page.move_to(page_top, 'right')
            else:
                if 'next' in request.POST:
                    page_top = get_object_or_404(request.website.pages,
                                                 pk=request.POST['next'])
                    page.move_to(page_top, 'left')
                else:
                    if 'parent' in request.POST:
                        page_top = get_object_or_404(request.website.pages,
                                                     pk=request.POST['parent'])
                        page.move_to(page_top, 'first-child')
            # We save updates.
            page.save()
            # Ask refresh manager
            refresh_manager = True
            # Messgae fo user
            msg_user = MESSAGES.get('items_move_success', '')
        # ----------------------
        # Settings page as draft
        # ----------------------
        elif 'draft' in request.POST:
            page.draft = not page.draft
            page.save()
            refresh_manager = True
            msg_user = MESSAGES.get('page_draft_toggle', '')
        # ----------------------
        # Updating settings page
        # ----------------------
        else:
            # Get POST values
            post_values = request.POST.copy()
            post_values['website'] = request.website.id
            # Creation of form
            form = PageWAForm(post_values, instance=page)
            if form.is_valid():
                page = form.save()
                # We ask content updating
                if page == request.page:
                    refresh_page = True
                # Message for user
                msg_user = MESSAGES.get('app_edit_success', '')
            else:
                # We reload the edit form with errors
                content = render_to_string(
                    'administration/page/page-edit.html', {
                        'form': form,
                        'page': page
                    },
                    context_instance=RequestContext(request))
                response = Response(
                    status.HTTP_203_NON_AUTHORITATIVE_INFORMATION, {
                        "html": content,
                        "msg": MESSAGES.get('default_error', "")
                    })
                return self.render(response)
        # ---------------
        # Refresh Website
        # ---------------
        # Update cache for current page displayed.
        request.page = get_object_or_404(request.website.pages,
                                         pk=request.page.id)
        # Check if we need reload current page
        # if current url changed or refresh content asked.
        new_url_current_page = request.page.get_absolute_url()
        if old_url_current_page != new_url_current_page or refresh_page:
            response = Response(status.HTTP_202_ACCEPTED,
                                {'location': new_url_current_page})
            return self.render(response)
        # Else we refresh only page manager and navigation.
        # Page manager:
        if refresh_manager:
            pages_list = request.website.pages.all()
            page_manager_html = render_to_string(
                'administration/page/page-list.html', {
                    'pages': pages_list,
                },
                context_instance=RequestContext(request))
        else:
            page_manager_html = None

        navigation_html = RenderingContext(request).html_navigation
        # Response
        response = Response(
            status.HTTP_200_OK,
            {
                "manager_html": page_manager_html,
                "navigation_html": navigation_html,
                # "page_html": page_content_html,
                "msg": msg_user
            })
        return self.render(response)