예제 #1
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
예제 #2
0
def create_exam_enrollment_historic(user, enrollment):
    exam_enrollment_history = ExamEnrollmentHistory()
    exam_enrollment_history.exam_enrollment = enrollment
    exam_enrollment_history.score_final = enrollment.score_final
    exam_enrollment_history.justification_final = enrollment.justification_final
    exam_enrollment_history.person = person.find_by_user(user)
    exam_enrollment_history.save()
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
            })
예제 #4
0
def find_by_user(a_user):
    try:
        pers = model_person.find_by_user(a_user)
        tutor = Tutor.objects.get(person=pers)
        return tutor
    except ObjectDoesNotExist:
        return None
예제 #5
0
파일: search.py 프로젝트: makinacorpus/osis
def learning_units_proposal_search(request):
    search_form = LearningUnitProposalForm(request.GET or None)
    proposals = []
    try:
        if search_form.is_valid():
            proposals = search_form.get_proposal_learning_units()
            check_if_display_message(request, proposals)

    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    if proposals:
        proposals = _proposal_management(request, proposals)
    a_person = find_by_user(request.user)
    context = {
        'form': search_form,
        'academic_years': get_last_academic_years(),
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': PROPOSAL_SEARCH,
        'proposals': proposals,
        'is_faculty_manager': a_person.is_faculty_manager()
    }

    return layout.render(request, "learning_units.html", context)
예제 #6
0
파일: search.py 프로젝트: makinacorpus/osis
def _learning_units_search(request, search_type):
    service_course_search = search_type == SERVICE_COURSES_SEARCH

    form = LearningUnitYearForm(request.GET or None,
                                service_course_search=service_course_search)
    found_learning_units = []
    try:
        if form.is_valid():
            found_learning_units = form.get_activity_learning_units()

            check_if_display_message(request, found_learning_units)
    except TooManyResultsException:
        messages.add_message(request, messages.ERROR, _('too_many_results'))

    if request.GET.get('xls_status') == "xls":
        return create_xls(request.user, found_learning_units)
    a_person = find_by_user(request.user)
    context = {
        'form': form,
        'academic_years': get_last_academic_years(),
        'container_types':
        learning_container_year_types.LEARNING_CONTAINER_YEAR_TYPES,
        'types': learning_unit_year_subtypes.LEARNING_UNIT_YEAR_SUBTYPES,
        'learning_units': found_learning_units,
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': search_type,
        'is_faculty_manager': a_person.is_faculty_manager()
    }
    return layout.render(request, "learning_units.html", context)
def learning_units_summary_list(request):
    a_user_person = find_by_user(request.user)
    learning_units_found = []

    initial_academic_year = current_academic_year()
    if academic_calendar.is_academic_calendar_has_started(initial_academic_year, SUMMARY_COURSE_SUBMISSION):
        initial_academic_year = initial_academic_year.next()

    search_form = LearningUnitYearForm(request.GET or None, initial={'academic_year_id': initial_academic_year})
    try:
        if search_form.is_valid():
            learning_units_found_search = search_form.get_learning_units(
                requirement_entities=a_user_person.find_main_entities_version,
                luy_status=True
            )
            learning_units_found = get_learning_units_and_summary_status(learning_units_found_search)
            check_if_display_message(request, learning_units_found_search)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(learning_units_found)
    learning_units = sorted(learning_units_found, key=lambda learning_yr: learning_yr.acronym)
    errors = [can_learning_unit_year_educational_information_be_udpated(learning_unit_year_id=luy.id)
              for luy in learning_units]
    context = {
        'form': search_form,
        'formset': _get_formset(request, responsible_and_learning_unit_yr_list),
        'learning_units_with_errors': list(zip(learning_units, errors)),
        'experimental_phase': True,
        'search_type': SUMMARY_LIST,
        'is_faculty_manager': a_user_person.is_faculty_manager()
    }

    return layout.render(request, "learning_units.html", context)
