def master(request, cohort_id, master_id): current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id) allocated_master = internship_master.get_by_id(master_id) allocations = master_allocation.find_by_master(current_cohort, allocated_master) allocated_master_address = allocated_master.person.personaddress_set.first( ) if allocated_master.person else None return render(request, "master.html", locals())
def test_delete_master_only_delete_allocations(self): master_test = MasterFactory( person__source=person_source_type.INTERNSHIP) # master and person exists before delete self.assertTrue( InternshipMaster.objects.filter(pk=master_test.pk).exists()) self.assertTrue( Person.objects.filter(pk=master_test.person.pk).exists()) fake = faker.Faker() organization_test = OrganizationFactory(cohort=self.cohort, reference=fake.random_int( min=10, max=100)) allocation = MasterAllocationFactory(master=master_test, organization=organization_test) url = reverse('master_delete', kwargs={ 'cohort_id': self.cohort.id, 'master_id': master_test.id }) allocations = master_allocation.find_by_master(self.cohort, master_test) self.assertIn(allocation, allocations) response = self.client.get(url) self.assertRedirects( response, reverse('internships_masters', kwargs={'cohort_id': self.cohort.id})) allocations = master_allocation.find_by_master(self.cohort, master_test) self.assertNotIn(allocation, allocations) # master and person have NOT been deleted self.assertTrue( InternshipMaster.objects.filter(pk=master_test.pk).exists()) self.assertTrue( Person.objects.filter(pk=master_test.person.pk).exists())
def test_save_duplicated(self): organization = OrganizationFactory() specialty = SpecialtyFactory() MasterAllocationFactory(organization=organization, specialty=specialty, master=self.master) MasterAllocationFactory(organization=organization, specialty=specialty, master=self.master) allocations = master_allocation.find_by_master(specialty.cohort, self.master) self.assertEquals(1, allocations.count())
def master_form(request, cohort_id, master_id=None): current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id) if master_id: allocated_master = internship_master.get_by_id(master_id) allocations = master_allocation.find_by_master(current_cohort, allocated_master) doctor_selected = 'selected' if allocated_master.civility == Civility.DOCTOR.value else '' professor_selected = 'selected' if allocated_master.civility == Civility.PROFESSOR.value else '' female_selected = 'selected' if allocated_master.gender == Gender.FEMALE.value else '' male_selected = 'selected' if allocated_master.gender == Gender.MALE.value else '' generalist_selected = 'selected' if allocated_master.type_mastery == Mastery.GENERALIST.value else '' specialist_selected = 'selected' if allocated_master.type_mastery == Mastery.SPECIALIST.value else '' countries = country.find_all() specialties = internship_speciality.find_by_cohort(current_cohort) hospitals = organization.find_by_cohort(current_cohort) return shortcuts.render(request, "master_form.html", locals())
def master_delete(request, master_id, cohort_id): current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id) allocated_master = internship_master.get_by_id(master_id) current_allocations = master_allocation.find_by_master( current_cohort, allocated_master) # will only delete current allocations if current_allocations: current_allocations.delete() msg_content = "{} {} : {} {}".format( _('Master allocations deleted in'), current_cohort, allocated_master.person.last_name, allocated_master.person.first_name ) if allocated_master.person else "{}".format(_('Master deleted')) messages.add_message(request, messages.SUCCESS, msg_content, "alert-success") return HttpResponseRedirect( reverse('internships_masters', kwargs={ 'cohort_id': cohort_id, }))
def master_form(request, cohort_id, master_id=None, allocated_master=None): current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id) if master_id: allocated_master = internship_master.get_by_id(master_id) allocations = master_allocation.find_by_master(current_cohort, allocated_master) master_form = MasterForm(request.POST or None, instance=allocated_master) person = allocated_master.person if allocated_master else None if request.POST.get('existing-person-id'): person = Person.objects.get(pk=request.POST.get('existing-person-id')) person_form = InternshipPersonForm(request.POST or None, instance=person) person_address = person.personaddress_set.first() if person else None person_address_form = InternshipPersonAddressForm(request.POST or None, instance=person_address) specialties = internship_speciality.find_by_cohort(current_cohort) hospitals = organization.find_by_cohort(current_cohort) roles = Role.choices() dynamic_fields = json.dumps( list(person_form.fields.keys()) + list(person_address_form.fields.keys())) return render(request, "master_form.html", locals())
def test_clean_allocations(self): allocation = MasterAllocationFactory(master=self.master) cohort = allocation.specialty.cohort master_allocation.clean_allocations(cohort, self.master) allocations = master_allocation.find_by_master(cohort, self.master) self.assertEquals(0, allocations.count())
def test_find_by_master(self): allocation = MasterAllocationFactory(master=self.master) allocations = master_allocation.find_by_master( allocation.specialty.cohort, self.master) self.assertEquals(self.master, allocations[0].master)
def master(request, cohort_id, master_id): current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id) allocated_master = internship_master.get_by_id(master_id) allocations = master_allocation.find_by_master(current_cohort, allocated_master) return shortcuts.render(request, "master.html", locals())