def admin_settings(category: str) -> Union[str, Response]: if category in ['general', 'mail'] and not is_authorized('admin'): abort(403) # pragma: no cover form = getattr(importlib.import_module('openatlas.forms.setting'), uc_first(category) + 'Form')() # Get forms dynamically if form.validate_on_submit(): Transaction.begin() try: Settings.update(form) logger.log('info', 'settings', 'Settings updated') Transaction.commit() flash(_('info update'), 'info') except Exception as e: # pragma: no cover Transaction.rollback() logger.log('error', 'database', 'transaction failed', e) flash(_('error transaction'), 'error') tab = 'data' if category == 'api' else category tab = 'email' if category == 'mail' else tab return redirect(url_for('admin_index') + '#tab-' + tab) set_form_settings(form) return render_template('display_form.html', form=form, manual_page='admin/' + category, title=_('admin'), crumbs=[[ _('admin'), url_for('admin_index') + '#tab-' + ('data' if category == 'api' else category) ], _(category)])
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 admin_settings(category: str) -> Union[str, Response]: if category in ['general', 'mail'] and not is_authorized('admin'): abort(403) # pragma: no cover form_name = f"{uc_first(category)}Form" form = getattr( importlib.import_module('openatlas.forms.setting'), form_name)() if form.validate_on_submit(): data = {} for field in form: if field.type in ['CSRFTokenField', 'HiddenField', 'SubmitField']: continue value = field.data if field.type == 'BooleanField': value = 'True' if field.data else '' data[field.name] = value Transaction.begin() try: Settings.update(data) logger.log('info', 'settings', 'Settings updated') Transaction.commit() 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( f"{url_for('admin_index')}" f"#tab-{category.replace('api', 'data').replace('mail', 'email')}") set_form_settings(form) return render_template( 'display_form.html', form=form, manual_page=f"admin/{category}", title=_('admin'), crumbs=[ [ _('admin'), f"{url_for('admin_index')}" f"#tab-{'data' if category == 'api' else category}"], _(category)])