예제 #1
0
def student_affectation(request, cohort_id, organization_id):
    cohort = get_object_or_404(models.cohort.Cohort, pk=cohort_id)
    organization = get_object_or_404(models.organization.Organization, pk=organization_id)

    affectations = models.internship_student_affectation_stat.search(organization=organization)\
                                                             .order_by("student__person__last_name",
                                                                       "student__person__first_name")

    for a in affectations:
        a.email = ""
        a.adress = ""
        a.phone_mobile = ""
        internship_student_information = models.internship_student_information.search(
            person=a.student.person,
            cohort=cohort
        )
        _add_student_information(a, internship_student_information)
    periods = models.period.search(cohort=cohort)

    internships = models.internship_offer.search(organization = organization, cohort=cohort)
    all_speciality = get_all_specialities(internships)
    all_speciality = models.internship_speciality.set_speciality_unique(all_speciality)
    set_tabs_name(all_speciality)
    context = {
        'organization': organization,
        'affectations': affectations,
        'specialities': all_speciality,
        'periods': periods,
        'cohort': cohort,
    }
    return render(request, "place_detail_affectation.html", context)
예제 #2
0
def student_choice(request, cohort_id, organization_id):
    cohort = get_object_or_404(models.cohort.Cohort, pk=cohort_id)
    organization = get_object_or_404(models.organization.Organization,
                                     pk=organization_id)
    organization_choice = models.internship_choice.search(
        organization=organization)

    all_offers = models.internship_offer.search(organization=organization,
                                                cohort=cohort)
    all_speciality = models.internship_speciality.find_all(cohort)
    set_tabs_name(all_speciality)
    for al in all_offers:
        number_first_choice = len(
            models.internship_choice.search(organization=al.organization,
                                            speciality=al.speciality,
                                            choice=1))
        number_all_choice = len(
            models.internship_choice.search(organization=al.organization,
                                            speciality=al.speciality))
        al.number_first_choice = number_first_choice
        al.number_all_choice = number_all_choice

    context = {
        'organization': organization,
        'organization_choice': organization_choice,
        'offers': all_offers,
        'specialities': all_speciality,
        'cohort': cohort,
    }
    return render(request, "place_detail.html", context)
예제 #3
0
def student_affectation(request, cohort_id, organization_id):
    cohort = get_object_or_404(Cohort, pk=cohort_id)
    # TODO: get_object_or_404(Organization, pk=organization_id, cohort__id=cohort_id)
    organization = get_object_or_404(Organization, pk=organization_id)

    affectations = mdl_internship.internship_student_affectation_stat.search(
        organization=organization).order_by("student__person__last_name",
                                            "student__person__first_name")

    for a in affectations:
        a.email = ""
        a.adress = ""
        a.phone_mobile = ""
        internship_student_information = mdl_internship.internship_student_information.search(
            person=a.student.person, cohort=cohort)
        if internship_student_information:
            informations = internship_student_information.first()
            a.email = informations.email
            a.adress = informations.location + " " + informations.postal_code + " " + informations.city
            a.phone_mobile = informations.phone_mobile
    periods = mdl_internship.period.search(cohort=cohort)

    internships = mdl_internship.internship_offer.search(
        organization=organization, cohort=cohort)
    all_speciality = get_all_specialities(internships)
    all_speciality = set_speciality_unique(all_speciality)
    set_tabs_name(all_speciality)
    context = {
        'organization': organization,
        'affectations': affectations,
        'specialities': all_speciality,
        'periods': periods,
        'cohort': cohort,
    }
    return render(request, "place_detail_affectation.html", context)
예제 #4
0
def internships(request, cohort_id):
    # import ipdb
    # ipdb.set_trace()
    cohort = get_object_or_404(Cohort, pk=cohort_id)

    # First get the value of the option's value for the sort
    if request.method == 'GET':
        organization_sort_value = request.GET.get('organization_sort')
        if request.GET.get('speciality_sort') != '0':
            speciality_sort_value = request.GET.get('speciality_sort')
        else :
            speciality_sort_value = None
    # Then select Internship Offer depending of the option
    if organization_sort_value and organization_sort_value != "0":
        query = mdl_internship.internship_offer.search(organization__name = organization_sort_value)
    else:
        query = mdl_internship.internship_offer.find_internships()

    query = query.filter(organization__cohort=cohort)

    # Sort the internships by the organization's reference
    query = sort_internships(query)

    # Get The number of differents choices for the internships
    get_number_choices(query)

    internships = Internship.objects.filter(cohort=cohort)

    all_internships = mdl_internship.internship_offer.find_internships().filter(organization__cohort=cohort)
    all_organizations = get_all_organizations(all_internships)
    all_specialities = get_all_specialities(all_internships)
    set_tabs_name(all_specialities)
    all_non_mandatory_speciality = mdl_internship.internship_speciality.find_non_mandatory()
    if speciality_sort_value:
        all_non_mandatory_internships = mdl_internship.internship_offer.find_non_mandatory_internships(speciality__name=speciality_sort_value)
    else:
        all_non_mandatory_internships = mdl_internship.internship_offer.find_non_mandatory_internships(speciality__mandatory=0)

    all_non_mandatory_internships = all_non_mandatory_internships.filter(organization__cohort=cohort)
    all_non_mandatory_speciality = all_non_mandatory_speciality.filter(cohort=cohort)

    get_number_choices(all_non_mandatory_internships)

    context = {
        'section': 'internship',
        'all_internships': query,
        'internships': internships,
        'all_non_mandatory_internships': all_non_mandatory_internships,
        'all_organizations': all_organizations,
        'all_speciality': all_specialities,
        'organization_sort_value': organization_sort_value,
        'speciality_sort_value': speciality_sort_value,
        'non_mandatory_speciality': all_non_mandatory_speciality,
        'cohort': cohort,
    }
    return render(request, "internships.html", context)
