def post(self): json_data = request.get_json() if not json_data: raise RequestException("No input data", 400) try: data = enrollment_schema.load(json_data) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) enrollment = Enrollment.create(**data) result = enrollment_schema.dump(enrollment) response = jsonify( {APIConst.MESSAGE: 'created new enrollment', APIConst.DATA: result}) return response
def post(self): json_data = request.get_json() if not json_data: raise RequestException("No input data", 400) try: data = notif_delivery_schema.load(json_data) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) delivery = NotificationDelivery.create(**data) result = notif_delivery_schema.dump(delivery) response = jsonify({ APIConst.MESSAGE: 'created new notification delivery', APIConst.DATA: result }) return response
def post(self): json_data = request.get_json() if not json_data: raise RequestException("No input data", 400) try: data = class_session_schema.load(json_data) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) class_session = ClassSession.create(**data) result = class_session_schema.dump(class_session) response = jsonify( {APIConst.MESSAGE: 'created new class session', APIConst.DATA: result}) return response
def post(self): json_data = request.get_json() if not json_data: raise RequestException("No input data", 400) try: data = orgper_schema.load(json_data) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) orgper = OrganizationPersonAssociation.create(**data) result = orgper_schema.dump(orgper) response = jsonify( {APIConst.MESSAGE: 'created new organization', APIConst.DATA: result}) return response
def patch(self, id): _class = self.get_resource_with_ids(Class, id) json_data = request.get_json() try: data = class_patch_schema.load(json_data, partial=True) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) try: _class.update(**data) except Exception as err: raise RequestException( payload={APIConst.INPUT: json_data}) from err result = class_schema.dump(Class.get_with_id(_class.id)) response = jsonify({APIConst.MESSAGE: 'updated class {}'.format(id), APIConst.DATA: result}) return response
def patch(self, id): organization = self.get_resource_with_ids(Organization, id) json_data = request.get_json() try: data = organization_patch_schema.load(json_data) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) try: organization.update(**data) except Exception as err: raise RequestException( payload={APIConst.INPUT: json_data}) from err result = organization_schema.dump( Organization.get_with_id(organization.id)) response = jsonify({ APIConst.MESSAGE: 'updated organization {}'.format(id), APIConst.DATA: result}) return response
def get(self, ids=None, cs_id=None): if ids is not None: return self.response_to_get_with_ids( Lesson, LessonSchema.make_dynamic_schema(), ids) elif cs_id is not None: return self.response_to_get_with_keyvalue_dict( Lesson, LessonSchema.make_dynamic_schema(), {'class_session_id': cs_id}) else: raise RequestException()