~homeworkprod/byceps

abdc90335ceec2a47363e425d4bf78ad0183f00b — Jochen Kupperschmidt 2 years ago f542baf
Move current user view code and templates to its own blueprint
15 files changed, 29 insertions(+), 28 deletions(-)

M byceps/application.py
M byceps/blueprints/admin/core/templates/layout/admin/_current_user.html
M byceps/blueprints/authentication/templates/authentication/password_update_form.html
M byceps/blueprints/core/templates/layout/_current_user.html
M byceps/blueprints/core/templates/layout/_current_user_menu_items.html
M byceps/blueprints/user/avatar/views.py
A byceps/blueprints/user/current/__init__.py
R byceps/blueprints/user/{forms.py => current/forms.py}
R byceps/blueprints/user/{templates/user/current/_account.html => current/templates/user/current/_account.html}
R byceps/blueprints/user/{templates/user/current/_details_personal.html => current/templates/user/current/_details_personal.html}
R byceps/blueprints/user/{templates/user/current/_newsletter.html => current/templates/user/current/_newsletter.html}
R byceps/blueprints/user/{templates/user/current/_profile.html => current/templates/user/current/_profile.html}
R byceps/blueprints/user/{templates/user/details_update_form.html => current/templates/user/current/details_update_form.html}
R byceps/blueprints/user/{templates/user/view_current.html => current/templates/user/current/view.html}
R byceps/blueprints/user/{views.py => current/views.py}
M byceps/application.py => byceps/application.py +1 -1
@@ 69,7 69,7 @@ def _get_blueprints(app):
        ('authorization',           None                            ),
        ('core',                    '/core'                         ),
        ('healthcheck',             '/health'                       ),
        ('user',                    '/users'                        ),
        ('user.current',            '/users'                        ),
        ('user.creation',           '/users'                        ),
        ('user.email_address',      '/users/email_address'          ),
        ('user.avatar',             '/users'                        ),

M byceps/blueprints/admin/core/templates/layout/admin/_current_user.html => byceps/blueprints/admin/core/templates/layout/admin/_current_user.html +2 -2
@@ 5,7 5,7 @@
<div class="current-user">
  {%- if g.current_user.is_active %}
  <div class="dropdown left">
    <button href="{{ url_for('user.view_current') }}" class="dropdown-toggle button button--clear">
    <button href="{{ url_for('user_current.view') }}" class="dropdown-toggle button button--clear">
      {{ render_user_avatar_32(g.current_user) }}
      {{ render_icon('caret-down') }}
    </button>


@@ 16,7 16,7 @@
      </li>
      <li class="divider"></li>
      <li><a href="{{ url_for('user_admin.view', user_id=g.current_user.id) }}">{{ render_icon('user-profile') }} Profil</a></li>
      <li><a href="{{ url_for('user.view_current') }}">{{ render_icon('user') }} Einstellungen</a></li>
      <li><a href="{{ url_for('user_current.view') }}">{{ render_icon('user') }} Einstellungen</a></li>
      <li class="divider"></li>
      <li><a data-action="logout" href="{{ url_for('authentication.logout', _method='POST') }}">{{ render_icon('log-out') }} abmelden</a></li>
    </ol>

M byceps/blueprints/authentication/templates/authentication/password_update_form.html => byceps/blueprints/authentication/templates/authentication/password_update_form.html +1 -1
@@ 15,7 15,7 @@
      {{ form_field(form.new_password_confirmation, maxlength=40, required='required') }}
    {%- endcall %}

    {{ form_buttons('Passwort ändern', cancel_url=url_for('user.view_current')) }}
    {{ form_buttons('Passwort ändern', cancel_url=url_for('user_current.view')) }}
  </form>

{%- endblock %}

M byceps/blueprints/core/templates/layout/_current_user.html => byceps/blueprints/core/templates/layout/_current_user.html +1 -1
@@ 5,7 5,7 @@
<div class="current-user">
  {%- if g.current_user.is_active %}
  <div class="dropdown left">
    <a href="{{ url_for('user.view_current') }}" class="dropdown-toggle">
    <a href="{{ url_for('user_current.view') }}" class="dropdown-toggle">
      {{ render_user_avatar_32(g.current_user) }}
      <span class="label-and-name">
        <span class="label">Angemeldet als</span>

