Пример #1
0
 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,
         })
Пример #2
0
 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,
         })
Пример #3
0
 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,
         })
Пример #4
0
 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,
         })
Пример #5
0
 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]))
Пример #6
0
 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})
Пример #7
0
 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,
         })
Пример #8
0
 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,
         })
Пример #9
0
 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)
Пример #10
0
 def list(self, request):
     groups = Group.list()
     return Response.json([group.to_dict() for group in groups])
Пример #11
0
 def list(self, request):
     users = User.list()
     return Response.json([user.to_dict for user in users])
Пример #12
0
 def list(self, request):
     boards = Board.query.filter(Board.group == None)
     return Response.json(list([board.to_dict() for board in boards]))
Пример #13
0
 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]))