예제 #5
0
def internship_affectation_sumup(request, cohort_id):
    cohort = get_object_or_404(models.cohort.Cohort, pk=cohort_id)
    all_speciality = list(models.internship_speciality.find_all(cohort=cohort))
    all_speciality = models.internship_speciality.set_speciality_unique(
        all_speciality)
    set_tabs_name(all_speciality)
    periods = models.period.search(cohort=cohort)
    organizations = models.organization.search(cohort=cohort)
    organizations = models.organization.sort_organizations(organizations)
    offers = models.internship_offer.search(cohort=cohort)
    informations = []
    for organization in organizations:
        for offer in offers:
            if offer.organization.reference == organization.reference:
                informations.append(offer)

    for x in range(0, len(informations)):
        if informations[x] != 0:
            if informations[x].speciality.acronym == "MI":
                informations[x + 1] = 0
                informations[x + 2] = 0

    informations = [x for x in informations if x != 0]

    all_affectations = list(
        models.internship_student_affectation_stat.search())
    affectations = {}
    for speciality in all_speciality:
        temp_affectations = {}
        for period in periods:
            temp_temp_affectations = []
            for aff in all_affectations:
                if aff.speciality.acronym == speciality.acronym and aff.period == period:
                    temp_temp_affectations.append(aff)
            temp_affectations[period.name] = temp_temp_affectations
        affectations[speciality.name] = temp_affectations

    context = {
        'section': 'internship',
        'specialities': all_speciality,
        'periods': periods,
        'organizations': informations,
        'affectations': affectations,
        'cohort': cohort
    }
    return render(request, "internship_affectation_sumup.html", context)
예제 #6
0
def list_internships(request, cohort_id, specialty_id=None):
    cohort = get_object_or_404(Cohort, pk=cohort_id)
    if not specialty_id:
        specialty = cohort.internshipspeciality_set.filter(mandatory=True).first()
    else:
        specialty = InternshipSpeciality.objects.get(id=specialty_id)
    cohort = get_object_or_404(mdl_int.cohort.Cohort, pk=cohort_id)
    organization_sort_value = None
    speciality_sort_value = None
    # First get the value of the option's value for the sort
    if request.method == 'GET':
        organization_sort_value = request.GET.get('organization_sort')
        if request.GET.get('speciality_sort') != '0' and request.GET.get('speciality_sort') != 'None':
            speciality_sort_value = request.GET.get('speciality_sort')

    query = InternshipOffer.objects.filter(organization__cohort=cohort)

    # Then select Internship Offer depending of the option
    if organization_sort_value and organization_sort_value != "0":
        query = query.filter(
            organization__name=organization_sort_value,
            speciality=specialty
        )
    else:
        query = query.filter(
            speciality__mandatory=1,
            cohort=cohort,
            speciality=specialty
        )

    query = query.select_related("organization", "speciality") \
        .order_by('speciality__acronym', 'speciality__name', 'organization__reference')

    # Sort the internships by the organization's reference
    query = _sort_internships(query, specialty.id)

    # Get The number of different choices for the internships
    mandatory_choices = InternshipChoice.objects.filter(
        speciality=specialty,
    ).select_related("speciality")

    _get_number_choices(query, mandatory_choices, mandatory=True)

    internships = mdl_int.internship.Internship.objects.filter(cohort=cohort)

    all_internships = mdl_int.internship_offer.find_mandatory_internships(cohort)
    organizations = _get_all_organizations(all_internships)
    all_specialities = get_all_specialities(all_internships)
    set_tabs_name(all_specialities)
    all_non_mandatory_speciality = cohort.internshipspeciality_set.filter(mandatory=False).order_by('acronym', 'name')
    if speciality_sort_value:
        all_non_mandatory_internships = InternshipOffer.objects.filter(
            speciality__mandatory=0,
            organization__cohort=cohort
        )
        all_non_mandatory_internships = all_non_mandatory_internships.select_related("organization", "speciality") \
            .order_by('speciality__acronym', 'speciality__name', 'organization__reference')
        if (speciality_sort_value != "all"):
            all_non_mandatory_internships = all_non_mandatory_internships.filter(
                speciality__name=speciality_sort_value
            )
        organizations = _get_all_organizations(all_non_mandatory_internships)
        non_mandatory_choices = InternshipChoice.objects.filter(
            speciality_id__in=all_non_mandatory_speciality,
            organization_id__in=organizations,
        ).select_related("speciality")
        _get_number_choices(all_non_mandatory_internships, non_mandatory_choices, mandatory=False)
    else:
        all_non_mandatory_internships = InternshipOffer.objects.none()
    context = {
        'active_tab': specialty.id,
        'all_internships': query,
        'internships': internships,
        'all_non_mandatory_internships': all_non_mandatory_internships,
        'organizations': organizations,
        'all_speciality': all_specialities,
        'organization_sort_value': organization_sort_value,
        'speciality_sort_value': speciality_sort_value,
        'non_mandatory_speciality': all_non_mandatory_speciality,
        'cohort': cohort,
    }
    return render(request, "internships.html", context)
