Beispiel #1
0
def create():
    english = Subject.get_by_id(3)
    math = Subject.get_by_id(4)
    life_skills = Subject.get_by_id(5)

    tutor_1 = Tutor.get_by_id(1)
    tutor_2 = Tutor.get_by_id(2)

    start_1 = datetime.datetime(2021, 2, 1, 10, 0)
    end_1 = datetime.datetime(2021, 2, 1, 12, 0)
    duration_1 = (end_1 - start_1).seconds // 60  # convert to minute

    start_2 = datetime.datetime(2021, 2, 1, 11, 0)
    end_2 = datetime.datetime(2021, 2, 1, 13, 0)
    duration_2 = (end_2 - start_2).seconds // 60  # convert to minute

    session = Tutor_session(subject=english,
                            tutor=tutor_1,
                            title="Some title",
                            price=100,
                            duration=duration_1,
                            start_time=start_1,
                            end_time=end_1,
                            max_student_capacity=10,
                            status="Confirmed",
                            zoom_host="",
                            zoom_participant="")

    if session.save():
        flash("session created")
    else:
        flash("error creating session")
    return render_template('home.html', errors=session.errors)
Beispiel #2
0
def delete(id):
    tutor_session = Tutor_session.get_by_id(id)
    tutor = Tutor.get_by_id(get_jwt_identity())

    if tutor_session:
        if tutor_session.tutor_id == tutor.id:
            if tutor_session.delete_instance(recursive=True):
                responseObject = ({
                    "message": "Successfully deleted tutor session.",
                    "status": "success!"
                })
                return make_response(jsonify(responseObject)), 200
            else:
                responseObject = {
                    "status": "failed",
                    "message": "Deleting tutor session failed."
                }
                return make_response(jsonify(responseObject)), 400
        else:
            responseObject = ({
                "message": "No permission to delete tutor session.",
                "status": "failed!"
            })
            return make_response(jsonify(responseObject)), 403
    else:
        responseObject = ({
            "message": "Tutor session does not exist.",
            "status": "failed!"
        })
        return make_response(jsonify(responseObject)), 500
Beispiel #3
0
def me():
    tutor = Tutor.get_by_id(get_jwt_identity())
    if tutor:
        tutor_data = model_to_dict(tutor)

        return make_response(jsonify(tutor_data)), 200
    else:
        return abort(404)
Beispiel #4
0
def new():
    params = request.json
    tutor_id = get_jwt_identity()
    tutor = Tutor.get_by_id(tutor_id)

    try:
        new_tutor_session = Tutor_session(
            subject=params.get('subject'),
            tutor_id=tutor.id,
            title=params.get('title'),
            price=params.get('price'),
            description=params.get('description'),
            start_time=(datetime(int(params.get('start_year')),
                                 int(params.get('start_month')),
                                 int(params.get('start_day')),
                                 int(params.get('start_hour')),
                                 int(params.get('start_minute')))),
            end_time=(datetime(int(params.get('end_year')),
                               int(params.get('end_month')),
                               int(params.get('end_day')),
                               int(params.get('end_hour')),
                               int(params.get('end_minute')))),
            max_student_capacity=params.get('max_student_capacity'),
            status="Confirmed",
            status_timestamp=datetime.now(),
            zoom_host=params.get('zoom_host'),
            zoom_participant=params.get('zoom_participant'))
    except:
        responseObject = {
            "status": "failed",
            "message": ['All fields are required!']
        }
        return make_response(jsonify(responseObject)), 400

    if new_tutor_session.save():
        responseObject = ({
            "message": "Successfully created new tutor session.",
            "status": "success!",
            "session": {
                "id": new_tutor_session.id,
                "title": new_tutor_session.title,
                "description": new_tutor_session.description,
                "subject": new_tutor_session.subject_id,
                "tutor_id": new_tutor_session.tutor.id,
                "start_time": new_tutor_session.start_time,
                "end_time": new_tutor_session.end_time,
                "max_student_capacity": new_tutor_session.max_student_capacity,
                "price": new_tutor_session.price,
                "status": new_tutor_session.status,
                "status_timestamp": new_tutor_session.status_timestamp,
                "zoom_host": new_tutor_session.zoom_host,
                "zoom_participant": new_tutor_session.zoom_participant
            }
        })
        return make_response(jsonify(responseObject)), 201
    else:
        return make_response(jsonify([err for err in new_tutor_session.errors
                                      ])), 400
Beispiel #5
0
def show_me():
    tutor = Tutor.get_by_id(get_jwt_identity())

    if tutor:
        my_tutor_sessions = Tutor_session.select().where(
            Tutor_session.tutor_id == tutor.id)

        my_tutor_sessions_data = []

        for tutor_session in my_tutor_sessions:
            tutor_session = model_to_dict(tutor_session)
            my_tutor_sessions_data.append(tutor_session)

        return make_response(jsonify(my_tutor_sessions_data)), 200
Beispiel #6
0
def upload():
    tutor = Tutor.get_by_id(1) #hard coded for testing purposes

    file = request.files["profile_photo"]
    file.filename = secure_filename(file.filename)
    image_path = upload_file_to_s3(file, "tutor", tutor.username)

    # save photo url in database
    tutor.profile_image=image_path

    if tutor.save(only=[Tutor.profile_image]):
        flash("Profile photo saved to database successfully!",'info')
    else:
        flash("Unable to save profile photo to database.",'danger')
    return render_template('home.html',errors=tutor.errors)
Beispiel #7
0
def update_profile_picture():
    tutor = Tutor.get_by_id(get_jwt_identity())

    file = request.files['profile_image']
    file.filename = secure_filename(file.filename)
    image_path = upload_file_to_s3(file, "tutor", tutor.username)

    tutor.profile_image = image_path

    if tutor.save(only=[Tutor.profile_image]):
        objectResponse = ({
            "message": "Succesfully updated profile image.",
            "status": "success!",
            "image": {
                "url": f"{app.config.get('S3_LOCATION')}{image_path}"
            }
        })
        return make_response(jsonify(objectResponse)), 200
    else:
        return make_response(jsonify([err for err in tutor.errors])), 400
Beispiel #8
0
def show_tutor_tutorsesions(id):
    tutor = Tutor.get_by_id(id)

    if tutor:
        tutor_sessions = Tutor_session.select().where(
            Tutor_session.tutor_id == tutor.id)

        tutor_sessions_data = []

        for tutor_session in tutor_sessions:
            tutor_session = model_to_dict(tutor_session)
            tutor_sessions_data.append(tutor_session)

        return make_response(jsonify(tutor_sessions_data)), 200
    else:
        objectResponse = ({
            "message": "Tutor does not exist.",
            "status": "erroe!"
        })
        return make_response(jsonify(objectResponse)), 404
Beispiel #9
0
def show(id):
    tutor = Tutor.get_by_id(id)
    tutor_data = model_to_dict(tutor)

    return make_response(jsonify(tutor_data)), 200