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)
        })
Пример #2
0
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)
        })
Пример #3
0
def build_doc(request, mandates):
    year = mandates[0].academic_year
    filename = ('%s_%s_%s.pdf' %
                (_('assistants_mandates'), year, time.strftime("%Y%m%d_%H%M")))
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    buffer = BytesIO()
    doc = SimpleDocTemplate(buffer,
                            pagesize=PAGE_SIZE,
                            rightMargin=MARGIN_SIZE,
                            leftMargin=MARGIN_SIZE,
                            topMargin=70,
                            bottomMargin=25)
    styles = getSampleStyleSheet()
    styles.add(
        ParagraphStyle(
            name='Tiny',
            fontSize=6,
            font='Helvetica',
            leading=8,
            leftIndent=0,
            rightIndent=0,
            firstLineIndent=0,
            alignment=TA_LEFT,
            spaceBefore=0,
            spaceAfter=0,
            splitLongWords=1,
        ))
    styles.add(
        ParagraphStyle(
            name='StandardWithBorder',
            font='Helvetica',
            leading=18,
            leftIndent=10,
            rightIndent=10,
            firstLineIndent=0,
            alignment=TA_JUSTIFY,
            spaceBefore=25,
            spaceAfter=5,
            splitLongWords=1,
            borderColor='#000000',
            borderWidth=1,
            borderPadding=10,
        ))
    content = []
    if academic_assistant.find_by_person(find_by_user(request.user)):
        role = user_role.ASSISTANT
    elif reviewer.find_by_person(find_by_user(request.user)):
        role = reviewer.find_by_person(find_by_user(request.user)).role
    else:
        role = user_role.ADMINISTRATOR
    for mandate in mandates:
        add_mandate_content(content, mandate, styles, role)
    doc.build(content, add_header_footer)
    pdf = buffer.getvalue()
    buffer.close()
    response.write(pdf)
    return response
Пример #4
0
def assistant_home(request):
    if settings.access_to_procedure_is_open(
    ) and academic_assistant.find_by_person(person=request.user.person):
        return HttpResponseRedirect(reverse('assistant_mandates'))
    else:
        try:
            manager.find_by_person(person=request.user.person)
            return HttpResponseRedirect(reverse('manager_home'))
        except manager.Manager.DoesNotExist:
            try:
                reviewer.find_by_person(person=request.user.person)
                return HttpResponseRedirect(
                    reverse('reviewer_mandates_list_todo'))
            except reviewer.Reviewer.DoesNotExist:
                return HttpResponseRedirect(reverse('access_denied'))
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 test_context_data(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, HttpResponse.status_code)

        context = response.context

        entities_vers_qs = entity_version.EntityVersion.objects.filter(
            pk__in=[self.institute.pk, self.institute_child.pk])
        self.assertQuerysetEqual(context['object_list'],
                                 entities_vers_qs,
                                 transform=lambda x: x,
                                 ordered=False)
        self.assertQuerysetEqual(
            context["object_list"],
            [tuple(), (self.research_assistant_reviewer, )],
            transform=lambda x: tuple(x.entity.delegated_reviewer),
            ordered=False)

        self.assertEqual(
            context['entity'],
            entity_version.get_last_version(self.research_reviewer.entity))
        self.assertEqual(context['year'], self.current_academic_year.year)
        self.assertEqual(context['current_reviewer'],
                         find_by_person(self.research_reviewer.person)[0])
        self.assertFalse(context['is_supervisor'])