예제 #8
0
def create_exam_enrollment_historic(user, enrollment):
    exam_enrollment_history = ExamEnrollmentHistory()
    exam_enrollment_history.exam_enrollment = enrollment
    exam_enrollment_history.score_final = enrollment.score_final
    exam_enrollment_history.justification_final = enrollment.justification_final
    exam_enrollment_history.person = person.find_by_user(user)
    exam_enrollment_history.save()
예제 #9
0
 def test_change_language(self):
     user = UserFactory()
     user.save()
     create_person_with_user(user)
     person.change_language(user, "en")
     a_person = person.find_by_user(user)
     self.assertEqual(a_person.language, "en")
예제 #10
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'))
예제 #11
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'))
예제 #12
0
 def get_context_data(self, **kwargs):
     context = super(AssistantMandatesListView, self).get_context_data(**kwargs)
     context['assistant'] = academic_assistant.find_by_person(person.find_by_user(self.request.user))
     context['current_academic_year'] = current_academic_year()
     context['can_see_file'] = settings.assistants_can_see_file()
     for mandate in context['object_list']:
         entities_id = mandate.mandateentity_set.all().order_by('id').values_list('entity', flat=True)
         mandate.entities = base.models.entity.find_versions_from_entites(entities_id,
                                                                          mandate.academic_year.start_date)
     return context
예제 #13
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'))
예제 #14
0
def learning_units_summary_list(request):
    a_user_person = find_by_user(request.user)
    learning_units_found = []

    initial_academic_year = current_academic_year()
    if academic_calendar.is_academic_calendar_has_started(
            initial_academic_year, SUMMARY_COURSE_SUBMISSION):
        initial_academic_year = initial_academic_year.next()

    search_form = LearningUnitYearForm(
        request.GET or None,
        initial={'academic_year_id': initial_academic_year})
    try:
        if search_form.is_valid():
            learning_units_found_search = search_form.get_learning_units(
                requirement_entities=a_user_person.find_main_entities_version,
                luy_status=True)

            # TODO refactoring : too many queries
            learning_units_found = get_learning_units_and_summary_status(
                learning_units_found_search)
            check_if_display_message(request, learning_units_found_search)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')
    responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(
        learning_units_found)
    learning_units = sorted(learning_units_found,
                            key=lambda learning_yr: learning_yr.acronym)
    errors = [
        can_learning_unit_year_educational_information_be_udpated(
            learning_unit_year_id=luy.id) for luy in learning_units
    ]

    if request.GET.get('xls_status') == "xls_teaching_material":
        try:
            return generate_xls_teaching_material(request.user,
                                                  learning_units_found)
        except ObjectDoesNotExist:
            display_warning_messages(
                request,
                _("the list to generate is empty.").capitalize())

    form_comparison = SelectComparisonYears(
        academic_year=get_academic_year_of_reference(learning_units_found))
    context = {
        'form': search_form,
        'formset': _get_formset(request,
                                responsible_and_learning_unit_yr_list),
        'learning_units_with_errors': list(zip(learning_units, errors)),
        'search_type': SUMMARY_LIST,
        'is_faculty_manager': a_user_person.is_faculty_manager(),
        'form_comparison': form_comparison
    }

    return layout.render(request, "learning_units.html", context)
예제 #15
0
 def get_context_data(self, **kwargs):
     context = super(AssistantMandatesListView,
                     self).get_context_data(**kwargs)
     context['assistant'] = academic_assistant.find_by_person(
         person.find_by_user(self.request.user))
     context['can_see_file'] = settings.assistants_can_see_file()
     for mandate in context['object_list']:
         entities_id = mandate.mandateentity_set.all().order_by(
             'id').values_list('entity', flat=True)
         mandate.entities = base.models.entity.find_versions_from_entites(
             entities_id, mandate.academic_year.start_date)
     return context
