Example #1
0
    def put(self):
        page = self.load()

        revision = int(self.req.POST["revision"])
        new_body = self.req.POST["body"]
        comment = self.req.POST.get("comment", "")
        preview = self.req.POST.get("preview", "0")
        partial = self.req.GET.get("partial", "all")

        if preview == "1":
            self.res.headers["Content-Type"] = "text/html; charset=utf-8"
            page = page.get_preview_instance(new_body)
            html = template(self.req, "wikipage_bodyonly.html", {"page": page})
            set_response_body(self.res, html, False)
            return

        if not page.can_write(self.user):
            self._403(page)
            return

        try:
            page.update_content(new_body, revision, comment, self.user, partial=partial)
            self.res.headers["X-Message"] = "Successfully updated."

            if partial == "all":
                quoted_path = urllib2.quote(self.path.replace(" ", "_"))
                self.res.status = 303
                restype = get_restype(self.req, "html")
                if restype == "html":
                    self.res.location = str("/" + quoted_path)
                else:
                    self.res.location = str("/%s?_type=%s" % (quoted_path, restype))
            else:
                self.res.status = 200
                self.res.headers["Content-Type"] = "application/json; charset=utf-8"
                self.res.write(json.dumps({"revision": page.revision}))
        except ConflictError as e:
            html = template(self.req, "wikipage.edit.html", {"page": page, "conflict": e})
            self.res.status = 409
            self.res.headers["Content-Type"] = "text/html; charset=utf-8"
            set_response_body(self.res, html, False)
        except ValueError as e:
            html = template(
                self.req,
                "error.html",
                {
                    "page": page,
                    "description": "Cannot accept the data for following reasons",
                    "errors": [e.message],
                    "suggest_link": ("javascript:history.back();", "Go back"),
                },
            )
            self.res.status = 406
            self.res.headers["Content-Type"] = "text/html; charset=utf-8"
            set_response_body(self.res, html, False)
Example #2
0
    def put(self):
        page = self.load()

        revision = int(self.req.POST['revision'])
        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')
        preview = self.req.POST.get('preview', '0')
        partial = self.req.GET.get('partial', 'all')

        if preview == '1':
            self.res['Content-Type'] = 'text/html; charset=utf-8'
            page = page.get_preview_instance(new_body)
            html = template(self.req, 'wikipage_bodyonly.html', {
                'page': page,
            })
            self.res.write(html)
            return self.res

        try:
            page.update_content(new_body, revision, comment, self.req.user, partial=partial)
            self.res['X-Message'] = 'Successfully updated.'

            if partial == 'all':
                quoted_path = urllib2.quote(self.path.encode('utf8').replace(' ', '_'))
                restype = get_restype(self.req, 'html')
                if restype == 'html':
                    self.res = HttpResponseRedirect(str('/' + quoted_path))
                else:
                    self.res = HttpResponseRedirect(str('/%s?_type=%s' % (quoted_path, restype)))
                self.res.status_code = 303
            else:
                self.res.status_code = 200
                self.res['Content-Type'] = 'application/json; charset=utf-8'
                self.res.write(json.dumps({'revision': page.revision}))

            return self.res
        except ConflictError as e:
            html = template(self.req, 'wikipage.edit.html', {'page': page, 'conflict': e})
            self.res.status = 409
            self.res['Content-Type'] = 'text/html; charset=utf-8'
            self.res.write(html)
            return self.res
        except ValueError as e:
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'Cannot accept the data for following reasons',
                'errors': [e.message],
                'suggest_link': ('javascript:history.back();', 'Go back'),
            })
            self.res.status = 406
            self.res['Content-Type'] = 'text/html; charset=utf-8'
            self.res.write(html)
            return self.res
