diff --git a/decorators/cohort_view_decorators.py b/decorators/cohort_view_decorators.py index 0eae1ba9..11a913c8 100644 --- a/decorators/cohort_view_decorators.py +++ b/decorators/cohort_view_decorators.py @@ -33,8 +33,8 @@ import base.models as mdl_base from dashboard.views import main as dash_main_view -from internship.models import internship_student_information from internship.models.cohort import Cohort +from internship.models.internship_student_information import InternshipStudentInformation def redirect_if_not_in_cohort(function): @@ -45,8 +45,9 @@ def wrapper(request, cohort_id, *args, **kwargs): except MultipleObjectsReturned: return dash_main_view.show_multiple_registration_id_error(request) - if student and internship_student_information.find_by_person_in_cohort(cohort_id, - student.person_id).count() > 0: + if student and InternshipStudentInformation.objects.filter( + cohort_id=cohort_id, person_id=student.person_id + ).count() > 0: return function(request, cohort_id, *args, **kwargs) else: return redirect(reverse("internship")) diff --git a/forms/form_select_speciality.py b/forms/form_select_speciality.py deleted file mode 100644 index abab70f9..00000000 --- a/forms/form_select_speciality.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# -# OSIS stands for Open Student Information System. It's an application -# designed to manage the core business of higher education institutions, -# such as universities, faculties, institutes and professional schools. -# The core business involves the administration of students, teachers, -# courses, programs and so on. -# -# Copyright (C) 2015-2016 Université catholique de Louvain (http://www.uclouvain.be) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# A copy of this license - GNU General Public License - is available -# at the root of the source code of this program. If not, -# see http://www.gnu.org/licenses/. -# -############################################################################## -from django import forms - -from internship.models.internship_speciality import InternshipSpeciality - - -class SpecialityForm(forms.Form): - speciality = forms.ModelChoiceField(queryset=InternshipSpeciality.objects.all(), empty_label=None) diff --git a/models/internship.py b/models/internship.py index f2ea80a5..53d46b23 100644 --- a/models/internship.py +++ b/models/internship.py @@ -43,7 +43,3 @@ class Internship(SerializableModel): def __str__(self): return u"%s" % self.name - - -def find_by_cohort(cohort): - return Internship.objects.filter(cohort=cohort) diff --git a/models/internship_offer.py b/models/internship_offer.py index 3358102e..4f54b994 100644 --- a/models/internship_offer.py +++ b/models/internship_offer.py @@ -65,28 +65,8 @@ def find_selectable_by_speciality_and_cohort(speciality, cohort): selectable=True).order_by("organization__reference") -def find_selectable_by_cohort(cohort): - return InternshipOffer.objects.filter(cohort=cohort, selectable=True).order_by("organization__reference") - - -def find_by_speciality(speciality): - return InternshipOffer.objects.filter(speciality=speciality) - - -def find_by_cohort(cohort): - return InternshipOffer.objects.filter(cohort=cohort) - - def find_by_pk(a_pk): try: return InternshipOffer.objects.get(pk=a_pk) except ObjectDoesNotExist: return None - - -def cohort_open_for_selection(cohort): - return InternshipOffer.objects.filter(selectable=True, cohort=cohort).count() > 0 - - -def find_offer(speciality, cohort, organization): - return InternshipOffer.objects.filter(cohort=cohort, organization=organization, speciality=speciality) diff --git a/models/internship_speciality.py b/models/internship_speciality.py index 8cfec3b8..da4112bc 100644 --- a/models/internship_speciality.py +++ b/models/internship_speciality.py @@ -42,11 +42,3 @@ class InternshipSpeciality(SerializableModel): def __str__(self): return u"%s" % self.name - - -def find_by_cohort(cohort): - return InternshipSpeciality.objects.filter(cohort=cohort) - - -def find_selectables(cohort): - return find_by_cohort(cohort).filter(selectable=True) diff --git a/models/internship_student_affectation_stat.py b/models/internship_student_affectation_stat.py index 53ff07a0..3edb1876 100644 --- a/models/internship_student_affectation_stat.py +++ b/models/internship_student_affectation_stat.py @@ -55,7 +55,3 @@ class InternshipStudentAffectationStat(SerializableModel): def __str__(self): return u"%s %s %s %s" % (self.student, self.period, self.organization, self.speciality) - - -def search(student=None): - return InternshipStudentAffectationStat.objects.filter(student=student).order_by('period__date_start') diff --git a/models/internship_student_information.py b/models/internship_student_information.py index 411a29f2..eaf9edae 100644 --- a/models/internship_student_information.py +++ b/models/internship_student_information.py @@ -65,15 +65,3 @@ def find_by_user_in_cohort(user, cohort): return InternshipStudentInformation.objects.get(person__user=user, cohort=cohort) except ObjectDoesNotExist: return None - - -def find_by_person_in_cohort(cohort_id, person_id): - return InternshipStudentInformation.objects.filter(cohort_id=cohort_id, person_id=person_id) - - -def find_by_person(person): - return InternshipStudentInformation.objects.filter(person=person) - - -def exists_by_person(person): - return InternshipStudentInformation.objects.filter(person=person).exists() diff --git a/models/organization.py b/models/organization.py index c9a8372e..26ce38b0 100644 --- a/models/organization.py +++ b/models/organization.py @@ -54,10 +54,6 @@ def save(self, *args, **kwargs): super(Organization, self).save(*args, **kwargs) -def find_by_cohort(cohort): - return Organization.objects.filter(cohort_id=cohort.pk) - - def search(cohort, name="", city=""): organizations = Organization.objects.filter(cohort=cohort) @@ -68,7 +64,3 @@ def search(cohort, name="", city=""): organizations = organizations.filter(city__icontains=city) return organizations - - -def get_all_cities(): - return list(Organization.objects.values_list('city', flat=True).distinct('city').order_by('city')) diff --git a/tests/models/test_internship_offer.py b/tests/models/test_internship_offer.py index 7dd0d71b..5e6adc5e 100644 --- a/tests/models/test_internship_offer.py +++ b/tests/models/test_internship_offer.py @@ -26,6 +26,7 @@ from django.test import TestCase from internship.models import internship_offer +from internship.models.internship_offer import InternshipOffer from internship.tests.factories.cohort import CohortFactory from internship.tests.models import test_organization, test_internship_speciality @@ -58,11 +59,11 @@ def setUp(self): def test_find_by_speciality(self): speciality = self.offer.speciality - actual_offers = internship_offer.find_by_speciality(speciality) + actual_offers = InternshipOffer.objects.filter(speciality=speciality) self.assertIn(self.offer, actual_offers) speciality = test_internship_speciality.create_speciality(name="radiologie") - actual_offers = internship_offer.find_by_speciality(speciality) + actual_offers = InternshipOffer.objects.filter(speciality=speciality) self.assertNotIn(self.offer, actual_offers) def test_get_py_pk(self): @@ -74,12 +75,12 @@ def test_get_py_pk(self): self.assertFalse(internship_offer.find_by_pk(pk)) def test_get_number_selectable(self): - actual = internship_offer.cohort_open_for_selection(self.offer.cohort) + actual = InternshipOffer.objects.filter(selectable=True, cohort=self.offer.cohort).count() > 0 self.assertTrue(actual) self.offer.selectable = False self.offer.save() - actual = internship_offer.cohort_open_for_selection(self.offer.cohort) + actual = InternshipOffer.objects.filter(selectable=True, cohort=self.offer.cohort).count() > 0 self.assertFalse(actual) def test_find_selectable_by_speciality_and_cohort(self): diff --git a/tests/models/test_internship_student_affectation_stat.py b/tests/models/test_internship_student_affectation_stat.py index 970d738f..ad2450b6 100644 --- a/tests/models/test_internship_student_affectation_stat.py +++ b/tests/models/test_internship_student_affectation_stat.py @@ -27,6 +27,7 @@ from base.tests.models import test_student from internship.models import internship_student_affectation_stat as mdl_student_affectation +from internship.models.internship_student_affectation_stat import InternshipStudentAffectationStat from internship.tests.models import test_organization, test_internship_speciality, test_period @@ -50,10 +51,14 @@ def setUp(self): def test_with_no_match(self): create_internship_student_affectation_stat(self.other_student) - student_affectations = list(mdl_student_affectation.search(student=self.student)) + student_affectations = list( + InternshipStudentAffectationStat.objects.filter(student=self.student).order_by('period__date_start') + ) self.assertFalse(student_affectations) def test_with_match(self): expected = create_internship_student_affectation_stat(self.student) - actual = list(mdl_student_affectation.search(student=self.student)) + actual = list( + InternshipStudentAffectationStat.objects.filter(student=self.student).order_by('period__date_start') + ) self.assertEqual([expected], actual) diff --git a/tests/models/test_internship_student_information.py b/tests/models/test_internship_student_information.py index 60962759..c2b540ae 100644 --- a/tests/models/test_internship_student_information.py +++ b/tests/models/test_internship_student_information.py @@ -30,6 +30,7 @@ from base.tests.factories.user import UserFactory from base.tests.models import test_person from internship.models import internship_student_information as mdl_student_information +from internship.models.internship_student_information import InternshipStudentInformation from internship.tests.factories.cohort import CohortFactory @@ -78,11 +79,11 @@ def setUp(self): def test_with_no_information_for_user(self): other_person = test_person.create_person("other", "another") - student_information = mdl_student_information.find_by_person(other_person) + student_information = InternshipStudentInformation.objects.filter(person=other_person) self.assertFalse(student_information) def test_with_information_for_user(self): - self.assertEqual(mdl_student_information.find_by_person(self.student_information.person).first(), + self.assertEqual(InternshipStudentInformation.objects.filter(person=self.student_information.person).first(), self.student_information) @@ -95,9 +96,11 @@ def setUp(self): def test_with_no_information_for_user(self): other_person = test_person.create_person("other", "another") - student_information_exists = mdl_student_information.exists_by_person(other_person) + student_information_exists = InternshipStudentInformation.objects.filter(person=other_person).exists() self.assertFalse(student_information_exists) def test_with_information_for_user(self): - student_information_exists = mdl_student_information.exists_by_person(self.student_information.person) + student_information_exists = InternshipStudentInformation.objects.filter( + person=self.student_information.person + ).exists() self.assertTrue(student_information_exists) diff --git a/tests/models/test_organization.py b/tests/models/test_organization.py index 479d6102..a5b3c485 100644 --- a/tests/models/test_organization.py +++ b/tests/models/test_organization.py @@ -27,6 +27,7 @@ from django.test import TestCase from internship.models import organization as mdl_organization +from internship.models.organization import Organization from internship.tests.factories.cohort import CohortFactory @@ -62,12 +63,12 @@ def test_with_prefix(self): class TestGetAllCities(TestCase): def test_with_no_data(self): - cities = mdl_organization.get_all_cities() + cities = list(Organization.objects.values_list('city', flat=True).distinct('city').order_by('city')) self.assertFalse(cities) def test_with_one_city(self): create_organization() - cities = mdl_organization.get_all_cities() + cities = list(Organization.objects.values_list('city', flat=True).distinct('city').order_by('city')) self.assertListEqual(['test'], cities) def test_with_two_same_cities(self): @@ -75,7 +76,7 @@ def test_with_two_same_cities(self): self.organization_2 = create_organization(reference='02') self.organization_3 = create_organization(reference='03') create_organization(city="city") - cities = mdl_organization.get_all_cities() + cities = list(Organization.objects.values_list('city', flat=True).distinct('city').order_by('city')) self.assertListEqual(["city", "test"], cities) diff --git a/views/hospital.py b/views/hospital.py index dd908bee..d9a20788 100644 --- a/views/hospital.py +++ b/views/hospital.py @@ -30,13 +30,14 @@ from internship import models as mdl_internship from internship.decorators.cohort_view_decorators import redirect_if_not_in_cohort from internship.forms.form_search_hospital import SearchHospitalForm +from internship.models.organization import Organization @login_required @permission_required('internship.can_access_internship', raise_exception=True) @redirect_if_not_in_cohort def view_hospitals_list(request, cohort_id): - cities = mdl_internship.organization.get_all_cities() + cities = list(Organization.objects.values_list('city', flat=True).distinct('city').order_by('city')) name = "" city = "" cohort = mdl_internship.cohort.Cohort.objects.get(pk=cohort_id) diff --git a/views/main.py b/views/main.py index 95e4fca4..1dd8e5dc 100644 --- a/views/main.py +++ b/views/main.py @@ -36,6 +36,7 @@ from dashboard.views import main as dash_main_view from internship.decorators.cohort_view_decorators import redirect_if_not_in_cohort from internship.decorators.global_view_decorators import redirect_if_multiple_registrations +from internship.models.internship_student_information import InternshipStudentInformation @login_required @@ -55,7 +56,7 @@ def view_internship_home(request, cohort_id): def view_cohort_selection(request): student = mdl_base.student.find_by_user(request.user) if student: - cohort_subscriptions = mdl_internship.internship_student_information.find_by_person(student.person) + cohort_subscriptions = InternshipStudentInformation.objects.filter(person=student.person) if cohort_subscriptions: cohorts = [subscription.cohort for subscription in cohort_subscriptions] return layout.render(request, "cohort_selection.html", {'cohorts': cohorts}) diff --git a/views/resume.py b/views/resume.py index c933d3c8..c4ae5709 100644 --- a/views/resume.py +++ b/views/resume.py @@ -35,11 +35,11 @@ from internship.models import cohort as mdl_internship_cohort from internship.models import internship as mdl_internship from internship.models import internship_choice as mdl_internship_choice -from internship.models import internship_offer as mdl_internship_offer -from internship.models import internship_speciality as mdl_internship_speciality from internship.models import internship_student_affectation_stat as mdl_student_affectation from internship.models import internship_student_information as mdl_student_information from internship.models import period as mdl_period +from internship.models.internship_offer import InternshipOffer +from internship.models.internship_speciality import InternshipSpeciality @login_required @@ -58,16 +58,16 @@ def view_student_resume(request, cohort_id): student=student, period_id__in=period_ids ).order_by("period__name") - specialities = mdl_internship_speciality.find_by_cohort(cohort) + specialities = InternshipSpeciality.objects.filter(cohort=cohort) student_choices = mdl_internship_choice.search(student=student, specialities=specialities) cohort = mdl_internship_cohort.Cohort.objects.get(pk=cohort_id) publication_allowed = cohort.publication_start_date <= datetime.date.today() offers = {} for affectation in student_affectations: - offer = mdl_internship_offer.find_offer( + offer = InternshipOffer.objects.filter( cohort=cohort, - speciality=affectation.speciality, - organization=affectation.organization + organization=affectation.organization, + speciality=affectation.speciality ).first() try: offers[affectation.organization].update({affectation.speciality: offer}) @@ -83,18 +83,3 @@ def view_student_resume(request, cohort_id): "cohort": cohort, "offers": offers }) - - -def save_from_form(form, person, cohort): - defaults = { - "location": form.cleaned_data["location"], - "postal_code": form.cleaned_data["postal_code"], - "city": form.cleaned_data["city"], - "country": form.cleaned_data["country"], - "email": form.cleaned_data["email"], - "phone_mobile": form.cleaned_data["phone_mobile"], - "contest": form.cleaned_data["contest"], - } - - mdl_student_information.InternshipStudentInformation.objects.update_or_create(person=person, cohort=cohort, - defaults=defaults) diff --git a/views/selection.py b/views/selection.py index c2380005..905e4436 100644 --- a/views/selection.py +++ b/views/selection.py @@ -41,6 +41,7 @@ from internship.forms.form_offer_preference import OfferPreferenceFormSet, OfferPreferenceForm from internship.models.cohort import Cohort from internship.models.internship import Internship +from internship.models.internship_offer import InternshipOffer from internship.models.internship_speciality import InternshipSpeciality @@ -53,7 +54,7 @@ def view_internship_selection(request, cohort_id, internship_id=None): cohort = mdl_int.cohort.Cohort.objects.get(pk=cohort_id) internships = Internship.objects.filter(cohort=cohort).order_by("speciality__name", "name") - if not mdl_int.internship_offer.cohort_open_for_selection(cohort): + if not InternshipOffer.objects.filter(selectable=True, cohort=cohort).count() > 0: return layout.render(request, "internship_selection_closed.html", {'cohort': cohort}) if request.POST: @@ -63,7 +64,7 @@ def view_internship_selection(request, cohort_id, internship_id=None): current_internship = internships.get(pk=internship_id) - specialities = mdl_int.internship_speciality.find_selectables(cohort).order_by("name") + specialities = InternshipSpeciality.objects.filter(cohort=cohort).filter(selectable=True).order_by("name") student = mdl.student.find_by_user(request.user) saved_choices = []