Пример #7
0
 def get_context_data(self, **kwargs):
     context = super(MandatesListView, self).get_context_data(**kwargs)
     phd_list = ['RESEARCH', 'SUPERVISION', 'VICE_RECTOR', 'DONE']
     research_list = ['SUPERVISION', 'VICE_RECTOR', 'DONE']
     supervision_list = ['VICE_RECTOR', 'DONE']
     vice_rector_list = ['VICE_RECTOR', 'DONE']
     current_reviewer = reviewer.find_by_person(self.request.user.person)
     can_delegate = reviewer.can_delegate(current_reviewer)
     context['can_delegate'] = can_delegate
     context['reviewer'] = current_reviewer
     entity = entity_version.get_last_version(current_reviewer.entity)
     context['entity'] = entity
     context['phd_list'] = phd_list
     context['research_list'] = research_list
     context['supervision_list'] = supervision_list
     context['vice_rector_list'] = vice_rector_list
     context['is_supervisor'] = self.is_supervisor
     context['filter'] = self.kwargs.get("filter", None)
     context['year'] = academic_year.find_academic_year_by_id(
         self.request.session.get('selected_academic_year')).year
     start_date = academic_year.find_academic_year_by_id(
         int(self.request.session.get('selected_academic_year'))).start_date
     for mandate in context['object_list']:
         entities = []
         entities_id = mandate.mandateentity_set.all().order_by('id')
         for entity in entities_id:
             current_entityversion = entity_version.get_by_entity_and_date(
                 entity.entity, start_date)[0]
             if current_entityversion is None:
                 current_entityversion = entity_version.get_last_version(
                     entity.entity)
             entities.append(current_entityversion)
         mandate.entities = entities
     return context
Пример #8
0
 def get_queryset(self):
     form_class = MandatesArchivesForm
     form = form_class(self.request.GET)
     current_reviewer = reviewer.find_by_person(self.request.user.person)
     if len(
             assistant_mandate.find_for_supervisor_for_academic_year(
                 self.request.user.person,
                 academic_year.current_academic_year())) > 0:
         self.is_supervisor = True
     mandates_id = mandate_entity.find_by_entity(
         current_reviewer.entity).values_list('assistant_mandate_id',
                                              flat=True)
     if form.is_valid():
         self.request.session['selected_academic_year'] = form.cleaned_data[
             'academic_year'].id
         selected_academic_year = academic_year.AcademicYear.objects.get(
             id=self.request.session.get('selected_academic_year'))
     elif self.request.session.get('selected_academic_year'):
         selected_academic_year = academic_year.AcademicYear.objects.get(
             id=self.request.session.get('selected_academic_year'))
     else:
         selected_academic_year = academic_year.current_academic_year()
         self.request.session[
             'selected_academic_year'] = selected_academic_year.id
     if self.kwargs.get("filter", None):
         selected_academic_year = academic_year.current_academic_year()
         self.request.session[
             'selected_academic_year'] = selected_academic_year.id
         queryset = assistant_mandate.find_by_academic_year(selected_academic_year).filter(id__in=mandates_id).\
             filter(state=current_reviewer.role.replace('_ASSISTANT', ''))
     else:
         queryset = assistant_mandate.find_by_academic_year(
             selected_academic_year).filter(id__in=mandates_id)
     return queryset
 def get_context_data(self, **kwargs):
     context = super(AssistantsListView, self).get_context_data(**kwargs)
     context['year'] = academic_year.current_academic_year().year
     start_date = academic_year.current_academic_year().start_date
     context['is_reviewer'] = self.is_reviewer
     context['current_reviewer'] = self.reviewer
     if self.reviewer:
         entity = entity_version.get_last_version(self.reviewer.entity)
     else:
         entity = None
     context['entity'] = entity
     if self.is_reviewer:
         can_delegate = reviewer.can_delegate(
             reviewer.find_by_person(self.request.user.person))
         context['can_delegate'] = can_delegate
     else:
         context['can_delegate'] = False
     for mandate in context['object_list']:
         entities = []
         entities_id = mandate.mandateentity_set.all().order_by('id')
         for entity in entities_id:
             current_entityversion = entity_version.get_by_entity_and_date(
                 entity.entity, start_date)[0]
             if current_entityversion is None:
                 current_entityversion = entity_version.get_last_version(
                     entity.entity)
             entities.append(current_entityversion)
         mandate.entities = entities
     return context
Пример #10
0
def add_reviewer_for_structure(request):
    current_entity = entity.find_by_id(request.POST.get("entity"))
    year = academic_year.starting_academic_year().year
    current_reviewer = reviewer_eligible_to_delegate(
        reviewer.find_by_person(request.user.person),
        current_entity
    )
    if not current_reviewer:
        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)
        new_reviewer.person = person.find_by_id(request.POST.get('person_id'))
        new_reviewer.save()
        send_message(
            person=new_reviewer.person,
            html_template_ref='assistant_reviewers_startup_html',
            txt_template_ref='assistant_reviewers_startup_txt'
        )
        return redirect('reviewer_delegation')

    role = current_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': current_reviewer
    })
