def test_data_delete(): from models.account import Account from models.project import Project from models.report import Report from models.variable import Variable roles = { 'administrator':[], 'privileged_manager':[], 'manager':[], 'privileged_member':[], 'member':[], } rolesVariable = Variable.query.filter_by(name='roles', scope='permissions').first() roles.update(rolesVariable.value or {}) for account in [account for account in Account.all() if account.id.startswith('test.')]: for role_id, members in roles.items(): if account.id in members: roles[role_id].remove(account.id) Account.delete(account.id) flash('account deleted: '+str(account)) rolesVariable.value = roles rolesVariable.save() for project in [project for project in Project.all() if project.id.startswith('TEST/')]: Project.delete(project.id) flash('project deleted: '+str(project)) return redirect(url_for('test_data_index'))
def prj_drop(): prjid = json.loads(request.args['prjid']) success = Project.delete(prjid) if not success: msg = 'Record not deleted for unknown reason. Contact admin.' return jsonify(error=msg) data = Project.get_all() return jsonify(projects=data)
def delete(project_id): auth_header = request.headers.get('Authorization') if not auth_header: return jsonify(status="failed", message="No authorization header found.") else: token = auth_header.split(" ")[1] user_id = decode_auth_token(token) user = User.get(User.id == int(user_id)) if user: project = Project.get_or_none(Project.id == project_id) delete = Project.delete().where(Project.id == project_id) if not project: return jsonify(status="failed", message="Could not find project in database.") elif delete.execute(): return jsonify(status="success", message="Project deleted.") else: return jsonify(status="failed", message="Unable to delete project.")