def profile_settings(category: str) -> Union[str, Response]: if category not in ['profile', 'display'] and not is_authorized('contributor'): abort(403) # pragma: no cover form = getattr( importlib.import_module('openatlas.forms.setting'), uc_first(category) + 'Form')() if form.validate_on_submit(): for field in form: if field.type in ['CSRFTokenField', 'HiddenField', 'SubmitField']: continue if field.name == 'name': current_user.real_name = field.data elif field.name == 'email': current_user.email = field.data else: current_user.settings[field.name] = field.data Transaction.begin() try: current_user.update() current_user.update_settings(form) Transaction.commit() session['language'] = current_user.settings['language'] flash(_('info update'), 'info') except Exception as e: # pragma: no cover Transaction.rollback() logger.log('error', 'database', 'transaction failed', e) flash(_('error transaction'), 'error') return redirect(url_for('profile_index') + '#tab-' + category) set_form_settings(form, True) return render_template( 'display_form.html', form=form, manual_page='profile', title=_('profile'), crumbs=[[_('profile'), url_for('profile_index') + '#tab-' + category], _(category)])
def profile_update(): form = ProfileForm() if form.validate_on_submit(): current_user.real_name = form.name.data current_user.email = form.email.data current_user.settings['show_email'] = form.show_email.data current_user.settings['newsletter'] = form.newsletter.data g.cursor.execute('BEGIN') try: current_user.update() current_user.update_settings() g.cursor.execute('COMMIT') flash(_('info update'), 'info') except Exception as e: # pragma: no cover g.cursor.execute('ROLLBACK') logger.log('error', 'database', 'transaction failed', e) flash(_('error transaction'), 'error') return redirect(url_for('profile_index')) form.name.data = current_user.real_name form.email.data = current_user.email form.show_email.data = current_user.settings['show_email'] form.newsletter.data = current_user.settings['newsletter'] return render_template('profile/update.html', form=form)
def set_locale(language: str) -> str: session['language'] = language if hasattr(current_user, 'id') and current_user.id: current_user.settings['language'] = language current_user.update_settings() return redirect(request.referrer)
def set_locale(language): session['language'] = language if hasattr(current_user, 'id') and current_user.id: current_user.settings['language'] = language current_user.update_settings() return redirect(request.referrer)