def test_can_delegate_to_entity(self): self.assertFalse( reviewer.can_delegate_to_entity(self.reviewer1, self.entity1)) self.assertFalse( reviewer.can_delegate_to_entity(self.reviewer2, self.entity1)) self.assertTrue( reviewer.can_delegate_to_entity(self.reviewer2, self.entity2)) self.assertTrue( reviewer.can_delegate_to_entity(self.reviewer3, self.entity4)) self.assertFalse( reviewer.can_delegate_to_entity(self.reviewer4, self.entity1))
def add_reviewer_for_structure(request): current_entity = entity.find_by_id(request.POST.get("entity")) year = academic_year.current_academic_year().year if not reviewer.can_delegate_to_entity(reviewer.find_by_person(request.user.person), current_entity): return redirect('assistants_home') form = ReviewerDelegationForm(data=request.POST) if form.is_valid() and request.POST.get('person_id'): new_reviewer = form.save(commit=False) this_person = person.find_by_id(request.POST.get('person_id')) if reviewer.find_by_person(this_person): msg = _("person_already_reviewer_msg") form.add_error(None, msg) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) }) new_reviewer.person = this_person new_reviewer.save() html_template_ref = 'assistant_reviewers_startup_html' txt_template_ref = 'assistant_reviewers_startup_txt' send_message(person=this_person, html_template_ref=html_template_ref, txt_template_ref=txt_template_ref) return redirect('reviewer_delegation') else: this_reviewer = reviewer.find_by_person(person=request.user.person) role = this_reviewer.role + '_ASSISTANT' form = ReviewerDelegationForm(initial={'entity': current_entity, 'year': year, 'role': role}) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) })
def add_reviewer_for_structure(request): current_entity = entity.find_by_id(request.POST.get("entity")) year = academic_year.current_academic_year().year if not reviewer.can_delegate_to_entity(reviewer.find_by_person(request.user.person), current_entity): return redirect('assistants_home') form = ReviewerDelegationForm(data=request.POST) if form.is_valid() and request.POST.get('person_id'): new_reviewer = form.save(commit=False) this_person = person.find_by_id(request.POST.get('person_id')) if reviewer.find_by_person(this_person): msg = _("person_already_reviewer_msg") form.add_error(None, msg) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) }) new_reviewer.person = this_person new_reviewer.save() html_template_ref = 'assistant_reviewers_startup_html' txt_template_ref = 'assistant_reviewers_startup_txt' send_message(person=this_person, html_template_ref=html_template_ref, txt_template_ref=txt_template_ref) return redirect('reviewer_delegation') else: this_reviewer = reviewer.find_by_person(person=request.user.person) role = this_reviewer.role + '_ASSISTANT' form = ReviewerDelegationForm(initial={'entity': current_entity, 'year': year, 'role': role}) return render(request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'entity': current_entity, 'reviewer': reviewer.find_by_person(request.user.person) })
def test_can_delegate_to_entity(self): self.assertFalse(reviewer.can_delegate_to_entity(self.reviewer1, self.entity1)) self.assertFalse(reviewer.can_delegate_to_entity(self.reviewer2, self.entity1)) self.assertTrue(reviewer.can_delegate_to_entity(self.reviewer2, self.entity2)) self.assertTrue(reviewer.can_delegate_to_entity(self.reviewer3, self.entity4)) self.assertFalse(reviewer.can_delegate_to_entity(self.reviewer4, self.entity1))
def add_reviewer_for_structure(request): entity_id = request.POST.get("entity_id") related_entity = entity.get_by_internal_id(entity_id) current_entity_version = entity_version.get_last_version( entity.get_by_internal_id(entity_id)) year = academic_year.current_academic_year().year try: reviewer.can_delegate_to_entity( reviewer.find_by_person(request.user.person), related_entity) except: return redirect('assistants_home') if request.POST: form = ReviewerDelegationForm(data=request.POST) if form.is_valid(): new_reviewer = form.save(commit=False) if request.POST.get('person_id'): this_person = person.find_by_id(request.POST.get('person_id')) try: reviewer.find_by_person(this_person) msg = _("person_already_reviewer_msg") form.add_error(None, msg) return render( request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'related_entity': related_entity, 'current_entity_version': current_entity_version, 'reviewer': reviewer.find_by_person(request.user.person) }) except reviewer.Reviewer.DoesNotExist: pass new_reviewer.person = this_person new_reviewer.save() html_template_ref = 'assistant_reviewers_startup_html' txt_template_ref = 'assistant_reviewers_startup_txt' send_message(person=this_person, html_template_ref=html_template_ref, txt_template_ref=txt_template_ref) return redirect('reviewer_delegation') else: this_reviewer = reviewer.find_by_person(person=request.user.person) if this_reviewer.role == reviewer_role.SUPERVISION: role = reviewer_role.SUPERVISION_ASSISTANT else: role = reviewer_role.RESEARCH_ASSISTANT form = ReviewerDelegationForm(initial={ 'entity': related_entity, 'year': year, 'role': role }) reviewer_entity = entity_version.get_last_version( this_reviewer.entity) return render( request, "reviewer_add_reviewer.html", { 'form': form, 'year': year, 'related_entity': related_entity, 'entity': reviewer_entity, 'current_entity_version': current_entity_version, 'reviewer': reviewer.find_by_person(request.user.person) })
def reviewer_eligible_to_delegate(reviewers, entity_to_delegate): for rev in reviewers: if reviewer.can_delegate_to_entity(rev, entity_to_delegate): return rev return None