Пример #11
0
def review_view(request):
    mandate_id = request.POST.get("mandate_id")
    role = request.POST.get("role")
    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)
    current_role = current_reviewer.role
    if role == reviewer_role.PHD_SUPERVISOR:
        try:
            current_review = review.find_done_by_supervisor_for_mandate(mandate)
        except ObjectDoesNotExist:
            current_review = None
    else:
        current_review = review.find_review_for_mandate_by_role(mandate, role)
    assistant = mandate.assistant
    menu = generate_reviewer_menu_tabs(current_role, mandate, role)
    return render(request, 'review_view.html', {'review': current_review,
                                                'role': current_role,
                                                'menu': menu,
                                                'menu_type': 'reviewer_menu',
                                                'mandate_id': mandate.id,
                                                'mandate_state': mandate.state,
                                                'current_reviewer': current_reviewer,
                                                'entity': entity,
                                                'assistant': assistant,
                                                'year': mandate.academic_year.year + 1
                                                })
Пример #12
0
def pst_form_view(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)
    current_role = current_reviewer.role
    entity = entity_version.get_last_version(current_reviewer.entity)
    entities = get_entities_for_mandate(mandate)
    learning_units = tutoring_learning_unit_year.find_by_mandate(mandate)
    phd_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                  document_type.PHD_DOCUMENT)
    research_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                       document_type.RESEARCH_DOCUMENT)
    tutoring_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                       document_type.TUTORING_DOCUMENT)
    assistant = mandate.assistant
    menu = generate_reviewer_menu_tabs(current_role, mandate, None)
    return render(request, 'pst_form_view.html', {'menu': menu,
                                                  'menu_type': 'reviewer_menu',
                                                  'mandate_id': mandate.id,
                                                  'assistant': assistant, 'mandate': mandate,
                                                  'learning_units': learning_units,
                                                  'entity': entity,
                                                  'entities': entities,
                                                  'phd_files': phd_files,
                                                  'assistant_mandate_renewal': assistant_mandate_renewal,
                                                  'research_files': research_files,
                                                  'tutoring_files': tutoring_files,
                                                  'current_reviewer': current_reviewer,
                                                  'role': current_role,
                                                  'year': mandate.academic_year.year + 1})
Пример #13
0
def pst_form_view(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)
    current_role = current_reviewer.role
    entity = entity_version.get_last_version(current_reviewer.entity)
    entities = get_entities_for_mandate(mandate)
    learning_units = tutoring_learning_unit_year.find_by_mandate(mandate)
    phd_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                  document_type.PHD_DOCUMENT)
    research_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                       document_type.RESEARCH_DOCUMENT)
    tutoring_files = assistant_document_file.find_by_assistant_mandate_and_description(mandate,
                                                                                       document_type.TUTORING_DOCUMENT)
    assistant = mandate.assistant
    menu = generate_reviewer_menu_tabs(current_role, mandate, None)
    return render(request, 'pst_form_view.html', {'menu': menu,
                                                  'menu_type': 'reviewer_menu',
                                                  'mandate_id': mandate.id,
                                                  'assistant': assistant, 'mandate': mandate,
                                                  'learning_units': learning_units,
                                                  'entity': entity,
                                                  'entities': entities,
                                                  'phd_files': phd_files,
                                                  'assistant_mandate_renewal': assistant_mandate_renewal,
                                                  'research_files': research_files,
                                                  'tutoring_files': tutoring_files,
                                                  'current_reviewer': current_reviewer,
                                                  'role': current_role,
                                                  'year': mandate.academic_year.year + 1})
Пример #14
0
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_context_data(self):
     self.client.force_login(self.reviewer.person.user)
     response = self.client.get('/assistants/reviewer/delegation/')
     entities_version = entity_version.get_last_version(
         self.reviewer.entity).children
     entities = [
         this_entity_version.entity
         for this_entity_version in entities_version
     ]
     entities.insert(
         0,
         entity_version.get_last_version(self.reviewer.entity).entity)
     queryset = [{
         'id':
         entity.id,
         'title':
         entity_version.get_last_version(entity, None).title,
         'acronym':
         entity.most_recent_acronym,
         'has_already_delegate':
         get_delegate_for_entity(self.reviewer, entity)
     } for entity in entities]
     self.assertQuerysetEqual(response.context['object_list'],
                              queryset,
                              transform=lambda x: x)
     self.assertEqual(response.context['entity'],
                      entity_version.get_last_version(self.reviewer.entity))
     self.assertEqual(response.context['year'],
                      self.current_academic_year.year)
     self.assertEqual(response.status_code, HTTP_OK)
     self.assertEqual(response.context['current_reviewer'],
                      find_by_person(self.reviewer.person))
     self.assertEqual(response.context['is_supervisor'],
                      is_supervisor(self.reviewer.person))