예제 #7
0
def internship_save_modification_student(request, cohort_id):
    cohort = get_object_or_404(mdl_int.cohort.Cohort, pk=cohort_id)
    # Get the student
    registration_id = request.POST.getlist('registration_id')
    student = mdl.student.find_by(registration_id=registration_id[0], full_registration = True)
    # Delete all the student's choices present in the DB
    mdl_int.internship_choice.InternshipChoice.objects.filter(student=student).delete()
    mdl_int.internship_enrollment.InternshipEnrollment.objects.filter(student=student).delete()

    # Build the list of the organizations and specialities get by the POST request
    organization_list = list()
    speciality_list = list()
    periods_list = list()
    fixthis_list = list()

    if request.POST.get('organization'):
        organization_list = request.POST.getlist('organization')
    if request.POST.get('speciality'):
        speciality_list = request.POST.getlist('speciality')
    if request.POST.get('periods_s'):
        periods_list = request.POST.getlist('periods_s')
    if request.POST.get('fixthis'):
        fixthis_list = request.POST.getlist('fixthis')

    all_internships = mdl_int.internship_offer.find_mandatory_internships(cohort)
    all_specialities = get_all_specialities(all_internships)
    set_tabs_name(all_specialities)

    # Create an array with all the tab name of the speciality
    preference_list_tab = []
    for speciality in all_specialities:
        preference_list_tab.append('preference'+speciality.tab)

    # Create a list, for each element of the previous tab,
    # check if this element(speciality) is in the post request
    # If yes, add all the preference of the speciality in the list
    preference_list = list()
    for pref_tab in preference_list_tab:
        if request.POST.get(pref_tab):
            for pref in request.POST.getlist(pref_tab) :
                preference_list.append(pref)

    # If the fix checkbox is checked, the list receive '0', '1' as data
    # Delete the '0' value (the value before the '1', wich is required)
    index = 0
    for value in fixthis_list:
        if value == '1'and fixthis_list[index-1]=='0':
            del fixthis_list[index-1]
        index += 1

    _rebuild_the_lists(preference_list, speciality_list, organization_list)

    # Create the list of all preference and the internships fixed
    final_preference_list = list()
    final_fixthis_list = list()
    index = 0
    for p in preference_list:
        if p != '0':
            final_preference_list.append(p)
            final_fixthis_list.append(fixthis_list[index])
        index += 1

    # Rebuild the lists deleting the null value
    organization_list = [x for x in organization_list if x != 0]
    speciality_list = [x for x in speciality_list if x != 0]

    # Save the new choices
    index = final_preference_list.__len__()
    for x in range(0, index):
        new_choice = mdl_int.internship_choice.InternshipChoice()
        new_choice.student = student[0]
        organization = mdl_int.organization.search(reference=organization_list[x])
        new_choice.organization = organization[0]
        speciality = mdl_int.internship_speciality.search(name=speciality_list[x])
        new_choice.speciality = speciality[0]
        new_choice.choice = final_preference_list[x]
        if final_fixthis_list[x] == '1':
            new_choice.priority = True
        else:
            new_choice.priority = False
        new_choice.save()

    # Save in the enrollment if the internships are fixed and a period is selected
    index = periods_list.__len__()
    for x in range(0, index):
        if periods_list[x] != '0':
            new_enrollment = mdl_int.internship_enrollment.InternshipEnrollment()
            tab_period = periods_list[x].split('\\n')
            period = mdl_int.period.search(name=tab_period[0])
            organization = mdl_int.organization.search(reference=tab_period[1])
            speciality = mdl_int.internship_speciality.search(name=tab_period[2])
            internship = mdl_int.internship_offer.search(speciality__name=speciality[0],
                                                         organization__reference=organization[0].reference)
            new_enrollment.student = student[0]
            new_enrollment.internship_offer = internship[0]
            new_enrollment.place = organization[0]
            new_enrollment.period = period[0]
            new_enrollment.save()

    redirect_url = reverse('internships_modification_student', args=[registration_id[0]])
    return HttpResponseRedirect(redirect_url)
