Example #1
0
class ProjectList(Resource):
    def __init__(self, db=None):
        self.project_list = ProjectRecordList(db)

    def get(self):
        data = [proj.to_json() for proj in self.project_list.get_all()]
        cnt = len(data)
        return {'items': data}, 201, {'Access-Control-Allow-Origin': '*'}

    def post(self):
        args = request.values
        proj = ProjectRecord()
        proj.title = args['title']
        self.project_list.save(proj)
        return proj.to_json(), 201
Example #2
0
class ProjectList(Resource):
    def __init__(self, db=None):
        self.project_list = ProjectRecordList(db)

    def get(self):
        data = [proj.to_json() for proj in self.project_list.get_all()]
        cnt = len(data)
        return {'items':data}, 201, {'Access-Control-Allow-Origin': '*'}

    def post(self):
        args = request.values
        proj = ProjectRecord()
        proj.title = args['title']
        self.project_list.save(proj)
        return proj.to_json(), 201
Example #3
0
class Project(Resource):
    def __init__(self, db=None):
        self.project_list = ProjectRecordList(db)

    def get(self, project_id):
        proj = self.project_list.get_one(project_id)
        if proj:
            return proj.to_json(), 200, {'Access-Control-Allow-Origin': '*'}
        abort(404, message="Project {} doesn't exist".format(project_id))

    def delete(self, project_id):
        self.project_list.delete_one(project_id)
        return '', 204, {'Access-Control-Allow-Origin': '*'}

    def put(self, project_id):
        proj = self.project_list.get_one(project_id)
        if proj:
            args = request.values
            proj.title = args['title']
            self.project_list.save(proj)
            return proj.to_json(), 201, {'Access-Control-Allow-Origin': '*'}
        abort(404, message="Project {} doesn't exist".format(project_id))
Example #4
0
class Project(Resource):
    def __init__(self, db=None):
        self.project_list = ProjectRecordList(db)

    def get(self, project_id):
        proj = self.project_list.get_one(project_id);
        if proj:
            return proj.to_json(), 200, {'Access-Control-Allow-Origin': '*'}
        abort(404, message="Project {} doesn't exist".format(project_id))

    def delete(self, project_id):
        self.project_list.delete_one(project_id)
        return '', 204, {'Access-Control-Allow-Origin': '*'}

    def put(self, project_id):
        proj = self.project_list.get_one(project_id);
        if proj:
            args = request.values
            proj.title = args['title']
            self.project_list.save(proj)
            return proj.to_json(), 201, {'Access-Control-Allow-Origin': '*'}
        abort(404, message="Project {} doesn't exist".format(project_id))