Example #3
0
    def put(self):
        page = self.load()

        revision = int(self.req.POST['revision'])
        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')
        preview = self.req.POST.get('preview', '0')
        partial = self.req.GET.get('partial', 'all')

        if preview == '1':
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            html = template(self.req, 'generic_bodyonly.html', {
                'title': page.title,
                'body': page.preview_rendered_body(new_body)
            })
            set_response_body(self.res, html, False)
            return

        if not page.can_write(self.user):
            self._403(page)
            return

        try:
            page.update_content(new_body, revision, comment, self.user, partial=partial)
            self.res.headers['X-Message'] = 'Successfully updated.'

            if partial == 'all':
                quoted_path = urllib2.quote(self.path.replace(' ', '_'))
                self.res.status = 303
                restype = get_restype(self.req, 'html')
                if restype == 'html':
                    self.res.location = str('/' + quoted_path)
                else:
                    self.res.location = str('/%s?_type=%s' % (quoted_path, restype))
            else:
                self.res.status = 200
                self.res.headers['Content-Type'] = 'application/json; charset=utf-8'
                self.res.write(json.dumps({'revision': page.revision}))
        except ConflictError as e:
            html = template(self.req, 'wikipage.edit.html', {'page': page, 'conflict': e})
            self.res.status = 409
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)
        except ValueError as e:
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'Cannot accept the data for following reasons',
                'errors': [e.message],
                'suggest_link': ('javascript:history.back();', 'Go back'),
            })
            self.res.status = 406
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)
Example #4
0
    def post(self):
        page = self.load()

        if not page.can_write(self.user):
            self._403(page)
            return

        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')

        try:
            page.update_content(page.body + new_body, page.revision, comment, self.user)
            quoted_path = urllib2.quote(self.path.replace(' ', '_'))
            restype = get_restype(self.req, 'html')
            if restype == 'html':
                self.res.location = str('/' + quoted_path)
            else:
                self.res.location = str('/%s?_type=%s' % (quoted_path, restype))
            self.res.status = 303
            self.res.headers['X-Message'] = 'Successfully updated.'
        except ValueError as e:
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'Cannot accept the data for following reasons',
                'errors': [e.message]
            })
            self.res.status = 406
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)
Example #5
0
 def _403(self, page, head=False):
     self.res.status = 403
     self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
     html = template(self.req, 'error.html', {
         'page': page,
         'description': 'You don\'t have a permission',
         'errors': [],
     })
     set_response_body(self.res, html, head)
Example #6
0
 def _403(self, page, head=False):
     self.res.status_code = 403
     self.res['Content-Type'] = 'text/html; charset=utf-8'
     html = template(self.req, 'error.html', {
         'page': page,
         'description': 'You don\'t have a permission',
         'errors': [],
         'suggest_link': ('javascript:history.back();', 'Go back'),
     })
     self.res.write(html)
Example #7
0
 def _403(self, page, head=False):
     self.res.status = 403
     self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
     html = template(
         self.req, 'error.html', {
             'page': page,
             'description': 'You don\'t have a permission',
             'errors': [],
             'suggest_link': ('javascript:history.back();', 'Go back'),
         })
     set_response_body(self.res, html, head)
Example #8
0
 def _403(self, page, head=False):
     self.res.status = 403
     self.res.headers["Content-Type"] = "text/html; charset=utf-8"
     html = template(
         self.req,
         "error.html",
         {
             "page": page,
             "description": "You don't have a permission",
             "errors": [],
             "suggest_link": ("javascript:history.back();", "Go back"),
         },
     )
     set_response_body(self.res, html, head)
Example #9
0
    def delete(self):
        page = self.load()

        try:
            page.delete(self.user)
            self.res.status = 204
        except RuntimeError as e:
            self.res.status = 403
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'You don\'t have a permission to delete the page',
                'errors': [e.message]
            })
            set_response_body(self.res, html, False)
Example #10
0
    def delete(self):
        page = self.load()

        try:
            page.delete(self.user)
            self.res.status = 204
        except RuntimeError as e:
            self.res.status = 403
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'You don\'t have a permission to delete the page',
                'errors': [e.message],
                'suggest_link': ('javascript:history.back();', 'Go back'),
            })
            set_response_body(self.res, html, False)
Example #11
0
    def delete(self):
        page = self.load()

        try:
            page.delete(self.user)
            self.res.status = 204
        except RuntimeError as e:
            self.res.status = 403
            html = template(
                self.req, 'error.html', {
                    'page': page,
                    'description':
                    'You don\'t have a permission to delete the page',
                    'errors': [e.message],
                    'suggest_link': ('javascript:history.back();', 'Go back'),
                })
            set_response_body(self.res, html, False)
Example #12
0
    def post(self):
        page = self.load()

        if not page.can_write(self.user):
            self._403(page)
            return

        new_body = self.req.POST["body"]
        comment = self.req.POST.get("comment", "")

        view = self.req.GET.get("view", self.default_view)
        restype = get_restype(self.req, "html")

        # POST to edit form, not content
        if restype == "html" and view == "edit":
            if page.revision == 0:
                page.body = new_body
            representation = self.get_representation(page)
            representation.respond(self.res, head=False)
            return

        # POST to content
        try:
            page.update_content(page.body + new_body, page.revision, comment, self.user)
            quoted_path = urllib2.quote(self.path.replace(" ", "_"))
            if restype == "html":
                self.res.location = str("/" + quoted_path)
            else:
                self.res.location = str("/%s?_type=%s" % (quoted_path, restype))
            self.res.status = 303
            self.res.headers["X-Message"] = "Successfully updated."
        except ValueError as e:
            html = template(
                self.req,
                "error.html",
                {
                    "page": page,
                    "description": "Cannot accept the data for following reasons",
                    "errors": [e.message],
                    "suggest_link": ("javascript:history.back();", "Go back"),
                },
            )
            self.res.status = 406
            self.res.headers["Content-Type"] = "text/html; charset=utf-8"
            set_response_body(self.res, html, False)
