Пример #1
0
    def post(cls):
        name = request.get_json()["name"]

        if ListModel.find_by_name(name):
            return {"message": NAME_ALREADY_EXISTS.format(name=name)}, 400

        list = ListModel(name=name)
        try:
            list.save_to_db()
        except:
            return {"message": ERROR_INSERTING}, 500

        return list_schema.dump(list), 201
Пример #2
0
    def get(cls):
        name = request.get_json()["name"]

        list = ListModel.find_by_name(name)
        if list:
            return list_schema.dump(list), 200

        return {"message": LIST_NOT_FOUND}, 404
Пример #3
0
 def put(self, list_id):
     ilist = ListModel.find_by_id(list_id)
     ilist_data = list_schema.load(request.get_json())
     if ilist:
         ilist.title = ilist_data.title
     else:
         ilist_data.save_to_db()
     ilist.save_to_db()
     return list_schema.dump(ilist)
Пример #4
0
    def post(self):
        try:
            user = user_schema.load(request.get_json())
        except ValidationError as err:
            return err.messages, 400

        if UserModel.find_by_username(user.username):
            return {"message": "A user with that username already exists"}, 400
   
        user.save_to_db()
        
        thelist = ListModel("Gelen Kutusu")
        thelist.save_to_db()
        permission = ListPermissionModel(user.id, thelist.id)
        
        permission.save_to_db()
        #return {"message": "User created successfully."}, 201
        return perm_schema.dump(permission)
Пример #5
0
    def delete(cls):
        name = request.get_json()["name"]

        list = ListModel.find_by_name(name)
        if list:
            list.delete_from_db()
            return {"message": LIST_DELETED}, 200

        return {"message": LIST_NOT_FOUND}, 404
Пример #6
0
    def list_list(self, request):
        logging.info('list_list()')

        query = ListModel.get_lists()
        lists = [entity.to_message() for entity in query.fetch()]

        listList = ListListResponse()
        listList.lists = lists

        return listList
Пример #7
0
 def get(self):
     items = [item.json() for item in ListModel.find_all()]
     return {"lists":items}
Пример #8
0
 def delete(self, list_id):
     ilist = ListModel.find_by_id(list_id)
     if ilist:
         ilist.delete_from_db()
         return{"message":"list deleted"}, 200
     return{"message":"list not found"}    
Пример #9
0
 def get(self, list_id):
     ilist = ListModel.find_by_id(list_id)
     if ilist:
         return ilist.json()
     return {"message":"not found"}, 404     
Пример #10
0
 def get(cls):
     return {"lists": list_list_schema.dump(ListModel.find_all())}, 200
Пример #11
0
    def list_delete_all(self, request):
        logging.info('list_delete()')

        ListModel.delete_by_id(request)

        return ListListResponse()
Пример #12
0
    def list_insert(self, request):
        logging.info('list_insert()')

        entity = ListModel.put_from_message(request)
        return entity.to_message()
Пример #13
0
    def list_details(self, request):
        logging.info('list_details()')

        list = ListModel.get_details(request)

        return list.to_message()