Exemplo n.º 1
0
    def POST(self, path):
        p = db.get_version(path)
        if not p:
            raise web.seeother(path)

        i = web.input('permission.key', 'child_permission.key')
        q = {
            'key': path,
            'permission': {
                'connect': 'update',
                'key': i['permission.key'] or None,
            },
            'child_permission': {
                'connect': 'update',
                'key': i['child_permission.key'] or None,
            },
        }

        try:
            web.ctx.site.write(q)
        except Exception as e:
            import traceback

            traceback.print_exc(e)
            add_flash_message('error', str(e))
            return render.permission(p)

        raise web.seeother(web.changequery({}, m='permission'))
Exemplo n.º 2
0
 def POST(self):
     i = web.input("oldpassword", "password", "password2")
     f = forms.login_preferences()
     if not f.validates(i):
         return render.login_preferences(f)
     else:
         try:
             user = web.ctx.site.update_user(i.oldpassword, i.password, None)
         except ClientException as e:
             f.note = str(e)
             return render.login_preferences(f)
         add_flash_message('info', 'Password updated successfully.')
         raise web.seeother("/account/preferences")
Exemplo n.º 3
0
    def GET(self, path):
        i = web.input(v=None, t=None)

        if not web.ctx.site.can_write(path):
            return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".")

        if i.v is not None and safeint(i.v, None) is None:
            raise web.seeother(web.changequery(v=None))

        p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path))

        if i.t:
            type = db.get_type(i.t)
            if type is None:
                add_flash_message('error', 'Unknown type: ' + i.t)
            else:
                p.type = type

        return render.editpage(p)
Exemplo n.º 4
0
    def POST(self, path):
        i = web.input(_method='post')
        i = web.storage(helpers.unflatten(i))
        i.key = path

        _ = web.storage(
            (k, i.pop(k)) for k in list(i.keys()) if k.startswith('_'))
        action = self.get_action(_)
        comment = _.get('_comment', None)

        for k, v in i.items():
            i[k] = self.trim(v)

        p = web.ctx.site.get(path) or web.ctx.site.new(path, {})
        p.update(i)

        if action == 'preview':
            p['comment_'] = comment
            return render.editpage(p, preview=True)
        elif action == 'save':
            try:
                p._save(comment)
                path = web.input(
                    _method='GET',
                    redirect=None).redirect or web.changequery(query={})
                raise web.seeother(path)
            except (ClientException, db.ValidationException) as e:
                add_flash_message('error', str(e))
                p['comment_'] = comment
                return render.editpage(p)
        elif action == 'delete':
            q = dict(key=i['key'], type=dict(key='/type/delete'))

            try:
                web.ctx.site.save(q, comment)
            except (ClientException, db.ValidationException) as e:
                add_flash_message('error', str(e))
                p['comment_'] = comment
                return render.editpage(p)

            raise web.seeother(web.changequery(query={}))