def edit_study(study_id=None): # get the data points for display for all researchers in this study query = Researcher.filter_alphabetical(study_relations__study_id=study_id).values_list( "id", "username", "study_relations__relationship", "site_admin" ) # transform raw query data as needed listed_researchers = [] for pk, username, relationship, site_admin in query: listed_researchers.append(( pk, username, "Site Admin" if site_admin else relationship.replace("_", " ").title(), site_admin )) return render_template( 'edit_study.html', study=Study.objects.get(pk=study_id), administerable_researchers=get_administerable_researchers(), allowed_studies=get_researcher_allowed_studies(), listed_researchers=listed_researchers, is_admin=researcher_is_an_admin(), redirect_url='/edit_study/{:s}'.format(study_id), session_researcher=get_session_researcher(), )
def get_administerable_researchers(): """ Site admins see all researchers, study admins see researchers on their studies. """ researcher_admin = get_session_researcher() if researcher_admin.site_admin: relevant_researchers = Researcher.filter_alphabetical() else: relevant_researchers = researcher_admin.get_administered_researchers_by_username( ) return relevant_researchers