Пример #16
0
def review_view(request):
    mandate_id = request.POST.get("mandate_id")
    role = request.POST.get("role")
    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)
    current_role = current_reviewer.role
    if role == reviewer_role.PHD_SUPERVISOR:
        try:
            current_review = review.find_done_by_supervisor_for_mandate(mandate)
        except ObjectDoesNotExist:
            current_review = None
    else:
        current_review = review.find_review_for_mandate_by_role(mandate, role)
    assistant = mandate.assistant
    menu = generate_reviewer_menu_tabs(current_role, mandate, role)
    return render(request, 'review_view.html', {'review': current_review,
                                                'role': current_role,
                                                'menu': menu,
                                                'menu_type': 'reviewer_menu',
                                                'mandate_id': mandate.id,
                                                'mandate_state': mandate.state,
                                                'current_reviewer': current_reviewer,
                                                'entity': entity,
                                                'assistant': assistant,
                                                'year': mandate.academic_year.year + 1
                                                })
Пример #17
0
 def test_func(self):
     try:
         if settings.access_to_procedure_is_open():
             return reviewer.can_delegate(
                 reviewer.find_by_person(self.request.user.person))
     except ObjectDoesNotExist:
         return False
 def get_queryset(self):
     form_class = MandatesArchivesForm
     form = form_class(self.request.GET)
     current_reviewer = reviewer.find_by_person(self.request.user.person)
     if len(assistant_mandate.find_for_supervisor_for_academic_year(self.request.user.person,
                                                                    academic_year.current_academic_year())) > 0:
         self.is_supervisor = True
     mandates_id = mandate_entity.find_by_entity(current_reviewer.entity).values_list(
         'assistant_mandate_id', flat=True)
     if form.is_valid():
         self.request.session['selected_academic_year'] = form.cleaned_data[
             'academic_year'].id
         selected_academic_year = academic_year.AcademicYear.objects.get(
             id=self.request.session.get('selected_academic_year'))
     elif self.request.session.get('selected_academic_year'):
         selected_academic_year = academic_year.AcademicYear.objects.get(
             id=self.request.session.get('selected_academic_year'))
     else:
         selected_academic_year = academic_year.current_academic_year()
         self.request.session[
             'selected_academic_year'] = selected_academic_year.id
     if self.kwargs.get("filter", None):
         selected_academic_year = academic_year.current_academic_year()
         self.request.session[
             'selected_academic_year'] = selected_academic_year.id
         queryset = assistant_mandate.find_by_academic_year(selected_academic_year).filter(id__in=mandates_id).\
             filter(state=current_reviewer.role.replace('_ASSISTANT', '').replace('_DAF', ''))
     else:
         queryset = assistant_mandate.find_by_academic_year(selected_academic_year).filter(id__in=mandates_id)
     return queryset
def user_is_reviewer_and_procedure_is_open(user):
    try:
        if user.is_authenticated() and settings.access_to_procedure_is_open():
            return reviewer.find_by_person(user.person)
        else:
            return False
    except ObjectDoesNotExist:
        return False
 def test_context_data_phd_supervisor_is_reviewer(self):
     self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH,
                                     entity=self.entity_version.entity,
                                     person=self.phd_supervisor)
     self.client.force_login(self.phd_supervisor.user)
     response = self.client.get('/assistants/phd_supervisor/assistants/')
     self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor))
     self.assertTrue(response.context['can_delegate'])