예제 #8
0
def internships_save(request, cohort_id):
    # Check if the internships are selectable, if yes students can save their choices
    cohort = get_object_or_404(mdl_int.cohort.Cohort, pk=cohort_id)
    all_internships = mdl_int.internship_offer.search(cohort=cohort)
    selectable = _get_selectable(all_internships)

    if selectable:
        # Get the student
        student = mdl.student.find_by(person_username=request.user)
        # Delete all the student's choices for mandatory internships present in the DB
        mdl_int.internship_choice.InternshipChoice.objects.filter(student=student, internship_id=0).delete()

        # Build the list of the organizations and specialities get by the POST request
        organization_list = list()
        speciality_list = list()
        internship_choice_tab = []
        if request.POST.get('organization'):
            organization_list = request.POST.getlist('organization')
        if request.POST.get('speciality'):
            speciality_list = request.POST.getlist('speciality')
        if request.POST.getlist('is_choice'):
            internship_choice_tab = request.POST.getlist('is_choice')
            internship_choice_tab_del = list(set(internship_choice_tab))
            for choice_tab in internship_choice_tab_del:
                mdl_int.internship_choice.InternshipChoice.objects.filter(student=student,
                                                                          internship_choice=choice_tab).delete()

        all_specialities = get_all_specialities(all_internships)
        set_tabs_name(all_specialities)
        # Create an array with all the tab name of the speciality
        preference_list_tab = []
        for speciality in all_specialities:
            preference_list_tab.append('preference'+speciality.tab)

        # Create a list, for each element of the previous tab,
        # check if this element(speciality) is in the post request
        # If yes, add all the preference of the speciality in the list
        preference_list = list()
        for pref_tab in preference_list_tab:
            if request.POST.get(pref_tab):
                for pref in request.POST.getlist(pref_tab) :
                    preference_list.append(pref)

        _rebuild_the_lists(preference_list, speciality_list, organization_list, internship_choice_tab)
        # Rebuild the lists deleting the null value
        organization_list = [x for x in organization_list if x != 0]
        speciality_list = [x for x in speciality_list if x != 0]
        preference_list = [x for x in preference_list if x != '0']
        internship_choice_tab = [x for x in internship_choice_tab if x != 0]

        if len(speciality_list) > 0:
            # Check if the student sent correctly send 4 choice.
            # If not, the choices are set to 0
            old_spec=speciality_list[0]
            index = 0
            cumul = 0
            for p in speciality_list:
                new_spec = p
                index += 1
                if old_spec == new_spec:
                    cumul += 1
                    old_spec = new_spec
                else:
                    if cumul < 4:
                        cumul += 1
                        for i in range(index-cumul,index-1):
                            preference_list[i] = 0
                        cumul = 1
                    else :
                        cumul = 1
                    old_spec = new_spec
            if index < 4:
                for i in range(index-cumul,index):
                    preference_list[i] = 0
            else :
                if cumul != 4 :
                    for i in range(index-cumul,index):
                        if i < len(preference_list):
                            preference_list[i] = 0

        _rebuild_the_lists(preference_list, speciality_list, organization_list, internship_choice_tab)
        # Rebuild the lists deleting the null value
        organization_list = [x for x in organization_list if x != 0]
        speciality_list = [x for x in speciality_list if x != 0]
        preference_list = [x for x in preference_list if x != '0']
        internship_choice_tab = [x for x in internship_choice_tab if x != 0]

        index = preference_list.__len__()

        # Save the new student's choices
        for x in range(0, index):
            new_choice = mdl_int.internship_choice.InternshipChoice()
            new_choice.student = student[0]
            organization = mdl_int.organization.search(reference=organization_list[x])
            new_choice.organization = organization[0]
            speciality = mdl_int.internship_speciality.search(name=speciality_list[x])
            new_choice.speciality = speciality[0]
            new_choice.choice = preference_list[x]
            new_choice.internship_choice = internship_choice_tab[x]
            new_choice.priority = False
            new_choice.save()

    return HttpResponseRedirect(reverse('internships_stud', kwargs={
        'cohort_id': cohort.id,
    }))