<s> """<STR_LIT>""" <EOL> from flask import Blueprint , flash , request <EOL> from flask_login import login_required , current_user <EOL> from flask_themes2 import get_themes_list <EOL> from flask_babelplus import gettext as _ <EOL> from flaskbb . extensions import babel <EOL> from flaskbb . utils . helpers import render_template <EOL> from flaskbb . user . models import User <EOL> from flaskbb . user . forms import ( ChangePasswordForm , ChangeEmailForm , <EOL> ChangeUserDetailsForm , GeneralSettingsForm ) <EOL> user = Blueprint ( "<STR_LIT:user>" , __name__ ) <EOL> @ user . route ( "<STR_LIT>" ) <EOL> def profile ( username ) : <EOL> user = User . query . filter_by ( username = username ) . first_or_404 ( ) <EOL> return render_template ( "<STR_LIT>" , user = user ) <EOL> @ user . route ( "<STR_LIT>" ) <EOL> def view_all_topics ( username ) : <EOL> page = request . args . get ( "<STR_LIT>" , <NUM_LIT:1> , type = int ) <EOL> user = User . query . filter_by ( username = username ) . first_or_404 ( ) <EOL> topics = user . all_topics ( page ) <EOL> return render_template ( "<STR_LIT>" , user = user , topics = topics ) <EOL> @ user . route ( "<STR_LIT>" ) <EOL> def view_all_posts ( username ) : <EOL> page = request . args . get ( "<STR_LIT>" , <NUM_LIT:1> , type = int ) <EOL> user = User . query . filter_by ( username = username ) . first_or_404 ( ) <EOL> posts = user . all_posts ( page ) <EOL> return render_template ( "<STR_LIT>" , user = user , posts = posts ) <EOL> @ user . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" , "<STR_LIT:GET>" ] ) <EOL> @ login_required <EOL> def settings ( ) : <EOL> form = GeneralSettingsForm ( ) <EOL> form . theme . choices = [ ( theme . identifier , theme . name ) <EOL> for theme in get_themes_list ( ) ] <EOL> form . language . choices = [ ( locale . language , locale . display_name ) <EOL> for locale in babel . list_translations ( ) ] <EOL> if form . validate_on_submit ( ) : <EOL> current_user . theme = form . theme . data <EOL> current_user . language = form . language . data <EOL> current_user . save ( ) <EOL> flash ( _ ( "<STR_LIT>" ) , "<STR_LIT:success>" ) <EOL> else : <EOL> form . theme . data = current_user . theme <EOL> form . language . data = current_user . language <EOL> return render_template ( "<STR_LIT>" , form = form ) <EOL> @ user . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" , "<STR_LIT:GET>" ] ) <EOL> @ login_required <EOL> def change_password ( ) : <EOL> form = ChangePasswordForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> current_user . password = form . new_password . data <EOL> current_user . save ( ) <EOL> flash ( _ ( "<STR_LIT>" ) , "<STR_LIT:success>" ) <EOL> return render_template ( "<STR_LIT>" , form = form ) <EOL> @ user . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" , "<STR_LIT:GET>" ] ) <EOL> @ login_required <EOL> def change_email ( ) : <EOL> form = ChangeEmailForm ( current_user ) <EOL> if form . validate_on_submit ( ) : <EOL> current_user . email = form . new_email . data <EOL> current_user . save ( ) <EOL> flash ( _ ( "<STR_LIT>" ) , "<STR_LIT:success>" ) <EOL> return render_template ( "<STR_LIT>" , form = form ) <EOL> @ user . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" , "<STR_LIT:GET>" ] ) <EOL> @ login_required <EOL> def change_user_details ( ) : <EOL> form = ChangeUserDetailsForm ( obj = current_user ) <EOL> if form . validate_on_submit ( ) : <EOL> form . populate_obj ( current_user ) <EOL> current_user . save ( ) <EOL> flash ( _ ( "<STR_LIT>" ) , "<STR_LIT:success>" ) <EOL> return render_template ( "<STR_LIT>" , form = form ) </s>
