Example #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)
Example #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)
Example #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])
Example #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])
Example #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])
Example #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)
Example #8
0
 def test_has_no_criteria(self):
     form = ExternalLearningUnitYearForm({})
     self.assertFalse(form.is_valid())
     self.assertIn(_("minimum_one_criteria"), form.errors['__all__'])