def roles_delete(): """This function handles the /users/roles/delete endpoint for the blueprint It allows PNT-Admins to delete a role. It is called via a button on the ``users/roles/edit.html`` template :param id: The id of the role being edited :type id: int :returns: users.users_home :rtype: redirect """ role = Role.by_id(id) if not role: abort(404) db.session.delete(role) db.session.commit() return redirect(url_for('users.users_home'))
def roles_edit(id): """This function handles the /roles/edit endpoint for the blueprint It allows PNT-Admins to edit roles. It uses the :ref:`users-forms-label` to display RolesEditForm :param id: The id of the role being edited :type id: int :returns: users/roles/edit.html :rtype: template """ role = Role.by_id(id) if not role: abort(404) form = RoleEditForm(obj=role) if form.validate_on_submit(): form.populate_obj(role) db.session.add(role) db.session.commit() return redirect(url_for('users.users_home')) return render_template('users/roles/edit.html', form=form, role_id=role.id, admin=True)