Beispiel #1
0
def rename_study(study_id=None):
    study = Study.objects.get(pk=study_id)
    assert_admin(study_id)
    new_study_name = request.form.get('new_study_name', '')
    study.name = new_study_name
    study.save()
    return redirect('/edit_study/{:d}'.format(study.pk))
def delete_study(study_id=None):
    # Site admins and study admins can delete studies.
    assert_admin(study_id)

    if request.form.get('confirmation', 'false') == 'true':
        study = Study.objects.get(pk=study_id)
        study.mark_deleted()
        flash("Deleted study '%s'" % study.name, 'success')
        return "success"
Beispiel #3
0
def add_researcher_to_study():
    researcher_id = request.values['researcher_id']
    study_id = request.values['study_id']
    assert_admin(study_id)
    StudyRelation.objects.get_or_create(study_id=study_id,
                                        researcher_id=researcher_id,
                                        relationship=ResearcherRole.researcher)

    # This gets called by both edit_researcher and edit_study, so the POST request
    # must contain which URL it came from.
    return redirect(request.values['redirect_url'])
Beispiel #4
0
def remove_researcher_from_study():
    researcher_id = request.values['researcher_id']
    study_id = request.values['study_id']
    try:
        researcher = Researcher.objects.get(pk=researcher_id)
    except Researcher.DoesNotExist:
        return abort(404)
    assert_admin(study_id)
    assert_researcher_under_admin(researcher, study_id)
    StudyRelation.objects.filter(study_id=study_id, researcher_id=researcher_id).delete()
    return redirect(request.values['redirect_url'])
def demote_study_admin():
    researcher_pk = request.values.get("researcher_id")
    study_pk = request.values.get("study_id")
    assert_admin(study_pk)
    # assert_researcher_under_admin() would fail here...
    StudyRelation.objects.filter(
        researcher=Researcher.objects.get(pk=researcher_pk),
        study=Study.objects.get(pk=study_pk),
    ).update(relationship=ResearcherRole.researcher)

    redirect_url = request.values.get("redirect_url", None) or '/edit_researcher/{:s}'.format(researcher_pk)
    return redirect(redirect_url)
def elevate_researcher_to_study_admin():
    researcher_pk = request.values.get("researcher_id")
    study_pk = request.values.get("study_id")
    assert_admin(study_pk)
    edit_researcher = Researcher.objects.get(pk=researcher_pk)
    study = Study.objects.get(pk=study_pk)
    assert_researcher_under_admin(edit_researcher, study)
    StudyRelation.objects.filter(
        researcher=edit_researcher,
        study=study,
    ).update(relationship=ResearcherRole.study_admin)
    redirect_url = request.values.get("redirect_url", None) or '/edit_researcher/{:s}'.format(researcher_pk)
    return redirect(redirect_url)
Beispiel #7
0
def add_researcher_to_study():
    researcher_id = request.values['researcher_id']
    study_id = request.values['study_id']
    assert_admin(study_id)
    try:
        StudyRelation.objects.get_or_create(
            study_id=study_id, researcher_id=researcher_id, relationship=ResearcherRole.researcher
        )
    except ValidationError:
        # handle case of the study id + researcher already existing
        pass

    # This gets called by both edit_researcher and edit_study, so the POST request
    # must contain which URL it came from.
    return redirect(request.values['redirect_url'])