예제 #16
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
예제 #17
0
def learning_units_search(request, search_type):
    service_course_search = search_type == SERVICE_COURSES_SEARCH
    borrowed_course_search = search_type == BORROWED_COURSE

    form = LearningUnitYearForm(request.GET or None,
                                service_course_search=service_course_search,
                                borrowed_course_search=borrowed_course_search,
                                initial={'academic_year_id': starting_academic_year()})
    found_learning_units = []
    try:
        if form.is_valid():
            found_learning_units = form.get_activity_learning_units()
            check_if_display_message(request, found_learning_units)
    except TooManyResultsException:
        messages.add_message(request, messages.ERROR, _('too_many_results'))

    if request.POST.get('xls_status') == "xls":
        return create_xls(request.user, found_learning_units, _get_filter(form, search_type))
    if request.POST.get('xls_status') == "xls_attribution":
        return create_xls_attribution(request.user, found_learning_units, _get_filter(form, search_type))
    if request.POST.get('xls_status') == "xls_comparison":
        return create_xls_comparison(
            request.user,
            found_learning_units,
            _get_filter(form, search_type),
            request.POST.get('comparison_year')
        )

    if request.POST.get('xls_status') == "xls_with_parameters":
        return create_xls_with_parameters(request.user,
                                          found_learning_units,
                                          _get_filter(form, search_type),
                                          {WITH_GRP: request.POST.get('with_grp') == 'true',
                                           WITH_ATTRIBUTIONS: request.POST.get('with_attributions') == 'true'})

    a_person = find_by_user(request.user)
    form_comparison = SelectComparisonYears(academic_year=get_academic_year_of_reference(found_learning_units))
    context = {
        'form': form,
        'academic_years': get_last_academic_years(),
        'container_types': learning_container_year_types.LEARNING_CONTAINER_YEAR_TYPES,
        'types': learning_unit_year_subtypes.LEARNING_UNIT_YEAR_SUBTYPES,
        'learning_units': found_learning_units,
        'current_academic_year': starting_academic_year(),
        'experimental_phase': True,
        'search_type': search_type,
        'is_faculty_manager': a_person.is_faculty_manager(),
        'form_comparison': form_comparison
    }

    return layout.render(request, "learning_units.html", context)
예제 #18
0
def _create_update_person(user, person, user_infos):
    if not person:
        person = find_by_user(user)
    if not person:
        person = Person(user=user,
                        global_id=user_infos.get('USER_FGS'),
                        first_name=user_infos.get('USER_FIRST_NAME'),
                        last_name=user_infos.get('USER_LAST_NAME'),
                        email=user_infos.get('USER_EMAIL'))
        person.save()
        person_created.send(sender=None, person=person)
    else:
        updated, person = _update_person_if_necessary(
            person, user, user_infos.get('USER_FGS'))
    return person
예제 #19
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        person = person_mdl.find_by_user(user)
        # ./manage.py createsuperuser (in local) doesn't create automatically a Person associated to User
        if person:
            if person.language:
                user_language = person.language
                translation.activate(user_language)
                request.session[translation.LANGUAGE_SESSION_KEY] = user_language
    elif settings.OVERRIDED_LOGIN_URL:
        return redirect(settings.OVERRIDED_LOGIN_URL)
    return django_login(request)
예제 #20
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        person = person_mdl.find_by_user(user)
        # ./manage.py createsuperuser (in local) doesn't create automatically a Person associated to User
        if person:
            if person.language:
                user_language = person.language
                translation.activate(user_language)
                request.session[translation.LANGUAGE_SESSION_KEY] = user_language
    elif settings.OVERRIDED_LOGIN_URL:
        return redirect(settings.OVERRIDED_CURRENT_URL)
    return django_login(request)
예제 #21
0
def get_or_create_person(user=None, first_name=None, global_id=None):
    person = None
    created = False
    if user:
        person = mdl_person.find_by_user(user)
    if not person and global_id:
        person = mdl_person.find_by_global_id(global_id)
    if not person:
        person = Person(user=user, first_name=first_name, global_id=global_id)
        created = True
    if created:
        person.user = user
        person.first_name = first_name
        person.global_id = global_id
    person.save()
    return person
예제 #22
0
def get_or_create_person(user=None, first_name=None, global_id=None):
    person = None
    created = False
    if user:
        person = mdl_person.find_by_user(user)
    if not person and global_id:
        person = mdl_person.find_by_global_id(global_id)
    if not person:
        person = Person(user=user, first_name=first_name, global_id=global_id)
        created = True
    if created:
        person.user = user
        person.first_name = first_name
        person.global_id = global_id
    person.save()
    return person
