Esempio n. 1
0
def get_member_details(_id=None):
    if not id:
        return jsonify(errors='No user id given'), 400
    user = User.by_id(_id)
    if not user:
        return jsonify(errors='User not found with that id'), 404
    data = {
        "id": user.id,
        "name": user.name,
        "email": user.email,
        "avatar": UserAPI.avatar(user),
        "gender": user.gender,
        "locale": user.locale,
        "student_id": user.student_id,
        "education": user.education.name
    }
    return jsonify(data=data), 200
Esempio n. 2
0
def view_single(user_id):
    """
    View user for admins and edit for admins and users.

    User is passed based on routes below.
    """
    user = user_service.get_user_by_id(user_id)
    user.avatar = UserAPI.avatar(user)
    user.groups = UserAPI.get_groups_for_user_id(user)

    user.groups_amount = len(user.groups)

    if "gravatar" in user.avatar:
        user.avatar = user.avatar + "&s=341"

    # Get all activity entrees from these forms, order by start_time of
    # activity.
    activities = Activity.query.join(CustomForm).join(CustomFormResult). \
        filter(CustomFormResult.owner_id == user_id and
               CustomForm.id == CustomFormResult.form_id and
               Activity.form_id == CustomForm.id)

    user.activities_amount = activities.count()

    new_activities = activities \
        .filter(Activity.end_time > datetime.today()).distinct() \
        .order_by(Activity.start_time)
    old_activities = activities \
        .filter(Activity.end_time < datetime.today()).distinct() \
        .order_by(Activity.start_time.desc())

    can_write = role_service.user_has_role(current_user, Roles.USER_WRITE)

    return render_template('user/view_single.htm', user=user,
                           new_activities=new_activities,
                           old_activities=old_activities,
                           can_write=can_write)