Display profiles

This commit is contained in:
Gergely Polonkai 2018-07-09 09:57:23 +02:00
parent 2136546390
commit ad53608966
3 changed files with 29 additions and 1 deletions

View File

@ -245,5 +245,25 @@ class CalendarSocialApp(Flask):
return render_template('event-details.html', event=event)
@staticmethod
@route('/profile/@<string:username>')
def display_profile(username):
"""View to display profile details
"""
from flask import abort
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from .models import Profile, User
try:
profile = Profile.query.join(User).filter(User.username == username.lower()).one()
except NoResultFound:
abort(404)
except MultipleResultsFound:
abort(500)
return render_template('profile-details.html', profile=profile)
app = CalendarSocialApp(__name__)

View File

@ -30,7 +30,7 @@
</h1>
<nav class="menu">
{% if current_user.is_authenticated %}
{{ _('Logged in as %(username)s', username=current_user.username) }}
{{ _('Logged in as %(username)s', username=('<a href="' + url_for('display_profile', username=current_user.username) + '">' + current_user.username + '</a>') | safe) }}
{% endif %}
<ul>
{% if not current_user.is_authenticated %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block content %}
<h1>
{{ profile.name }}
<small>@{{ profile.user.username}}</small>
</h1>
{% endblock content %}