def review_save(request): mandate_id = request.POST.get("mandate_id") review_id = request.POST.get("review_id") rev = review.find_by_id(review_id) mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_person = request.user.person form = ReviewForm(data=request.POST, instance=rev, prefix='rev') menu = generate_phd_supervisor_menu_tabs(mandate, reviewer_role.PHD_SUPERVISOR) previous_mandates = assistant_mandate.find_before_year_for_assistant(mandate.academic_year.year, mandate.assistant) if form.is_valid(): current_review = form.save(commit=False) if 'validate_and_submit' in request.POST: validate_review_and_update_mandate(current_review, mandate) return HttpResponseRedirect(reverse("phd_supervisor_assistants_list")) elif 'save' in request.POST: current_review.status = review_status.IN_PROGRESS current_review.save() return review_edit(request) else: return render(request, "review_form.html", {'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'current_person': current_person, 'absences': mandate.absences, 'comment': mandate.comment, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'menu': menu, 'menu_type': 'phd_supervisor_menu', 'form': form})
def review_save(request): mandate_id = request.POST.get("mandate_id") review_id = request.POST.get("review_id") rev = review.find_by_id(review_id) mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_reviewer = reviewer.can_edit_review( reviewer.find_by_person(person.find_by_user(request.user)).id, mandate_id) form = ReviewForm(data=request.POST, instance=rev, prefix='rev') previous_mandates = assistant_mandate.find_before_year_for_assistant( mandate.academic_year.year, mandate.assistant) role = current_reviewer.role entity = entity_version.get_last_version(current_reviewer.entity) menu = generate_reviewer_menu_tabs(role, mandate, role) if form.is_valid(): current_review = form.save(commit=False) if 'validate_and_submit' in request.POST: current_review.status = review_status.DONE current_review.save() if mandate.state == assistant_mandate_state.PHD_SUPERVISOR: if mandate_entity.find_by_mandate_and_type( mandate, entity_type.INSTITUTE): mandate.state = assistant_mandate_state.RESEARCH elif mandate_entity.find_by_mandate_and_type( mandate, entity_type.POLE): mandate.state = assistant_mandate_state.RESEARCH else: mandate.state = assistant_mandate_state.SUPERVISION elif mandate.state == assistant_mandate_state.RESEARCH: mandate.state = assistant_mandate_state.SUPERVISION elif mandate.state == assistant_mandate_state.SUPERVISION: mandate.state = assistant_mandate_state.VICE_RECTOR elif mandate.state == assistant_mandate_state.VICE_RECTOR: mandate.state = assistant_mandate_state.DONE mandate.save() if current_review.reviewer is not None: return HttpResponseRedirect(reverse("reviewer_mandates_list")) else: return HttpResponseRedirect( reverse("phd_supervisor_assistants_list")) elif 'save' in request.POST: current_review.status = review_status.IN_PROGRESS current_review.save() return review_edit(request) else: return render( request, "review_form.html", { 'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'entity': entity, 'menu': menu, 'menu_type': 'reviewer_menu', 'form': form })
def review_save(request): mandate_id = request.POST.get("mandate_id") review_id = request.POST.get("review_id") rev = review.find_by_id(review_id) mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_reviewer = reviewer.find_by_person(request.user.person) form = ReviewForm(data=request.POST, instance=rev, prefix='rev') previous_mandates = assistant_mandate.find_before_year_for_assistant(mandate.academic_year.year, mandate.assistant) role = current_reviewer.role entity = entity_version.get_last_version(current_reviewer.entity) menu = generate_reviewer_menu_tabs(role, mandate, role) if form.is_valid(): current_review = form.save(commit=False) if 'validate_and_submit' in request.POST: validate_review_and_update_mandate(current_review, mandate) return HttpResponseRedirect(reverse("reviewer_mandates_list_todo")) elif 'save' in request.POST: current_review.status = review_status.IN_PROGRESS current_review.save() return review_edit(request) else: return render(request, "review_form.html", {'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'entity': entity, 'menu': menu, 'menu_type': 'reviewer_menu', 'form': form})
def test_without_advice(self): form = ReviewForm(data={ 'mandate': self.mandate.id, 'advice': None, 'status': self.review.status, 'remark': self.review.remark, 'justification': None, 'changed': self.review.changed }, instance=self.review) self.assertFalse(form.is_valid())
def test_with_valid_data(self): form = ReviewForm(data={ 'mandate': self.mandate.id, 'advice': self.review.advice, 'status': self.review.status, 'remark': self.review.remark, 'justification': self.review.justification, 'changed': self.review.changed }, instance=self.review) self.assertTrue(form.is_valid())
def test_without_advice(self): form = ReviewForm(data={ 'mandate': self.mandate.id, 'advice': None, 'status': self.review.status, 'remark': self.review.remark, 'justification': None, 'changed': self.review.changed }, instance=self.review) self.assertTrue(form.is_valid())
def review_save(request): mandate_id = request.POST.get("mandate_id") review_id = request.POST.get("review_id") rev = review.find_by_id(review_id) mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_reviewer = reviewer.find_by_person(request.user.person) form = ReviewForm(data=request.POST, instance=rev, prefix='rev') previous_mandates = assistant_mandate.find_before_year_for_assistant(mandate.academic_year.year, mandate.assistant) role = current_reviewer.role entity = entity_version.get_last_version(current_reviewer.entity) menu = generate_reviewer_menu_tabs(role, mandate, role) if form.is_valid(): current_review = form.save(commit=False) if 'validate_and_submit' in request.POST: if current_review.advice not in assistant_mandate_renewal.ASSISTANT_MANDATE_RENEWAL_TYPES: errors = form._errors.setdefault("advice", ErrorList()) errors.append(_('advice_missing_in_form')) return render(request, "review_form.html", {'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'reviewer_role': reviewer_role, 'can_validate': reviewer.can_validate(current_reviewer), 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'entity': entity, 'menu': menu, 'menu_type': 'reviewer_menu', 'form': form}) current_review.reviewer = current_reviewer validate_review_and_update_mandate(current_review, mandate) return HttpResponseRedirect(reverse("reviewer_mandates_list_todo")) elif 'save' in request.POST: current_review.reviewer = current_reviewer current_review.status = review_status.IN_PROGRESS current_review.save() return review_edit(request) else: return render(request, "review_form.html", {'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'reviewer_role': reviewer_role, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'entity': entity, 'menu': menu, 'menu_type': 'reviewer_menu', 'form': form})
def review_save(request): mandate_id = request.POST.get("mandate_id") review_id = request.POST.get("review_id") rev = review.find_by_id(review_id) mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_person = request.user.person form = ReviewForm(data=request.POST, instance=rev, prefix='rev') menu = generate_phd_supervisor_menu_tabs(mandate, reviewer_role.PHD_SUPERVISOR) previous_mandates = assistant_mandate.find_before_year_for_assistant( mandate.academic_year.year, mandate.assistant) if form.is_valid(): current_review = form.save(commit=False) if 'validate_and_submit' in request.POST: current_review.status = review_status.DONE current_review.save() if mandate_entity.find_by_mandate_and_type(mandate, entity_type.INSTITUTE): mandate.state = assistant_mandate_state.RESEARCH elif mandate_entity.find_by_mandate_and_type( mandate, entity_type.POLE): mandate.state = assistant_mandate_state.RESEARCH else: mandate.state = assistant_mandate_state.SUPERVISION mandate.save() return HttpResponseRedirect( reverse("phd_supervisor_assistants_list")) elif 'save' in request.POST: current_review.status = review_status.IN_PROGRESS current_review.save() return review_edit(request) else: return render( request, "review_form.html", { 'review': rev, 'role': mandate.state, 'year': mandate.academic_year.year + 1, 'current_person': current_person, 'absences': mandate.absences, 'comment': mandate.comment, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': mandate.assistant, 'menu': menu, 'menu_type': 'phd_supervisor_menu', 'form': form })
def review_edit(request): mandate_id = request.POST.get("mandate_id") mandate = assistant_mandate.find_mandate_by_id(mandate_id) current_reviewer = reviewer.find_by_person(request.user.person) entity = entity_version.get_last_version(current_reviewer.entity) delegate_role = current_reviewer.role + "_ASSISTANT" existing_review = review.find_review_for_mandate_by_role( mandate, delegate_role) if existing_review is None: existing_review, created = review.Review.objects.get_or_create( mandate=mandate, reviewer=current_reviewer, status=review_status.IN_PROGRESS) previous_mandates = assistant_mandate.find_before_year_for_assistant( mandate.academic_year.year, mandate.assistant) role = current_reviewer.role menu = generate_reviewer_menu_tabs(role, mandate, role) assistant = mandate.assistant form = ReviewForm(initial={ 'mandate': mandate, 'reviewer': existing_review.reviewer, 'status': existing_review.status, 'advice': existing_review.advice, 'changed': timezone.now, 'confidential': existing_review.confidential, 'remark': existing_review.remark }, prefix="rev", instance=existing_review) return render( request, 'review_form.html', { 'review': existing_review, 'role': role, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'reviewer_role': reviewer_role, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'assistant': assistant, 'can_validate': reviewer.can_validate(current_reviewer), 'current_reviewer': current_reviewer, 'entity': entity, 'menu': menu, 'menu_type': 'reviewer_menu', 'form': form })
def review_edit(request): mandate_id = request.POST.get("mandate_id") mandate = assistant_mandate.find_mandate_by_id(mandate_id) try: review.find_done_by_supervisor_for_mandate(mandate) return HttpResponseRedirect(reverse("assistants_home")) except: existing_review, created = review.Review.objects.get_or_create( mandate=mandate, reviewer=None, status=review_status.IN_PROGRESS) previous_mandates = assistant_mandate.find_before_year_for_assistant( mandate.academic_year.year, mandate.assistant) menu = generate_phd_supervisor_menu_tabs(mandate, reviewer_role.PHD_SUPERVISOR) assistant = mandate.assistant current_person = request.user.person form = ReviewForm(initial={ 'mandate': mandate, 'reviewer': existing_review.reviewer, 'status': existing_review.status, 'advice': existing_review.advice, 'changed': timezone.now, 'confidential': existing_review.confidential, 'remark': existing_review.remark }, prefix="rev", instance=existing_review) return render( request, 'review_form.html', { 'review': existing_review, 'role': reviewer_role.PHD_SUPERVISOR, 'year': mandate.academic_year.year + 1, 'absences': mandate.absences, 'comment': mandate.comment, 'mandate_id': mandate.id, 'previous_mandates': previous_mandates, 'current_person': current_person, 'can_validate': True, 'assistant': assistant, 'menu': menu, 'menu_type': 'phd_supervisor_menu', 'form': form })