nopaque/app/profile/routes.py

62 lines
2.4 KiB
Python
Raw Normal View History

2022-11-30 13:36:42 +00:00
from flask import flash, redirect, render_template, url_for
2022-11-29 15:46:33 +00:00
from flask_login import current_user, login_required
from app import db
from app.models import User
from . import bp
2022-11-30 13:36:42 +00:00
from .forms import (
EditProfileSettingsForm
)
2022-11-29 15:46:33 +00:00
@bp.route('')
@login_required
def profile():
user_image = 'static/images/user_avatar.png'
user_name = current_user.username
2022-11-30 13:36:42 +00:00
last_seen = f'{current_user.last_seen.strftime("%Y-%m-%d %H:%M")}'
location = 'Bielefeld'
about_me = '''Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimat'''
full_name = 'Inga Kirschnick'
2022-11-29 15:46:33 +00:00
email = current_user.email
2022-11-30 13:36:42 +00:00
website = 'https://nopaque.uni-bielefeld.de'
organization = 'Universität Bielefeld'
member_since = f'{current_user.member_since.strftime("%Y-%m-%d")}'
2022-11-29 15:46:33 +00:00
return render_template('profile/profile_page.html.j2',
user_image=user_image,
user_name=user_name,
2022-11-30 13:36:42 +00:00
last_seen=last_seen,
location=location,
about_me=about_me,
full_name=full_name,
email=email,
website=website,
organization=organization,
member_since=member_since)
2022-11-29 15:46:33 +00:00
2022-11-30 13:36:42 +00:00
@bp.route('/edit')
@login_required
def edit_profile():
edit_profile_settings_form = EditProfileSettingsForm(
current_user,
data=current_user.to_json_serializeable(),
prefix='edit-profile-settings-form'
)
if (edit_profile_settings_form.submit.data
and edit_profile_settings_form.validate()):
current_user.email = edit_profile_settings_form.email.data
current_user.username = edit_profile_settings_form.username.data
current_user.about_me = edit_profile_settings_form.about_me.data
current_user.location = edit_profile_settings_form.location.data
current_user.organization = edit_profile_settings_form.organization.data
current_user.website = edit_profile_settings_form.website.data
current_user.full_name = edit_profile_settings_form.full_name.data
db.session.commit()
flash('Your changes have been saved')
return redirect(url_for('.profile.edit_profile'))
return render_template('profile/edit_profile.html.j2',
edit_profile_settings_form=edit_profile_settings_form,
title='Edit Profile')