M byceps/blueprints/core/templates/layout/_current_user_menu_items.html => byceps/blueprints/core/templates/layout/_current_user_menu_items.html +1 -1
@@ 2,6 2,6 @@


      <li><a href="{{ url_for('user_profile.view', user_id=g.current_user.id) }}">{{ render_icon('user-profile') }} Profil</a></li>
      <li><a href="{{ url_for('user.view_current') }}">{{ render_icon('user') }} Einstellungen</a></li>
      <li><a href="{{ url_for('user_current.view') }}">{{ render_icon('user') }} Einstellungen</a></li>
      <li><a href="{{ url_for('ticketing.index_mine') }}">{{ render_icon('ticket') }} Tickets</a></li>
      <li><a href="{{ url_for('shop_orders.index') }}">{{ render_icon('invoice') }} Bestellungen</a></li>

M byceps/blueprints/user/avatar/views.py => byceps/blueprints/user/avatar/views.py +1 -1
@@ 68,7 68,7 @@ def update():
    flash_success('Dein Avatarbild wurde aktualisiert.', icon='upload')
    signals.avatar_updated.send(None, user_id=user.id)

    return redirect_to('user.view_current')
    return redirect_to('user_current.view')


def _update(user_id, image):

A byceps/blueprints/user/current/__init__.py => byceps/blueprints/user/current/__init__.py +0 -0
R byceps/blueprints/user/forms.py => byceps/blueprints/user/current/forms.py +3 -3
@@ 1,6 1,6 @@
"""
byceps.blueprints.user.forms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
byceps.blueprints.user.current.forms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.


@@ 9,7 9,7 @@ byceps.blueprints.user.forms
from wtforms import DateField, StringField
from wtforms.validators import InputRequired, Length, Optional

from ...util.l10n import LocalizedForm
from ....util.l10n import LocalizedForm


class DetailsForm(LocalizedForm):

R byceps/blueprints/user/templates/user/current/_account.html => byceps/blueprints/user/current/templates/user/current/_account.html +0 -0
R byceps/blueprints/user/templates/user/current/_details_personal.html => byceps/blueprints/user/current/templates/user/current/_details_personal.html +0 -0
R byceps/blueprints/user/templates/user/current/_newsletter.html => byceps/blueprints/user/current/templates/user/current/_newsletter.html +0 -0
R byceps/blueprints/user/templates/user/current/_profile.html => byceps/blueprints/user/current/templates/user/current/_profile.html +0 -0
R byceps/blueprints/user/templates/user/details_update_form.html => byceps/blueprints/user/current/templates/user/current/details_update_form.html +1 -1
@@ 21,7 21,7 @@
      {{ form_field(form.phone_number, maxlength=20) }}
    {%- endcall %}

    {{ form_buttons('Speichern', cancel_url=url_for('.view_current')) }}
    {{ form_buttons('Speichern', cancel_url=url_for('.view')) }}
  </form>

{%- endblock %}

R byceps/blueprints/user/templates/user/view_current.html => byceps/blueprints/user/current/templates/user/current/view.html +0 -0
R byceps/blueprints/user/views.py => byceps/blueprints/user/current/views.py +18 -17
@@ 1,6 1,6 @@
"""
byceps.blueprints.user.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
byceps.blueprints.user.current.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.


@@ 8,29 8,30 @@ byceps.blueprints.user.views

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

from ...config import get_site_mode
from ...services.country import service as country_service
from ...services.newsletter import service as newsletter_service
from ...services.user import command_service as user_command_service
from ...services.user import service as user_service
from ...util.framework.blueprint import create_blueprint
from ...util.framework.flash import flash_success
from ...util.framework.templating import templated
from ...util.views import redirect_to
from ....config import get_site_mode
from ....services.country import service as country_service
from ....services.newsletter import service as newsletter_service
from ....services.user import command_service as user_command_service
from ....services.user import service as user_service
from ....util.framework.blueprint import create_blueprint
from ....util.framework.flash import flash_success
from ....util.framework.templating import templated
from ....util.views import redirect_to

from ..authentication.decorators import login_required
from ...authentication.decorators import login_required

from ..creation.views import _find_newsletter_list_for_brand

from .forms import DetailsForm
from .creation.views import _find_newsletter_list_for_brand


blueprint = create_blueprint('user', __name__)
blueprint = create_blueprint('user_current', __name__)


@blueprint.route('/me')
@login_required
@templated
def view_current():
def view():
    """Show the current user's internal profile."""
    current_user = g.current_user



@@ 58,7 59,7 @@ def view_current():


@blueprint.route('/me.json')
def view_current_as_json():
def view_as_json():
    """Show selected attributes of the current user's profile as JSON."""
    if get_site_mode().is_admin():
        abort(404)


@@ 117,7 118,7 @@ def details_update():
                                             phone_number)

    flash_success('Deine Daten wurden gespeichert.')
    return redirect_to('.view_current')
    return redirect_to('.view')


def _get_current_user_or_404():