def add_privilege(): form = NewPrivilegeForm(request.form, obj=current_user) if request.method == 'POST' and form.validate(): for role in db.session.query(Role).order_by(Role.name): if role.name == form.name.data: flash( word( 'The privilege could not be added because it already exists.' ), 'error') return redirect(url_for('privilege_list')) db.session.add(Role(name=form.name.data)) db.session.commit() #docassemble.webapp.daredis.clear_user_cache() flash(word('The privilege was added.'), 'success') return redirect(url_for('privilege_list')) response = make_response( render_template('users/new_role_page.html', version_warning=None, bodyclass='daadminbody', page_title=word('Add Privilege'), tab_title=word('Add Privilege'), form=form), 200) response.headers[ 'Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0' return response
def get_role(db, name): the_role = Role.query.filter_by(name=name).first() if the_role: return the_role the_role = Role(name=name) db.session.add(the_role) db.session.commit() return the_role
def get_role(db, name, result=None): if result is None: result = dict() the_role = Role.query.filter_by(name=name).first() if the_role: return the_role the_role = Role(name=name) db.session.add(the_role) db.session.commit() result['changed'] = True return the_role
def get_role(the_db, name, result=None): if result is None: result = {} the_role = the_db.session.execute( select(Role).filter_by(name=name)).first() if the_role: return the_role the_role = Role(name=name) the_db.session.add(the_role) the_db.session.commit() result['changed'] = True return the_role
def add_privilege(): form = NewPrivilegeForm(request.form, obj=current_user) if request.method == 'POST' and form.validate(): for role in db.session.query(Role).order_by(Role.name): if role.name == form.name.data: flash(word('The privilege could not be added because it already exists.'), 'error') return redirect(url_for('privilege_list')) db.session.add(Role(name=form.name.data)) db.session.commit() flash(word('The privilege was added.'), 'success') return redirect(url_for('privilege_list')) return render_template('users/new_role_page.html', version_warning=None, bodyclass='adminbody', page_title=word('Add Privilege'), tab_title=word('Add Privilege'), form=form)