Example #1
0
def create_enrollment(user_id, user_email):
    data = request.get_json()
    study_id = data['study_id']
    study = Studies.get_by_id(study_id)
    user = Users.get(Users.email == user_email)
    enroll = Enrollments(study=study, user=user)
    try:
        enroll.save(force_insert=True)
    except IntegrityError as e:
        return jsonify({"error": "%s" % e}), 500
    d = model_to_dict(study)
    d.update({'enrolled': True})
    return d
Example #2
0
def get_enrollments(user_id, user_email):
    user = Users.get(Users.email == user_email)
    enrollments = Enrollments.select(
        Enrollments.study_id).filter(Enrollments.user == user).tuples()
    return jsonify([e[0] for e in enrollments])