Пример #21
0
 def get_context_data(self, **kwargs):
     context = super(StructuresListView, self).get_context_data(**kwargs)
     context['year'] = academic_year.current_academic_year().year
     context['current_reviewer'] = reviewer.find_by_person(self.request.user.person)
     entity = entity_version.get_last_version(context['current_reviewer'].entity)
     context['entity'] = entity
     context['is_supervisor'] = is_supervisor(self.request.user.person)
     return context
 def get_context_data(self, **kwargs):
     context = super(StructuresListView, self).get_context_data(**kwargs)
     context['year'] = academic_year.current_academic_year().year
     context['current_reviewer'] = reviewer.find_by_person(self.request.user.person)
     entity = entity_version.get_last_version(context['current_reviewer'].entity)
     context['entity'] = entity
     context['is_supervisor'] = is_supervisor(self.request.user.person)
     return context
Пример #23
0
def export_mandates_for_entity(request: http.HttpRequest, year: int):
    mandates = assistant_mandate.AssistantMandate.objects.filter(
        mandateentity__entity__in=reviewer.find_by_person(
            find_by_user(request.user)).values_list("entity", flat=True),
        academic_year=academic_year.find_academic_year_by_year(year)).order_by(
            'assistant__person__last_name')
    if mandates:
        return build_doc(request, mandates)
    return HttpResponseRedirect(reverse('reviewer_mandates_list'))
 def get_queryset(self):
     try:
         self.reviewer = reviewer.find_by_person(self.request.user.person)
         self.is_reviewer = True
     except ObjectDoesNotExist:
         self.is_reviewer = False
         self.reviewer = None
     return assistant_mandate.find_for_supervisor_for_academic_year(
         self.request.user.person, academic_year.current_academic_year())
Пример #25
0
def export_mandates_for_entity(request, year):
    current_reviewer = reviewer.find_by_person(find_by_user(request.user))
    mandates = find_mandates_for_academic_year_and_entity(
        academic_year.find_academic_year_by_year(year),
        current_reviewer.entity)
    if mandates:
        return build_doc(request, mandates)
    else:
        return HttpResponseRedirect(reverse('reviewer_mandates_list'))
 def test_context_data_phd_supervisor_is_reviewer(self):
     self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH,
                                     entity=self.entity_version.entity,
                                     person=self.phd_supervisor)
     self.client.force_login(self.phd_supervisor.user)
     response = self.client.get('/assistants/phd_supervisor/assistants/')
     self.assertEqual(response.context['current_reviewer'],
                      find_by_person(self.phd_supervisor))
     self.assertTrue(response.context['can_delegate'])
Пример #27
0
def export_mandates_for_entity(request, year):
    current_reviewer = reviewer.find_by_person(find_by_user(request.user))
    mandates = find_mandates_for_academic_year_and_entity(
        academic_year.find_academic_year_by_year(year),
        current_reviewer.entity
    )
    if mandates:
        return build_doc(request, mandates)
    else:
        return HttpResponseRedirect(reverse('reviewer_mandates_list'))
 def test_add_reviewer_for_structure_with_valid_data(self):
     data = {
         'person_id': self.delegate.id,
         'entity': self.institute.entity.id,
         'role': self.research_reviewer.role
     }
     response = self.client.post(self.url, data)
     self.assertEqual(response.status_code,
                      HttpResponseRedirect.status_code)
     self.assertTrue(find_by_person(self.delegate))
 def get_context_data(self, **kwargs):
     context = super(AssistantsListView, self).get_context_data(**kwargs)
     context['year'] = academic_year.current_academic_year().year
     context['current_reviewer'] = self.reviewer
     if self.reviewer:
         can_delegate = reviewer.can_delegate(reviewer.find_by_person(self.request.user.person))
         context['can_delegate'] = can_delegate
     else:
         context['can_delegate'] = False
     return add_entities_version_to_mandates_list(context)
 def get_context_data(self, **kwargs):
     context = super(AssistantsListView, self).get_context_data(**kwargs)
     context['year'] = academic_year.current_academic_year().year
     context['current_reviewer'] = self.reviewer
     if self.reviewer:
         can_delegate = reviewer.can_delegate(reviewer.find_by_person(self.request.user.person))
         context['can_delegate'] = can_delegate
     else:
         context['can_delegate'] = False
     return add_entities_version_to_mandates_list(context)
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['year'] = academic_year.starting_academic_year().year
     reviewers = reviewer.find_by_person(self.request.user.person)
     context['current_reviewer'] = reviewers.first()
     if reviewers:
         context['can_delegate'] = any(
             reviewer.can_delegate(rev) for rev in reviewers)
     else:
         context['can_delegate'] = False
     return add_entities_version_to_mandates_list(context)
 def test_can_add_reviewer_for_structure_with_person_already_reviewer(self):
     data = {
         'person_id': self.vice_sector_reviewer.person.id,
         'entity': self.institute.entity.id,
         'role': self.research_reviewer.role
     }
     response = self.client.post(self.url, data)
     self.assertEqual(response.status_code,
                      HttpResponseRedirect.status_code)
     self.assertEqual(len(find_by_person(self.vice_sector_reviewer.person)),
                      2)