Example #13
0
    def post(self):
        page = self.load()

        if not page.can_write(self.user):
            self._403(page)
            return

        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')

        view = self.req.GET.get('view', self.default_view)
        restype = get_restype(self.req, 'html')

        # POST to edit form, not content
        if restype == 'html' and view == 'edit':
            if page.revision == 0:
                page.body = new_body
            representation = self.get_representation(page)
            representation.respond(self.res, head=False)
            return

        # POST to content
        try:
            page.update_content(page.body + new_body, page.revision, comment,
                                self.user)
            quoted_path = urllib2.quote(self.path.replace(' ', '_'))
            if restype == 'html':
                self.res.location = str('/' + quoted_path)
            else:
                self.res.location = str('/%s?_type=%s' %
                                        (quoted_path, restype))
            self.res.status = 303
            self.res.headers['X-Message'] = 'Successfully updated.'
        except ValueError as e:
            html = template(
                self.req, 'error.html', {
                    'page': page,
                    'description':
                    'Cannot accept the data for following reasons',
                    'errors': [e.message],
                    'suggest_link': ('javascript:history.back();', 'Go back'),
                })
            self.res.status = 406
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)
Example #14
0
    def delete(self):
        page = self.load()

        try:
            page.delete(self.user)
            self.res.status = 204
        except RuntimeError as e:
            self.res.status = 403
            html = template(
                self.req,
                "error.html",
                {
                    "page": page,
                    "description": "You don't have a permission to delete the page",
                    "errors": [e.message],
                    "suggest_link": ("javascript:history.back();", "Go back"),
                },
            )
            set_response_body(self.res, html, False)
Example #15
0
    def post(self):
        page = self.load()

        if not page.can_write(self.req.user):
            self._403(page)
            return

        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')

        view = self.req.GET.get('view', self.default_view)
        restype = get_restype(self.req, 'html')

        # POST to edit form, not content
        if restype == 'html' and view == 'edit':
            if page.revision == 0:
                page.body = new_body
            representation = self.get_representation(page)
            representation.respond(self.res, head=False)
            return

        # POST to content
        try:
            page.update_content(page.body + new_body, page.revision, comment, self.req.user)
            quoted_path = urllib2.quote(self.path.replace(' ', '_'))
            if restype == 'html':
                self.res.location = str('/' + quoted_path)
            else:
                self.res.location = str('/%s?_type=%s' % (quoted_path, restype))
            self.res.status = 303
            self.res['X-Message'] = 'Successfully updated.'
        except ValueError as e:
            html = template(self.req, 'error.html', {
                'page': page,
                'description': 'Cannot accept the data for following reasons',
                'errors': [e.message],
                'suggest_link': ('javascript:history.back();', 'Go back'),
            })
            self.res.status = 406
            self.res['Content-Type'] = 'text/html; charset=utf-8'
            self.res.write(html)
        return self.res
Example #16
0
    def put(self):
        page = self.load()

        revision = int(self.req.POST['revision'])
        new_body = self.req.POST['body']
        comment = self.req.POST.get('comment', '')
        preview = self.req.POST.get('preview', '0')
        partial = self.req.GET.get('partial', 'all')

        if preview == '1':
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            page = page.get_preview_instance(new_body)
            html = template(self.req, 'wikipage_bodyonly.html', {
                'page': page,
            })
            set_response_body(self.res, html, False)
            return

        if not page.can_write(self.user):
            self._403(page)
            return

        try:
            page.update_content(new_body,
                                revision,
                                comment,
                                self.user,
                                partial=partial)
            self.res.headers['X-Message'] = 'Successfully updated.'

            if partial == 'all':
                quoted_path = urllib2.quote(self.path.replace(' ', '_'))
                self.res.status = 303
                restype = get_restype(self.req, 'html')
                if restype == 'html':
                    self.res.location = str('/' + quoted_path)
                else:
                    self.res.location = str('/%s?_type=%s' %
                                            (quoted_path, restype))
            else:
                self.res.status = 200
                self.res.headers[
                    'Content-Type'] = 'application/json; charset=utf-8'
                self.res.write(json.dumps({'revision': page.revision}))
        except ConflictError as e:
            html = template(self.req, 'wikipage.edit.html', {
                'page': page,
                'conflict': e
            })
            self.res.status = 409
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)
        except ValueError as e:
            html = template(
                self.req, 'error.html', {
                    'page': page,
                    'description':
                    'Cannot accept the data for following reasons',
                    'errors': [e.message],
                    'suggest_link': ('javascript:history.back();', 'Go back'),
                })
            self.res.status = 406
            self.res.headers['Content-Type'] = 'text/html; charset=utf-8'
            set_response_body(self.res, html, False)