def test_get_by_id(self):
        master = MasterFactory()
        persisted_master = internship_master.get_by_id(master.id)
        self.assertEquals(master.id, persisted_master.id)

        nonexistent_master = internship_master.get_by_id(0)
        self.assertIsNone(nonexistent_master)
예제 #2
0
def master_save(request, cohort_id):
    current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id)
    allocated_master = internship_master.get_by_id(
        request.POST.get("id")) if request.POST.get("id") else None

    form = MasterForm(request.POST, instance=allocated_master)
    errors = []
    hospital = ""
    if form.is_valid():
        form.save()
        allocated_master = form.instance
        master_allocation.clean_allocations(current_cohort, allocated_master)
        allocations = _build_allocations(request, allocated_master)
        _save_allocations(allocations)
        hospital = _extract_hospital_id(allocations)
    else:
        errors.append(form.errors)

    if errors:
        return HttpResponseRedirect(
            reverse("master_edit",
                    args=[current_cohort.id, allocated_master.id]))

    return HttpResponseRedirect("{}?hospital={}".format(
        reverse("internships_masters", args=[current_cohort.id]), hospital))
예제 #3
0
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())
예제 #4
0
def master_save(request, cohort_id):
    current_cohort = shortcuts.get_object_or_404(cohort.Cohort, pk=cohort_id)
    allocated_master = internship_master.get_by_id(
        request.POST.get("id")) if request.POST.get("id") else None
    form_master = MasterForm(request.POST, instance=allocated_master)
    person = allocated_master.person if allocated_master else None
    if not person and request.POST.get('existing-person-id'):
        person = Person.objects.get(pk=request.POST.get('existing-person-id'))
    form_person = InternshipPersonForm(request.POST, instance=person)
    person_address = person.personaddress_set.first() if person else None
    form_person_address = InternshipPersonAddressForm(request.POST or None,
                                                      instance=person_address)
    errors = []
    hospital = ""
    if form_master.is_valid() and form_person.is_valid(
    ) and form_person_address.is_valid():
        allocated_master = form_master.instance
        if _validate_allocations(request):
            person = form_person.save()
            address = form_person_address.save(commit=False)
            address.person = person
            address.save()
            master = form_master.save()
            master.person = person
            master.save()
            master_allocation.clean_allocations(current_cohort,
                                                allocated_master)
            allocations = _build_allocations(request, allocated_master)
            _save_allocations(allocations)
            hospital = _extract_hospital_id(allocations)
        else:
            errors.append(form_master.errors)
            errors.append(form_person.errors)
            errors.append(form_person_address.errors)
            messages.add_message(
                request, messages.ERROR,
                _('A master must be affected to at least one hospital or one specialty with a role.'
                  ), "alert-danger")
    else:
        errors.append(form_master.errors)
        errors.append(form_person.errors)
        errors.append(form_person_address.errors)
        display_errors(request, errors)

    if errors:
        return master_form(request=request,
                           cohort_id=current_cohort.id,
                           allocated_master=allocated_master)

    return HttpResponseRedirect("{}?hospital={}".format(
        reverse("internships_masters", args=[current_cohort.id]), hospital))
예제 #5
0
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())
예제 #6
0
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,
        }))
예제 #7
0
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())
예제 #8
0
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())
    def test_get_by_id(self):
        persisted_master = internship_master.get_by_id(self.master.id)
        self.assertEqual(self.master.id, persisted_master.id)

        nonexistent_master = internship_master.get_by_id(0)
        self.assertIsNone(nonexistent_master)