Пример #33
0
 def get_queryset(self):
     if len(
             assistant_mandate.find_for_supervisor_for_academic_year(
                 self.request.user.person,
                 academic_year.current_academic_year())) > 0:
         self.is_supervisor = True
     rev = reviewer.find_by_person(self.request.user.person)
     main_entity_version = entity_version.get_last_version(rev.entity)
     queryset = list(main_entity_version.find_direct_children())
     queryset.insert(0, main_entity_version)
     return queryset
 def test_add_reviewer_for_structure_with_valid_data(self):
     self.client.force_login(self.reviewer.person.user)
     this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0]
     response = self.client.post('/assistants/reviewer/delegate/add/',
                                 {
                                     'person_id': self.delegate.id,
                                     'entity': this_entity.id,
                                     'role': self.reviewer.role
                                 }
                                 )
     self.assertEqual(response.status_code, HTTP_FOUND)
     self.assertTrue(find_by_person(self.delegate))
Пример #35
0
 def get_queryset(self):
     rev = reviewer.find_by_person(self.request.user.person)
     entities_version = entity_version.get_last_version(rev.entity).children
     entities = [this_entity_version.entity for this_entity_version in entities_version]
     entities.insert(0, entity_version.get_last_version(rev.entity).entity)
     queryset = [{
         'id': entity.id,
         'title': entity_version.get_last_version(entity, None).title,
         'acronym': entity.most_recent_acronym,
         'has_already_delegate': reviewer.get_delegate_for_entity(rev, entity)
     } for entity in entities]
     return queryset
 def get_queryset(self):
     rev = reviewer.find_by_person(self.request.user.person)
     entities_version = entity_version.get_last_version(rev.entity).children
     entities = [this_entity_version.entity for this_entity_version in entities_version]
     entities.insert(0, entity_version.get_last_version(rev.entity).entity)
     queryset = [{
         'id': entity.id,
         'title': entity_version.get_last_version(entity, None).title,
         'acronym': entity.most_recent_acronym,
         'has_already_delegate': reviewer.get_delegate_for_entity(rev, entity)
     } for entity in entities]
     return queryset
Пример #37
0
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 test_add_reviewer_for_structure_with_valid_data(self):
     self.client.force_login(self.reviewer.person.user)
     this_entity = find_versions_from_entites([self.entity_factory.id],
                                              date=None)[0]
     response = self.client.post(
         '/assistants/reviewer/delegate/add/', {
             'person_id': self.delegate.id,
             'entity': this_entity.id,
             'role': self.reviewer.role
         })
     self.assertEqual(response.status_code, HTTP_FOUND)
     self.assertTrue(find_by_person(self.delegate))