def review_edit(request):
    mandate_id = request.POST.get("mandate_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)
    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,
            'mandate_id': mandate.id,
            'previous_mandates': previous_mandates,
            'assistant': assistant,
            'current_reviewer': current_reviewer,
            'entity': entity,
            'menu': menu,
            'menu_type': 'reviewer_menu',
            'form': form
        })
예제 #24
0
def mandate_change_state(request):
    mandate = assistant_mandate.find_mandate_by_id(request.POST.get("mandate_id"))
    if mandate:
        if 'bt_mandate_accept' in request.POST:
            mandate.state = assistant_mandate_state.TRTS
        elif 'bt_mandate_decline' in request.POST:
            mandate.state = assistant_mandate_state.DECLINED
            faculty = mandate_entity.find_by_mandate_and_type(mandate, entity_type.FACULTY)
            if faculty:
                faculty_dean = reviewer.find_by_entity_and_role(
                    faculty.first().entity, reviewer_role.SUPERVISION).first()
                pers = person.find_by_user(request.user)
                assistant = academic_assistant.find_by_person(pers)
                html_template_ref = 'assistant_dean_assistant_decline_html'
                txt_template_ref = 'assistant_dean_assistant_decline_txt'
                send_message(person=faculty_dean.person, html_template_ref=html_template_ref,
                             txt_template_ref=txt_template_ref, assistant=assistant)
        mandate.save()
    return HttpResponseRedirect(reverse('assistant_mandates'))
예제 #25
0
def li_with_permission_for_proposal(data):
    context = data['context']
    permission = data['permission_function']
    url = data['url']
    message = data['message']
    url_id = data['url_id']
    load_modal = data.get('load_modal', False)
    js_script = data.get('js_script', '')
    obj = data['obj']

    proposal = context['proposal']
    person = find_by_user(context.get('user'))

    permission_denied_message, disabled = is_valid_proposal(context)

    if not disabled:
        if not is_year_editable(
                proposal.learning_unit_year, person, raise_exception=False):
            disabled = "disabled"
            permission_denied_message = "{}" \
                .format(_("You can't modify proposition which are related to a learning unit year under"))
        else:
            permission_denied_message, disabled = _get_permission_proposal(
                context, permission, obj)

    if not disabled:
        href = url
    else:
        href = "#"
        load_modal = False

    return {
        "class_li": disabled,
        "load_modal": load_modal,
        "url": href,
        "id_li": url_id,
        "title": permission_denied_message,
        "text": message,
        "js_script": js_script,
    }
def mandate_change_state(request):
    mandate_id = request.POST.get("mandate_id")
    mandate = assistant_mandate.find_mandate_by_id(mandate_id)
    if 'bt_mandate_accept' in request.POST:
        mandate.state = assistant_mandate_state.TRTS
    elif 'bt_mandate_decline' in request.POST:
        mandate.state = assistant_mandate_state.DECLINED
        faculty = mandate_entity.find_by_mandate_and_type(
            mandate, entity_type.FACULTY)
        if faculty:
            faculty_dean = reviewer.find_by_entity_and_role(
                faculty.first().structure, reviewer_role.SUPERVISION).first()
            assistant = academic_assistant.find_by_person(
                person.find_by_user(request.user))
            html_template_ref = 'assistant_dean_assistant_decline_html'
            txt_template_ref = 'assistant_dean_assistant_decline_txt'
            send_message(person=faculty_dean.person,
                         html_template_ref=html_template_ref,
                         txt_template_ref=txt_template_ref,
                         assistant=assistant)
    mandate.save()
    return HttpResponseRedirect(reverse('assistant_mandates'))
