def upload_phenotypes(proj_id): pheno_file = request.files['phenotypes'] filename = secure_filename(pheno_file.filename) # TODO: Also test the file is a CSV if pheno_file: error, result = file_to_obj_list("PHENOTYPES", pheno_file, proj_id) if error: headers, error_list = result return render_template('upload_error_report.html', title="Phenotypes Upload Error Report", filename=filename, headers=headers, errors=error_list) for pheno in result: db.session.add(pheno) # Project log entry log = ProjectLog(proj_id, request.remote_addr, current_user.email, "Uploaded Phenotypes File: '{}'".format(filename)) db.session.add(log) db.session.commit() flash("Successfully uploaded phenotypes file: '{}'".format(filename), "success") else: flash("No phenotypes file", "danger") return redirect(url_for('project', id=proj_id))
def upload_genotypes(proj_id): geno_file = request.files['genotypes'] filename = secure_filename(geno_file.filename) # TODO: Also test the file is a CSV if geno_file: error, result = file_to_obj_list("GENOTYPES", geno_file, proj_id) if error: return render_template( 'upload_error_report.html', title="Genotypes Upload Error Report", filename=filename, headers=["ID", "Marker", "Allele 1", "Allele 2"], errors=result) for geno in result: db.session.add(geno) # Project log entry log = ProjectLog(proj_id, request.remote_addr, current_user.email, "Uploaded Genotypes File: '{}'".format(filename)) db.session.add(log) db.session.commit() flash("Successfully uploaded genotypes file: '{}'".format(filename), "success") else: flash("No genotypes file", "danger") return redirect(url_for('project', id=proj_id))
def upload_individuals(proj_id): ind_file = request.files['individuals'] filename = secure_filename(ind_file.filename) # TODO Also test the file is a CSV if ind_file: error, result = file_to_obj_list("INDIVIDUALS", ind_file, proj_id) if error: return render_template('upload_error_report.html', title="Individuals Upload Error Report", filename=filename, headers=["ID", "Gender"], errors=result) for ind in result: # TODO Test the individual does not already exist # TODO Create dummy parents? db.session.add(ind) # Project log entry log = ProjectLog(proj_id, request.remote_addr, current_user.email, "Uploaded Individuals File: '{}'".format(filename)) db.session.add(log) db.session.commit() flash("Successfully uploaded individuals file: '{}'".format(filename), "success") else: flash("No individuals file", "danger") return redirect(url_for('project', id=proj_id))
def remove_member(user_email, proj_id): num_admins = ProjectMemship.query.filter_by(project_id=proj_id, is_project_admin=True).count() if num_admins == 1 and current_user.email == user_email: flash( "Cannot delete oneself if there is no other project administrator", "danger") return redirect(url_for('project', id=proj_id)) ProjectMemship.query.filter( ProjectMemship.user_email == user_email and ProjectMemship.project_id == proj_id).delete() # Project log entry log = ProjectLog(proj_id, request.remote_addr, current_user.email, ("Removed user " + user_email)) db.session.add(log) db.session.commit() flash("User removed successfully", "success") if current_user.email == user_email: return redirect(url_for('index')) else: return redirect(url_for('project', id=proj_id))
def add_member(proj_id): project_memship = ProjectMemship( user_email=request.form.get('email'), project_id=proj_id, is_project_admin=(request.form.get('is_project_admin') == 'on')) db.session.add(project_memship) # Project log entry message = "Added user " + project_memship.user_email + " as " if project_memship.is_project_admin: message += "administrator" else: message += "contributor" log = ProjectLog(proj_id, request.remote_addr, current_user.email, message) db.session.add(log) db.session.commit() flash("Member added to project", "success") return redirect(url_for('project', id=proj_id))
def delete_project(id): # Delete all members ProjectMemship.query.filter_by(project_id=id).delete() # TODO Delete all geno, pheno, group, indv Genotype.query_by_project(id).delete(synchronize_session=False) Phenotype.query_by_project(id).delete(synchronize_session=False) Individual.query.filter_by(project_id=id).\ delete() # Delete the project itself Project.query.filter_by(id=id).delete() # Project log entry log = ProjectLog(id, request.remote_addr, current_user.email, "Deleted project {}".format(id)) db.session.add(log) db.session.commit() flash("Project deleted successfully", "success") return redirect(url_for('index'))
def add_project(): form = AddProjectForm() if form.validate_on_submit(): project = Project(title=form.title.data, desc=form.desc.data) memship = ProjectMemship(user=current_user, project=project, is_project_admin=True) db.session.add(project) db.session.add(memship) # Need to commit to give the project an id db.session.commit() # Project log entry log = ProjectLog(project.id, request.remote_addr, current_user.email, ("Created project " + str(project))) db.session.add(log) db.session.commit() flash("Added new project", "success") return redirect(url_for('project', id=project.id)) return render_template('add_project.html', title='Add Project', form=form)