from flask import flash, redirect, render_template, url_for from flask_login import current_user, login_required from app import db from app.models import User from . import bp from .forms import ( EditProfileSettingsForm ) @bp.route('') @login_required def profile(): user_image = 'static/images/user_avatar.png' user_name = current_user.username 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' email = current_user.email website = 'https://nopaque.uni-bielefeld.de' organization = 'Universität Bielefeld' member_since = f'{current_user.member_since.strftime("%Y-%m-%d")}' return render_template('profile/profile_page.html.j2', user_image=user_image, user_name=user_name, last_seen=last_seen, location=location, about_me=about_me, full_name=full_name, email=email, website=website, organization=organization, member_since=member_since) @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')