Example #1
0
def request_student(user_id):
    student = users.get_or_404(user_id)
    tutor = current_user.user

    try:
        existing_relation = tutoring_relations.get(tutor=tutor,
                                                   student=student)

    except:
        new_relation = tutoring_relations.create(tutor=tutor,
                                                 student=student,
                                                 initiated_by='tutor',
                                                 accepted=False)

        return current_user.user

    else:
        if existing_relation.accepted:
            error_code = 1
            error_message = "This user is already your student."
        else:
            if existing_relation.initiated_by == 'tutor':
                error_code = 2
                error_message = "You already requested this user as a student."
            else:
                error_code = 3
                error_message = "This user already requested you as a tutor."

        return jsonify(error_code=error_code, error_message=error_message), 400
Example #2
0
def remove_student(user_id):
    student = users.get_or_404(user_id)
    tutor = current_user.user

    relation = tutoring_relations.get_or_404(tutor=tutor,
                                             student=student,
                                             accepted=True)
    relation.delete()

    return current_user.user
Example #3
0
def cancel_student_request(user_id):
    student = users.get_or_404(user_id)
    tutor = current_user.user

    relation = tutoring_relations.get_or_404(tutor=tutor,
                                             student=student,
                                             initiated_by='tutor',
                                             accepted=False)
    relation.delete()

    return current_user.user
Example #4
0
def decline_student(user_id):
    student = current_user.user
    tutor = users.get_or_404(user_id)

    relation = tutoring_relations.get_or_404(tutor=tutor,
                                             student=student,
                                             initiated_by='tutor',
                                             accepted=False)

    relation.delete()

    return current_user.user
Example #5
0
def accept_tutor(user_id):
    student = users.get_or_404(user_id)
    tutor = current_user.user

    relation = tutoring_relations.get_or_404(tutor=tutor,
                                             student=student,
                                             initiated_by='student',
                                             accepted=False)

    relation.accepted = True
    relation.save()

    return current_user.user
Example #6
0
def record_visited_user_dashboard_analytic():
    """ Creates a new VisitedDashboardActivity object which is used to track analytics on the platform
    :param user_id: the id of the user from which we want to get the dashboard
    """
    try:
        data = request.get_json()
        dashboard_user = users.get_or_404(data['dashboard_user'])
        credentials = current_user._get_current_object()
        obj = visited_user_dashboards.create(credentials=credentials,
                                             dashboard_user=dashboard_user)
    except Exception as e:
        return jsonify(error=e.message), 400
    else:
        return obj, 201
Example #7
0
 def user_info(self, user_id):
     user = users.get_or_404(user_id)
     return self.render("admin/user_info.html", user=user, tracks=tracks, skills=skills, lessons=lessons)
Example #8
0
def user_dashboard(user_id):
    user = users.get_or_404(user_id)

    return jsonify(data=user, courses_info=user.courses_info(analytics=True))
Example #9
0
def get_user_info(user_id):
    return users.get_or_404(user_id)