~homeworkprod/byceps

ref: 0f32ddebed1f09618da28526d6702060c237cb51 byceps/byceps/blueprints/site/user_profile/views.py -rw-r--r-- 1.7 KiB
0f32ddeb — Jochen Kupperschmidt Flatten package/path of user profile site blueprint 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
byceps.blueprints.site.user_profile.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from operator import attrgetter

from flask import abort, g

from ....services.orga_team import service as orga_team_service
from ....services.ticketing import attendance_service, ticket_service
from ....services.user import service as user_service
from ....services.user_badge import awarding_service as badge_awarding_service
from ....util.framework.blueprint import create_blueprint
from ....util.framework.templating import templated


blueprint = create_blueprint('user_profile', __name__)


@blueprint.route('/<uuid:user_id>')
@templated
def view(user_id):
    """Show a user's profile."""
    user = user_service.find_active_user(user_id, include_avatar=True)
    if user is None:
        abort(404)

    badges_with_awarding_quantity = badge_awarding_service.get_badges_awarded_to_user(
        user.id
    )

    orga_team = orga_team_service.find_orga_team_for_user_and_party(
        user.id, g.party_id
    )

    _current_party_tickets = ticket_service.find_tickets_used_by_user(
        user.id, g.party_id
    )
    current_party_tickets = [t for t in _current_party_tickets if not t.revoked]

    attended_parties = attendance_service.get_attended_parties(user.id)
    attended_parties.sort(key=attrgetter('starts_at'), reverse=True)

    return {
        'user': user,
        'badges_with_awarding_quantity': badges_with_awarding_quantity,
        'orga_team': orga_team,
        'current_party_tickets': current_party_tickets,
        'attended_parties': attended_parties,
    }