def reviewer_action(request): reviewers_formset = formset_factory(ReviewersFormset)(request.POST, request.FILES) if reviewers_formset.is_valid(): for reviewer_form in reviewers_formset: action = reviewer_form.cleaned_data.get('action') if action == 'DELETE': reviewer_delete(request, reviewer_form.cleaned_data.get('id')) elif action == 'REPLACE': year = academic_year.starting_academic_year().year reviewer_id = reviewer_form.cleaned_data.get('id') this_reviewer = reviewer.find_by_id(reviewer_id) entity = entity_version.get_last_version(this_reviewer.entity) form = ReviewerReplacementForm(initial={ 'person': this_reviewer.person, 'id': this_reviewer.id }, prefix="rev", instance=this_reviewer) return render( request, "manager_replace_reviewer.html", { 'reviewer': this_reviewer, 'entity': entity, 'year': year, 'form': form }) return HttpResponseRedirect(reverse('reviewers_list'))
def reviewers_index(request): all_reviewers = reviewer.find_reviewers() initial_formset_content = [{'action': None, 'entity': rev.entity, 'entity_version': entity_version.get_last_version(rev.entity), 'role': rev.role, 'person': rev.person, 'id': rev.id, } for rev in all_reviewers] reviewers_formset = formset_factory(ReviewersFormset, extra=0)(initial=initial_formset_content) for form in reviewers_formset: current_reviewer = reviewer.find_by_id(form['id'].value()) if review.find_by_reviewer(current_reviewer).count() == 0: form.fields['action'].choices = (('-----', _('-----')), ('DELETE', _('delete')), ('REPLACE', _('replace'))) else: form.fields['action'].choices = (('-----', _('-----')), ('REPLACE', _('replace'))) return render(request, "reviewers_list.html", {'reviewers_formset': reviewers_formset })
def reviewer_action(request): reviewers_formset = formset_factory(ReviewersFormset)(request.POST, request.FILES) if reviewers_formset.is_valid(): for reviewer_form in reviewers_formset: action = reviewer_form.cleaned_data.get('action') if action == 'DELETE': reviewer_delete(request, reviewer_form.cleaned_data.get('id')) elif action == 'REPLACE': year = academic_year.current_academic_year().year reviewer_id = reviewer_form.cleaned_data.get('id') this_reviewer = reviewer.find_by_id(reviewer_id) entity = entity_version.get_last_version(this_reviewer.entity) form = ReviewerReplacementForm(initial={'person': this_reviewer.person, 'id': this_reviewer.id}, prefix="rev", instance=this_reviewer) return render(request, "manager_replace_reviewer.html", {'reviewer': this_reviewer, 'entity': entity, 'year': year, 'form': form}) return HttpResponseRedirect(reverse('reviewers_list'))
def reviewer_replace(request): year = academic_year.current_academic_year().year form = ReviewerReplacementForm(data=request.POST, prefix='rev') reviewer_to_replace = reviewer.find_by_id(request.POST.get('reviewer_id')) entity = entity_version.get_last_version(reviewer_to_replace.entity) this_person = request.POST.get('person_id') if form.is_valid() and this_person: this_person = person.find_by_id(this_person) if reviewer.find_by_person(this_person): msg = _("person_already_reviewer_msg") form.add_error(None, msg) else: reviewer_to_replace.person = this_person reviewer_to_replace.save() return redirect('reviewers_list') else: msg = _("bad_person_msg") form.add_error(None, msg) return render(request, "manager_replace_reviewer.html", {'reviewer': reviewer_to_replace, 'entity': entity, 'year': year, 'form': form})
def reviewer_replace(request): year = academic_year.current_academic_year().year if request.POST: form = ReviewerReplacementForm(data=request.POST, prefix='rev') if form.is_valid(): reviewer_to_replace = reviewer.find_by_id(form.cleaned_data.get('id')) if request.POST.get('person_id'): 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, "manager_replace_reviewer.html", {'form': form, 'reviewer': reviewer_to_replace, 'year': year}) else: reviewer_to_replace.person = this_person reviewer_to_replace.save() return redirect('reviewers_list') else: return render(request, "manager_replace_reviewer.html", {'form': form, 'year': year}) else: return redirect('reviewers_list')
def reviewer_replace(request): year = academic_year.starting_academic_year().year form = ReviewerReplacementForm(data=request.POST, prefix='rev') reviewer_to_replace = reviewer.find_by_id(request.POST.get('reviewer_id')) entity = entity_version.get_last_version(reviewer_to_replace.entity) this_person = request.POST.get('person_id') if form.is_valid() and this_person: this_person = person.find_by_id(this_person) reviewer_to_replace.person = this_person reviewer_to_replace.save() return redirect('reviewers_list') else: msg = _( "Please enter the last name and first name of the person you are looking for and select the " "corresponding choice in the drop-down list") form.add_error(None, msg) return render( request, "manager_replace_reviewer.html", { 'reviewer': reviewer_to_replace, 'entity': entity, 'year': year, 'form': form })
def test_find_by_id(self): self.assertEqual(self.reviewer1, reviewer.find_by_id(self.reviewer1.id))
def reviewer_delete(request, reviewer_id): reviewer_to_delete = reviewer.find_by_id(reviewer_id) reviewer_to_delete.delete() return HttpResponseRedirect(reverse('reviewers_list'))