def retrieve(self, request): try: id = request.params["id"] if id.isdigit(): group = Group.retrieve(int(id)) else: group = Group.retrieve(screen_name=id) return Response.json(group.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def create(self, request): post = request.post() try: group = Group() group.screen_name = post["screen_name"] group.name = post["name"] group.create() return Response.json(group.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def delete(self, request): try: id = request.params["id"] if id.isdigit(): group = Group.retrieve(int(id)) else: group = Group.retrieve(screen_name=id) group.delete() return Response.json({"_id": group._id}) except Exception as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def create(self, request): post = request.post() try: user = User() user.screen_name = post["screen_name"] user.name = post["name"] user.set_password(post["password"]) user.create() return Response.json(user.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def user(self, request): id = request.params['id'] user = User.retrieve(int(id)) boards = [ bg.board for bg in BoardGuest.query.filter(BoardGuest.user == user).all() ] return Response.json(list([board.to_dict() for board in boards]))
def create(self, request): post = request.post() board = Board() board.subject = post['subject'] group = Group.retrieve(int(post['group'])) if 'group' in post else None board.group = group board.private = 'private' in post board.description = post.get('description', None) board.create() return Response.json({"_id": board._id})
def update(self, request): try: post = request.post() id = request.params["id"] if id.isdigit(): group = Group.retrieve(int(id)) else: group = Group.retrieve(screen_name=id) if "screen_name" in post: group.screen_name = post["screen_name"] if "name" in post: group.name = post["name"] group.update() return Response.json(group.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def update(self, request): try: post = request.post() id = request.params["id"] if id.isdigit(): user = User.retrieve(int(id)) else: user = User.retrieve(screen_name=id) if "screen_name" in post: user.screen_name = post["screen_name"] if "name" in post: user.name = post["name"] if "password" in post: user.set_password(post["password"]) user.update() return Response.json(user.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def handle(self, req: Request): manifest = { "name": "Mitama", "short_name": "Mitama", "icons": [{ "src": self.app.convert_fullurl(req, "/static/icon.png"), "sizes": "243x243", "type": "image/png" }], "start_url": "/", "display": "standalone" } return Response.json(manifest)
def list(self, request): groups = Group.list() return Response.json([group.to_dict() for group in groups])
def list(self, request): users = User.list() return Response.json([user.to_dict for user in users])
def list(self, request): boards = Board.query.filter(Board.group == None) return Response.json(list([board.to_dict() for board in boards]))
def group(self, request): id = request.params['id'] group = Group.retrieve(int(id)) boards = Board.query.filter(Board.group == group) return Response.json(list([board.to_dict() for board in boards]))