Пример #39
0
def build_doc(request, mandates, type='default'):
    if mandates:
        year = mandates[0].academic_year
    else:
        year = academic_year.current_academic_year()
    if type is 'export_to_sap':
        filename = ('%s_%s_%s.pdf' % (mandates[0].sap_id, year, mandates[0].assistant.person))
    else:
        filename = ('%s_%s_%s.pdf' % (_('assistants_mandates'), year, time.strftime("%Y%m%d_%H%M")))
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    buffer = BytesIO()
    doc = SimpleDocTemplate(buffer, pagesize=PAGE_SIZE, rightMargin=MARGIN_SIZE, leftMargin=MARGIN_SIZE, topMargin=70,
                            bottomMargin=25)
    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle(name='Tiny', fontSize=6, font='Helvetica', leading=8, leftIndent=0, rightIndent=0,
                              firstLineIndent=0, alignment=TA_LEFT, spaceBefore=0, spaceAfter=0, splitLongWords=1, ))
    styles.add(ParagraphStyle(name='StandardWithBorder', font='Helvetica', leading=18, leftIndent=10, rightIndent=10,
                              firstLineIndent=0, alignment=TA_JUSTIFY, spaceBefore=25, spaceAfter=5, splitLongWords=1,
                              borderColor='#000000', borderWidth=1, borderPadding=10, ))
    content = []
    if academic_assistant.find_by_person(find_by_user(request.user)):
        role = user_role.ASSISTANT
    elif reviewer.find_by_person(find_by_user(request.user)):
        role = reviewer.find_by_person(find_by_user(request.user)).role
    else:
        role = user_role.ADMINISTRATOR
    if type is 'default' or type is 'export_to_sap':
        for mandate in mandates:
            add_mandate_content(content, mandate, styles, role)
    else:
        content.append(create_paragraph("%s (%s)<br />" % (_('declined_mandates'), year), '', styles["BodyText"]))
        if mandates:
            write_table(content, add_declined_mandates(mandates, styles['Tiny']), COLS_WIDTH_FOR_DECLINED_MANDATES)
            content.append(PageBreak())
    doc.build(content, add_header_footer)
    pdf = buffer.getvalue()
    buffer.close()
    response.write(pdf)
    return response
 def test_context_data_phd_supervisor_is_not_reviewer(self):
     self.client.force_login(self.phd_supervisor.user)
     response = self.client.get('/assistants/phd_supervisor/assistants/')
     self.assertEqual(response.status_code, HTTP_OK)
     self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor))
     self.assertFalse(response.context['can_delegate'])
     entities_id = self.assistant_mandate.mandateentity_set.all().order_by('id').values_list('entity', flat=True)
     self.assistant_mandate.entities = find_versions_from_entites(entities_id, None)
     self.assistant_mandate.save()
     self.assertQuerysetEqual(response.context['object_list'],
                              find_for_supervisor_for_academic_year(self.phd_supervisor, self.current_academic_year),
                              transform = lambda x: x
                              )
Пример #41
0
def assistant_home(request):
    if (settings.access_to_procedure_is_open() or settings.assistants_can_see_file()) \
            and academic_assistant.find_by_person(person=request.user.person):
        return HttpResponseRedirect(reverse('assistant_mandates'))
    else:
        try:
            manager.find_by_person(person=request.user.person)
            return HttpResponseRedirect(reverse('manager_home'))
        except manager.Manager.DoesNotExist:
            if reviewer.find_by_person(person=request.user.person):
                return HttpResponseRedirect(reverse('reviewer_mandates_list_todo'))
            else:
                return HttpResponseRedirect(reverse('access_denied'))
 def test_context_data(self):
     self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH,
                                     entity=self.entity_version.entity,
                                     person=self.phd_supervisor)
     self.client.force_login(self.phd_supervisor.user)
     response = self.client.get('/assistants/reviewer/')
     self.assertEqual(response.context['reviewer'], find_by_person(self.phd_supervisor))
     self.assertTrue(response.context['can_delegate'])
     mandates_id = find_by_entity(self.reviewer.entity).values_list(
         'assistant_mandate_id', flat=True)
     self.assertQuerysetEqual(response.context['object_list'],
                              find_by_academic_year(self.current_academic_year).filter(id__in=mandates_id),
                              transform=lambda x: x
                              )
 def get_context_data(self, **kwargs):
     context = super(MandatesListView, self).get_context_data(**kwargs)
     current_reviewer = reviewer.find_by_person(self.request.user.person)
     can_delegate = reviewer.can_delegate(current_reviewer)
     context['can_delegate'] = can_delegate
     context['reviewer'] = current_reviewer
     entity = entity_version.get_last_version(current_reviewer.entity)
     context['entity'] = entity
     context['is_supervisor'] = self.is_supervisor
     context['review_status'] = review_status
     context['filter'] = self.kwargs.get("filter", None)
     context['year'] = academic_year.find_academic_year_by_id(
         self.request.session.get('selected_academic_year')).year
     context = add_entities_version_to_mandates_list(context)
     return add_actions_to_mandates_list(context, current_reviewer)