예제 #27
0
def learning_units_summary_list(request):
    a_user_person = find_by_user(request.user)
    learning_units_found = []

    search_form = LearningUnitYearForm(request.GET or None)

    try:
        if search_form.is_valid():
            learning_units_found_search = search_form.get_learning_units(
                requirement_entities=a_user_person.find_main_entities_version,
                luy_status=True)
            learning_units_found = get_learning_units_and_summary_status(
                learning_units_found_search)
            check_if_display_message(request, learning_units_found_search)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(
        learning_units_found)

    context = {
        'form':
        search_form,
        'formset':
        _get_formset(request, responsible_and_learning_unit_yr_list),
        'learning_units':
        sorted(learning_units_found,
               key=lambda learning_yr: learning_yr.acronym),
        'experimental_phase':
        True,
        'search_type':
        SUMMARY_LIST,
        'is_faculty_manager':
        a_user_person.is_faculty_manager()
    }

    return layout.render(request, "learning_units.html", context)
예제 #28
0
def build_doc(request: http.HttpRequest,
              mandates: Sequence[assistant_mandate.AssistantMandate],
              type: str = 'default'):
    if mandates:
        year = mandates[0].academic_year
    else:
        year = academic_year.starting_academic_year()
    if type == '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 = []
    roles = []
    if academic_assistant.find_by_person(find_by_user(request.user)):
        roles = [user_role.ASSISTANT]
    elif reviewer.find_by_person(find_by_user(request.user)):
        roles = reviewer.find_by_person(find_by_user(
            request.user)).values_list("role", flat=True)
    else:
        roles = [user_role.ADMINISTRATOR]
    if type == 'default' or type == 'export_to_sap':
        for mandate in mandates:
            add_mandate_content(content, mandate, styles, roles)
    elif type == 'declined_to_sap':
        for mandate in mandates:
            add_declined_mandate_content(content, mandate, styles)
    else:
        content.append(
            create_paragraph(
                "%s (%s)<br />" %
                (_('Assistants who have declined their renewal'), 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
예제 #29
0
def _has_role(user, role):
    pers = person.find_by_user(user)
    this_adviser = search_by_person(pers)
    return this_adviser.type == role if this_adviser else False
예제 #30
0
 def get_queryset(self):
     assistant = academic_assistant.find_by_person(person.find_by_user(self.request.user))
     return assistant_mandate.find_mandate_by_academic_assistant(assistant)
예제 #31
0
파일: tutor.py 프로젝트: neamatKhan/osis
def find_by_user(user):
    try:
        pers = person.find_by_user(user)
        return Tutor.objects.get(person=pers)
    except Tutor.DoesNotExist:
        return None
예제 #32
0
def _get_permission_proposal(context, permission, object):
    # object is sometimes a proposal, sometimes a learning_unit_year it's why it's call 'object'
    return _get_permission_result(object, permission,
                                  find_by_user(context.get('user')))
예제 #33
0
def _get_permission(context, permission):
    return _get_permission_result(context.get('learning_unit_year'),
                                  permission,
                                  find_by_user(context.get('user')))
 def setUpTestData(cls):
     cls.user = UserFactory()
     cls.student_information = create_student_information(cls.user)
     person = mdl_person.find_by_user(cls.user)
     cls.student_information2 = create_student_information(cls.user,
                                                           person=person)
예제 #35
0
def find_by_user(a_user):
    person = model_person.find_by_user(a_user)
    return find_by_person(person)
예제 #36
0
def get_managed_program_as_dict(user):
    managed_programs_as_dict = None
    person = person_mdl.find_by_user(user)
    if person:
        managed_programs_as_dict = api.get_managed_programs_as_dict(person.global_id)
    return managed_programs_as_dict
예제 #37
0
def find_by_user(a_user):
    person = model_person.find_by_user(a_user)
    return find_by_person(person)
예제 #38
0
파일: tutor.py 프로젝트: uclouvain/osis
def find_by_user(user):
    try:
        pers = person.find_by_user(user)
        return Tutor.objects.get(person=pers)
    except Tutor.DoesNotExist:
        return None
예제 #39
0
 def get_queryset(self):
     assistant = academic_assistant.find_by_person(
         person.find_by_user(self.request.user))
     return assistant_mandate.find_mandate_by_academic_assistant(assistant)