Beispiel #1
0
    def put(self, _id):
        data = self.parser.parse_args()
        course = CourseModel.find_by_id(_id)

        if course:
            course.name = data["name"]
            course.category = data["category"]
            course.trainers = data["trainers"]
            course.description = data["description"]
            course.target_audience = data["target_audience"]
            course.outcomes = data["outcomes"]
            course.requirements = data["requirements"]
            course.start_date = date(*data["start_date"])
            course.end_date = date(*data["end_date"])
            course.total_lectures = data["total_lectures"]
            course.lectures_per_week = data["lectures_per_week"]
            course.lecture_duration = timedelta(*data["lecture_duration"])
            course.min_spg = data["min_students_per_group"]
            course.max_spg = data["max_students_per_group"]
        else:
            valid_data = {
                key: val
                for key, val in data.items() if val is not None
            }
            course = CourseModel(**valid_data)

        try:
            course.save_to_db()
        except:
            return {
                "message": "An error occurred while saving to the database."
            }, 500

        return course.json()
    def post(self, _id):
        data = Course.parser.parse_args()
        print(data)
        course = CourseModel(**data)
        try:
            course.save_to_db()
        except:
            return {"message": "An error occurred inserting the course."}, 500

        return course.json(), 201
Beispiel #3
0
    def post(self):
        data = parser.parse_args()

        if CourseModel.query.filter_by(title=data['title']).first():
            msg = "A course with title:'{}' already exists.".format(
                data['title'])
            return {"message": msg}, 400

        course = CourseModel(**data)
        try:
            course.save()
        except:
            return {"message": "An error occurred while inserting Course"}, 500

        return course.json(), 201
Beispiel #4
0
    def post(self):
        data = self.parser.parse_args()
        # course = CourseModel.find_by_email(data["email"])
        # if course:
        #     return {'message': "The email {} already exists.".format(data["email"])}, 400

        valid_data = {key: val for key, val in data.items() if val is not None}
        course = CourseModel(**valid_data)

        try:
            course.save_to_db()
        except:
            return {
                "message": "An error occurred while saving to the database."
            }, 500

        return course.json(), 201
Beispiel #5
0
    def post(self, name):
        if CourseModel.find_by_name(name):
            return {
                'message':
                f"A course with name '{name}' is already entered into the database."
            }, 400
        data = Course.parser.parse_args()
        course = CourseModel(name, **data)

        try:
            course.save_to_db()
        except:
            return {
                'message':
                'An error occurred inserting the course into the database.'
            }, 500

        return course.json(), 201
    def put(self, _id):
        data = Course.parser.parse_args()

        course = CourseModel.find_by_id(_id)

        if course:
            course.price = data['price']
            course.description = data['description']
            course.on_discount = data['on_discount']
            course.title = data['title']
            course.date_updated = datetime.datetime.utcnow()
            course.image_path = data['image_path']

        else:
            course = CourseModel(**data)

        course.save_to_db()

        return course.json()
Beispiel #7
0
    def post(self):
        data = Course.postparser.parse_args()

        classname = data['classname']
        startdate = datetime.strptime(data['startdate'], "%Y-%m-%d")
        enddate = datetime.strptime(data['enddate'], "%Y-%m-%d")
        starttime = datetime.strptime(data['starttime'], "%I:%M %p")
        endtime = datetime.strptime(data['endtime'], "%I:%M %p")
        orgid = data['orgid']
        userid = data['userid']
        if data['classdays'] is None:
            classdays = [datetime.weekday(startdate)]
        else:
            classdays = list(map(int, data['classdays'].split(',')))

        jsonstr = []
        msgstr = []
        for n in range(int (((enddate + timedelta(days=1)) - startdate).days)):
            classdate = startdate + timedelta(n)
            day = datetime.weekday(classdate)
            if day in classdays:
                course = CourseModel(orgid=orgid,
                                     name=classname,
                                     starttime=datetime.strftime(starttime, "%H:%M"),
                                     endtime=datetime.strftime(endtime, "%H:%M"),
                                     classdate=datetime.strftime(classdate, "%Y-%m-%d"),
                                     startdate=datetime.strftime(startdate, "%Y-%m-%d"),
                                     enddate=datetime.strftime(enddate, "%Y-%m-%d"),
                                     classdays=data['classdays'] if data['classdays'] != None else datetime.weekday(startdate),
                                     userid=userid,
                                     requestuserid=None,
                                     requestdate=None,
                                     acceptuserid=None,
                                     acceptdate=None)
                try:
                    course.save_to_db()
                    msgstr.append({'status': "SUCCESS", "code": 200})
                except:
                    msgstr.append({'status': "ERROR", "code": 500})
                jsonstr.append(course.json())

        return {'courses': jsonstr,'messages': msgstr}
Beispiel #8
0
    def put(self, course_id):
        data = parser.parse_args()

        course = CourseModel.find_by_id(course_id)

        if course is None:
            new_course = CourseModel(**data)
            try:
                new_course.save()
            except:
                return {"message": "An error occurred while inserting Course."}, 500

            return new_course.json(), 201

        try:
            course.update(**data)
        except:
            return {"message": "An error occurred while updating Course."}, 500

        return course.json(), 200