Пример #44
0
 def test_context_data(self):
     self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH,
                                     entity=self.entity_version.entity,
                                     person=self.phd_supervisor)
     self.client.force_login(self.phd_supervisor.user)
     response = self.client.get('/assistants/reviewer/')
     self.assertEqual(response.context['reviewer'],
                      find_by_person(self.phd_supervisor))
     self.assertTrue(response.context['can_delegate'])
     mandates_id = find_by_entity(self.reviewer.entity).values_list(
         'assistant_mandate_id', flat=True)
     self.assertQuerysetEqual(
         response.context['object_list'],
         find_by_academic_year(
             self.current_academic_year).filter(id__in=mandates_id),
         transform=lambda x: x)
 def get_context_data(self, **kwargs):
     context = super(MandatesListView, self).get_context_data(**kwargs)
     current_reviewer = reviewer.find_by_person(self.request.user.person)
     can_delegate = reviewer.can_delegate(current_reviewer)
     context['can_delegate'] = can_delegate
     context['reviewer'] = current_reviewer
     entity = entity_version.get_last_version(current_reviewer.entity)
     context['entity'] = entity
     context['is_supervisor'] = self.is_supervisor
     context['review_status'] = review_status
     context['review_advice_choices'] = review_advice_choices
     context['filter'] = self.kwargs.get("filter", None)
     context['year'] = academic_year.find_academic_year_by_id(
         self.request.session.get('selected_academic_year')).year
     context = add_entities_version_to_mandates_list(context)
     return add_actions_to_mandates_list(context, current_reviewer)
Пример #46
0
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 test_context_data(self):
     self.client.force_login(self.reviewer.person.user)
     response = self.client.get('/assistants/reviewer/delegation/')
     entities_version = entity_version.get_last_version(self.reviewer.entity).children
     entities = [this_entity_version.entity for this_entity_version in entities_version]
     entities.insert(0, entity_version.get_last_version(self.reviewer.entity).entity)
     queryset = [{
         'id': entity.id,
         'title': entity_version.get_last_version(entity, None).title,
         'acronym': entity.most_recent_acronym,
         'has_already_delegate': get_delegate_for_entity(self.reviewer, entity)
     } for entity in entities]
     self.assertQuerysetEqual(response.context['object_list'],
                              queryset,
                              transform=lambda x: x
                              )
     self.assertEqual(response.context['entity'], entity_version.get_last_version(self.reviewer.entity))
     self.assertEqual(response.context['year'], self.current_academic_year.year)
     self.assertEqual(response.status_code, HTTP_OK)
     self.assertEqual(response.context['current_reviewer'], find_by_person(self.reviewer.person))
     self.assertEqual(response.context['is_supervisor'], is_supervisor(self.reviewer.person))
Пример #48
0
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 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_add(request):
    year = academic_year.current_academic_year().year
    if request.POST:
        form = ReviewerForm(data=request.POST)
        this_person = request.POST.get('person_id')
        if form.is_valid() and this_person:
            this_person = person.find_by_id(this_person)
            new_reviewer = form.save(commit=False)
            if reviewer.find_by_person(this_person):
                msg = _("person_already_reviewer_msg")
                form.add_error(None, msg)
            if reviewer.find_by_entity_and_role(new_reviewer.entity, new_reviewer.role):
                msg = _("reviewer_with_same_role_already_exists_msg")
                form.add_error(None, msg)
            if not form.has_error(field=NON_FIELD_ERRORS):
                new_reviewer.person = this_person
                new_reviewer.save()
                return redirect('reviewers_list')
        else:
            msg = _("bad_person_msg")
            form.add_error(None, msg)
    else:
        form = ReviewerForm(initial={'year': year})
    return render(request, "manager_add_reviewer.html", {'form': form, 'year': year})
Пример #51
0
 def test_find_by_person(self):
     self.assertEqual(self.reviewer1, reviewer.find_by_person(self.reviewer1.person))
 def get_queryset(self):
     self.reviewer = reviewer.find_by_person(self.request.user.person)
     return assistant_mandate.find_for_supervisor_for_academic_year(self.request.user.person,
                                                                    academic_year.current_academic_year())
Пример #53
0
def user_is_reviewer_and_procedure_is_open(user):
    return user.is_authenticated and settings.access_to_procedure_is_open() and reviewer.find_by_person(user.person)