Exemple #1
0
def get_user(user_id):
    try:
        user = select_user(user_id)
        if not user:
            return json.dumps(None)

    except Exception:
        return json.dumps(None)

    leagues = [{
        'name':
        league.name,
        'active':
        league.is_active,
        'complete':
        league.is_complete,
        'users': [{
            'id': user.id,
            'name': user.name,
        } for user in league.users]
    } for league in select_leagues_for_user(user)]

    return json.dumps({
        'id': user.id,
        'name': user.name,
        'leagues': leagues,
    })
Exemple #2
0
def profile():
    page_user = g.user

    from musicleague.persistence.select import select_leagues_for_user
    from musicleague.persistence.select import select_memberships_placed
    leagues = select_leagues_for_user(
        page_user.id,
        exclude_properties=['rounds', 'invited_users', 'scoreboard'])
    placed_leagues = select_memberships_placed(page_user.id)

    return {
        'user': g.user,
        'page_user': page_user,
        'leagues': leagues,
        'contributor_leagues': len(leagues),
        'placed_leagues': placed_leagues,
        'access_token': session['access_token'],
        'api_domain': getenv('API_DOMAIN'),
    }
Exemple #3
0
def view_user(user_id):
    if user_id == str(g.user.id):
        return redirect(url_for('profile'))

    page_user = get_user(user_id)

    from musicleague.persistence.select import select_leagues_for_user
    from musicleague.persistence.select import select_memberships_placed
    leagues = select_leagues_for_user(
        page_user.id,
        exclude_properties=['rounds', 'invited_users', 'scoreboard'])
    placed_leagues = select_memberships_placed(page_user.id)

    return {
        'user': g.user,
        'page_user': page_user,
        'leagues': leagues,
        'contributor_leagues': select_memberships_count(page_user.id),
        'placed_leagues': placed_leagues
    }