Passed
Push — main ( 7fb18a...baf70b )
by Jochen
04:45
created

byceps.blueprints.site.party_history.views.index()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.216

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 0
dl 0
loc 9
ccs 2
cts 5
cp 0.4
crap 1.216
rs 10
c 0
b 0
f 0
1
"""
2
byceps.blueprints.site.party_history.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from flask import abort, g
10
11 1
from ....services.party import service as party_service
12 1
from ....services.ticketing import attendance_service
13 1
from ....services.user import service as user_service
14 1
from ....util.framework.blueprint import create_blueprint
15 1
from ....util.framework.templating import templated
16
17
18 1
blueprint = create_blueprint('party_archive', __name__)
19
20
21 1
@blueprint.get('')
22 1
@templated
23
def index():
24
    """List archived parties."""
25
    parties = party_service.get_archived_parties_for_brand(g.brand_id)
26
    parties = [p for p in parties if not p.canceled]
27
28
    return {
29
        'parties': parties,
30
    }
31
32
33 1
@blueprint.get('/<party_id>')
34 1
@templated
35
def view(party_id):
36
    """Show archived party."""
37
    party = party_service.find_party(party_id)
38
    if (party is None) or (party.brand_id != g.brand_id) or not party.archived:
39
        abort(404)
40
41
    attendee_ids = attendance_service.get_attendee_ids_for_party(party_id)
42
    attendees = user_service.find_users(attendee_ids, include_avatars=True)
43
44
    return {
45
        'party': party,
46
        'attendees': attendees,
47
    }
48