Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless code (to verify) #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions decorators/cohort_view_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"))
Expand Down
32 changes: 0 additions & 32 deletions forms/form_select_speciality.py

This file was deleted.

4 changes: 0 additions & 4 deletions models/internship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 0 additions & 20 deletions models/internship_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 0 additions & 8 deletions models/internship_speciality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 0 additions & 4 deletions models/internship_student_affectation_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
12 changes: 0 additions & 12 deletions models/internship_student_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 0 additions & 8 deletions models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'))
9 changes: 5 additions & 4 deletions tests/models/test_internship_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions tests/models/test_internship_student_affectation_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
11 changes: 7 additions & 4 deletions tests/models/test_internship_student_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)


Expand All @@ -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)
7 changes: 4 additions & 3 deletions tests/models/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -62,20 +63,20 @@ 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):
self.organization = create_organization()
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)


Expand Down
3 changes: 2 additions & 1 deletion views/hospital.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
27 changes: 6 additions & 21 deletions views/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand All @@ -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)
5 changes: 3 additions & 2 deletions views/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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:
Expand All @@ -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 = []

Expand Down