示例#1
0
def learning_units_external_search(request):
    search_form = ExternalLearningUnitYearForm(request.GET or None,
                                               initial={'academic_year_id': current_academic_year()})
    user_person = get_object_or_404(Person, user=request.user)
    external_learning_units = []
    try:
        if search_form.is_valid():
            external_learning_units = search_form.get_learning_units()
            check_if_display_message(request, external_learning_units)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    if request.POST:
        return redirect(reverse("learning_unit_proposal_search") + "?{}".format(request.GET.urlencode()))

    context = {
        'form': search_form,
        'academic_years': get_last_academic_years(),
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': EXTERNAL_SEARCH,
        'learning_units': external_learning_units,
        'is_faculty_manager': user_person.is_faculty_manager(),
        'form_comparison': SelectComparisonYears(academic_year=get_academic_year_of_reference(external_learning_units)),
    }
    return layout.render(request, "learning_units.html", context)
示例#2
0
def learning_units_external_search(request):
    search_form = ExternalLearningUnitYearForm(request.GET or None,
                                               initial={
                                                   'academic_year_id':
                                                   current_academic_year(),
                                                   'with_entity_subordinated':
                                                   True
                                               })
    user_person = get_object_or_404(Person, user=request.user)
    found_learning_units = LearningUnitYear.objects.none()

    if search_form.is_valid():
        found_learning_units = search_form.get_queryset()
        check_if_display_message(request, found_learning_units)

    context = {
        'form':
        search_form,
        'academic_years':
        get_last_academic_years(),
        'current_academic_year':
        current_academic_year(),
        'search_type':
        EXTERNAL_SEARCH,
        'learning_units_count':
        found_learning_units.count(),
        'is_faculty_manager':
        user_person.is_faculty_manager,
        'form_comparison':
        SelectComparisonYears(academic_year=get_academic_year_of_reference(
            found_learning_units)),
        'page_obj':
        paginate_queryset(found_learning_units, request.GET),
    }
    return render(request, "learning_units.html", context)
示例#3
0
    def test_search_learning_units_by_city(self):
        form_data = {
            "city": NAMEN,
        }

        form = ExternalLearningUnitYearForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertCountEqual(form.get_activity_learning_units(), [self.external_lu_1.learning_unit_year])
示例#4
0
    def test_search_learning_units_on_acronym(self):
        form_data = {
            "acronym": self.external_lu_1.learning_unit_year.acronym,
        }

        form = ExternalLearningUnitYearForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertCountEqual(form.get_activity_learning_units(), [self.external_lu_1.learning_unit_year])
示例#5
0
    def test_search_learning_units_by_campus(self):
        form_data = {
            "campus": self.be_campus_1.id,
        }

        form = ExternalLearningUnitYearForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertCountEqual(form.get_activity_learning_units(),
                              [self.external_lu_BE_1])
示例#6
0
    def test_search_learning_units_by_country(self):
        form_data = {
            "country": self.external_lu_1.learning_unit_year.campus.organization.country.id,
        }

        form = ExternalLearningUnitYearForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertCountEqual(form.get_activity_learning_units(), [
            self.external_lu_1.learning_unit_year, self.external_lu_2.learning_unit_year])
 def test_assert_ignore_external_learning_units_of_type_mobility(self):
     original_count = LearningUnitYear.objects.filter(externallearningunityear__co_graduation=True, externallearningunityear__mobility=False).count()
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=self.academic_year,
         mobility=True,
         co_graduation=False,
         learning_unit_year__acronym="XTEST1234",
     )
     form_data = {
         "academic_year": self.academic_year.id,
     }
     form = ExternalLearningUnitYearForm(form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.get_activity_learning_units().count(), original_count)
示例#8
0
    def test_dropdown_init(self):

        country = CountryFactory()

        organization_1 = OrganizationFactory(name="organization 1")
        organization_2 = OrganizationFactory(name="organization 2")
        organization_3 = OrganizationFactory(name="organization 3")

        OrganizationAddressFactory(organization=organization_1,
                                   country=country,
                                   city=NAMUR)
        OrganizationAddressFactory(organization=organization_2,
                                   country=country,
                                   city=NAMUR)

        OrganizationAddressFactory(organization=organization_3,
                                   country=country,
                                   city=CINEY)

        CampusFactory(organization=organization_1)
        campus_2 = CampusFactory(organization=organization_1)
        campus_3 = CampusFactory(organization=organization_2)

        form = ExternalLearningUnitYearForm({
            'city': NAMUR,
            'country': country,
            "campus": campus_2
        })
        form._init_dropdown_list()

        self.assertEqual(form.fields['campus'].choices[0], (None, '---------'))
        self.assertEqual(form.fields['campus'].choices[1][1], 'organization 1')
        self.assertEqual(form.fields['campus'].choices[2],
                         (campus_3.id, 'organization 2'))

        self.assertEqual(form.fields['city'].choices, [(None, '---------'),
                                                       (CINEY, CINEY),
                                                       (NAMUR, NAMUR)])
示例#9
0
 def test_has_no_criteria(self):
     form = ExternalLearningUnitYearForm({})
     self.assertFalse(form.is_valid())
     self.assertIn(_("minimum_one_criteria"), form.errors['__all__'])