~homeworkprod/byceps

8565785f7983fe9dfa3a6ea362388678f0d7ec29 — Jochen Kupperschmidt 2 years ago d253db1
Introduce user profile blueprint
13 files changed, 56 insertions(+), 41 deletions(-)

M byceps/application.py
A byceps/blueprints/user/profile/__init__.py
R byceps/blueprints/user/{templates/user/profile/_attended_parties.html => profile/templates/user/profile/_attended_parties.html}
R byceps/blueprints/user/{templates/user/profile/_badges.html => profile/templates/user/profile/_badges.html}
R byceps/blueprints/user/{templates/user/profile/_contact.html => profile/templates/user/profile/_contact.html}
R byceps/blueprints/user/{templates/user/profile/_current_party_attendance.html => profile/templates/user/profile/_current_party_attendance.html}
R byceps/blueprints/user/{templates/user/view.html => profile/templates/user/profile/view.html}
A byceps/blueprints/user/profile/views.py
M byceps/blueprints/user/templates/macros/user.html
M byceps/blueprints/user/templates/user/current/_profile.html
M byceps/blueprints/user/views.py
M byceps/blueprints/user_badge/templates/user_badge/view.html
M byceps/blueprints/user_message/views.py
M byceps/application.py => byceps/application.py +1 -0
@@ 88,6 88,7 @@ def _get_blueprints(app):
            ('ticketing',               '/tickets'                  ),
            ('tourney.avatar',          '/tourney/avatars'          ),
            ('tourney.match',           '/tourney/matches'          ),
            ('user.profile',            '/users'                    ),
            ('user_badge',              '/user_badges'              ),
            ('user_group',              '/user_groups'              ),
            ('user_message',            '/user_messages'            ),

A byceps/blueprints/user/profile/__init__.py => byceps/blueprints/user/profile/__init__.py +0 -0
R byceps/blueprints/user/templates/user/profile/_attended_parties.html => byceps/blueprints/user/profile/templates/user/profile/_attended_parties.html +0 -0
R byceps/blueprints/user/templates/user/profile/_badges.html => byceps/blueprints/user/profile/templates/user/profile/_badges.html +0 -0
R byceps/blueprints/user/templates/user/profile/_contact.html => byceps/blueprints/user/profile/templates/user/profile/_contact.html +0 -0
R byceps/blueprints/user/templates/user/profile/_current_party_attendance.html => byceps/blueprints/user/profile/templates/user/profile/_current_party_attendance.html +0 -0
R byceps/blueprints/user/templates/user/view.html => byceps/blueprints/user/profile/templates/user/profile/view.html +1 -1
@@ 1,6 1,6 @@
{% extends 'layout/base.html' %}
{% from 'macros/user_avatar.html' import render_user_avatar_128 %}
{% set current_page = 'user.view' %}
{% set current_page = 'user_profile.view' %}
{% set title = '%s - Benutzer'|format(user.screen_name) %}

{% block head %}

A byceps/blueprints/user/profile/views.py => byceps/blueprints/user/profile/views.py +50 -0
@@ 0,0 1,50 @@
"""
byceps.blueprints.user.profile.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE 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 service as badge_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_service.get_badges_for_user(user.id)

    orga_team_membership = orga_team_service.find_membership_for_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_membership': orga_team_membership,
        'current_party_tickets': current_party_tickets,
        'attended_parties': attended_parties,
    }

M byceps/blueprints/user/templates/macros/user.html => byceps/blueprints/user/templates/macros/user.html +1 -1
@@ 5,7 5,7 @@
  {%- if user.deleted -%}
{{ user.screen_name|dim }}
  {%- else -%}
<a href="{{ url_for('user.view', user_id=user.id) }}">{{ user.screen_name }}</a>
<a href="{{ url_for('user_profile.view', user_id=user.id) }}">{{ user.screen_name }}</a>
  {%- endif -%}
{%- endmacro %}


M byceps/blueprints/user/templates/user/current/_profile.html => byceps/blueprints/user/templates/user/current/_profile.html +1 -1
@@ 7,7 7,7 @@
    {%- if g.site_mode.is_public() %}
    <tr>
      <th>öffentliches Profil</th>
      <td><a href="{{ url_for('.view', user_id=user.id) }}">Ansehen</a></td>
      <td><a href="{{ url_for('user_profile.view', user_id=user.id) }}">Ansehen</a></td>
    </tr>
    {%- endif %}
    <tr>

M byceps/blueprints/user/views.py => byceps/blueprints/user/views.py +0 -36
@@ 7,7 7,6 @@ byceps.blueprints.user.views
"""

from datetime import datetime
from operator import attrgetter

from flask import abort, g, jsonify, request, Response



@@ 18,16 17,13 @@ from ...services.country import service as country_service
from ...services.newsletter import service as newsletter_service
from ...services.newsletter.transfer.models import \
    Subscription as NewsletterSubscription
from ...services.orga_team import service as orga_team_service
from ...services.terms import consent_service as terms_consent_service, \
    version_service as terms_version_service
from ...services.ticketing import attendance_service, ticket_service
from ...services.user import command_service as user_command_service
from ...services.user import creation_service as user_creation_service
from ...services.user import email_address_confirmation_service
from ...services.user import event_service as user_event_service
from ...services.user import service as user_service
from ...services.user_badge import service as badge_service
from ...services.verification_token import service as verification_token_service
from ...util.framework.blueprint import create_blueprint
from ...util.framework.flash import flash_error, flash_notice, flash_success


@@ 43,38 39,6 @@ from . import signals
blueprint = create_blueprint('user', __name__)


@blueprint.route('/<uuid:user_id>')
@templated
def view(user_id):
    """Show a user's profile."""
    if get_site_mode().is_admin():
        abort(404)

    user = user_service.find_active_user(user_id, include_avatar=True)
    if user is None:
        abort(404)

    badges_with_awarding_quantity = badge_service.get_badges_for_user(user.id)

    orga_team_membership = orga_team_service.find_membership_for_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_membership': orga_team_membership,
        'current_party_tickets': current_party_tickets,
        'attended_parties': attended_parties,
    }


@blueprint.route('/<uuid:user_id>.json')
def view_as_json(user_id):
    """Show selected attributes of a user's profile as JSON."""

M byceps/blueprints/user_badge/templates/user_badge/view.html => byceps/blueprints/user_badge/templates/user_badge/view.html +1 -1
@@ 47,7 47,7 @@
  <h2>an {{ recipients|length }} Personen verliehen</h2>
  <ul class="list-grid">
    {%- for user in recipients|sort(attribute='screen_name') %}
    <li><a class="recipient" href="{{ url_for('user.view', user_id=user.id) }}">
    <li><a class="recipient" href="{{ url_for('user_profile.view', user_id=user.id) }}">
{{ render_user_avatar_64(user) }}
    </a></li>
    {%- endfor %}

M byceps/blueprints/user_message/views.py => byceps/blueprints/user_message/views.py +1 -1
@@ 61,7 61,7 @@ def create(recipient_id):
    flash_success(
        'Deine Nachricht an {} wurde versendet.'.format(recipient.screen_name))

    return redirect_to('user.view', user_id=recipient.id)
    return redirect_to('user_profile.view', user_id=recipient.id)


def _get_user_or_404(user_id):