示例#1
0
文件: resources.py 项目: lamboy/yoda
    def get(self, id):

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)

        return self.response(user_group.to_dict())
示例#2
0
文件: resources.py 项目: lamboy/yoda
    def delete(self, id):

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)
        user_group_dao.delete(user_group)

        return self.response({}, http.NO_CONTENT_204)
示例#3
0
文件: resources.py 项目: lamboy/yoda
    def post(self):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, required=True, location='json')
        args = parser.parse_args()

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.create(**args)

        return self.response(user_group.to_dict(), http.CREATED_201)
示例#4
0
文件: resources.py 项目: lamboy/yoda
    def get(self):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, location='args')
        args = parser.parse_args()

        user_group_dao = UserGroupDao(self.db_session())
        user_groups = user_group_dao.retrieve_all(**args)
        result = [user_group.to_dict() for user_group in user_groups]

        return self.response(result)
示例#5
0
文件: resources.py 项目: lamboy/yoda
    def delete(self, id, user_id):

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)

        user_dao = UserDao(self.db_session())
        user = user_dao.retrieve(id=user_id)
        if user is None:
            return self.error_response('User {} not found'.format(id), http.NOT_FOUND_404)

        if user in user_group.users:
            user_group.users.remove(user)
            user_group = user_group_dao.save(user_group)

        return self.response(user_group.to_dict())
示例#6
0
文件: resources.py 项目: lamboy/yoda
    def put(self, id):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, location='json')
        parser.add_argument('is_visible', type=bool, location='json')
        args = parser.parse_args()

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)

        if args.get('name'):
            user_group.name = args['name']

        user_group = user_group_dao.save(user_group)

        return self.response(user_group.to_dict())