Beispiel #1
0
def results(request, language=enums.languages.ENGLISH):
    query_params = request.GET
    search_form = SearchForm(query_params)
    course_search = CourseSearch(query_params.get('subject_query', ""), query_params.get('institution_query', ""),
                                 query_params.get('page', 1), query_params.get('count', 20))
    error = course_search.execute()

    if error:
        return render(request, '500.html')

    page = get_page_for_language(language, CourseFinderResults.objects.all())

    if not page:
        return render(request, '404.html')

    comparison_page = get_page_for_language(language, CourseComparisonPage.objects.all())
    bookmark_page = get_page_for_language(language, CourseManagePage.objects.all())

    full_path = '%s?%s' % (request.path, request.environ.get('QUERY_STRING'))
    welsh_url = '/cy' + full_path if language == enums.languages.ENGLISH else full_path
    english_url = full_path.replace('/cy/', '/')

    context = {
        'page': page,
        'search': course_search,
        'pagination_url': 'results',
        'comparison_link': comparison_page.url if comparison_page else '#',
        'manage_link': bookmark_page.url if bookmark_page else '#',
        'english_url': english_url,
        'welsh_url': welsh_url,
        'cookies_accepted': request.COOKIES.get('discoverUniCookies'),
        'filter_form': search_form
    }

    return render(request, 'coursefinder/course_finder_results.html', context)
Beispiel #2
0
 def test_course_search_execute_function_returns_error_on_failure(self, mock_search):
     course_search = CourseSearch("Computing", None, 1, 20)
     error = course_search.execute()
     self.assertIsNone(course_search.total_courses)
     self.assertIsNone(course_search.total_institutions)
     self.assertIsNone(course_search.results)
     self.assertIsNotNone(error)
     self.assertEquals(type(error), ApiError)
Beispiel #3
0
 def test_course_search_execute_function_appends_counts_and_list_of_courses_to_model_on_success(self):
     mock_data = SearchMocks.get_search_response_content()
     course_search = CourseSearch("Computing", None, 1, 20)
     error = course_search.execute()
     self.assertIsNone(error)
     self.assertEquals(course_search.total_courses, mock_data.get('total_number_of_courses'))
     self.assertEquals(course_search.total_institutions, mock_data.get('total_results'))
     self.assertEquals(type(course_search.results), list)
     self.assertEquals(len(course_search.results), len(mock_data.get('items')))
def results(request, language=enums.languages.ENGLISH):
    query_params = request.POST
    search_form = FilterForm({
        "course_query":
        query_params.get('subject_query', ""),
        "institution_query":
        query_params.get('institution_query', ""),
    })

    course_search = CourseSearch(query_params.get('subject_query', ""),
                                 query_params.get('institution_query', ""),
                                 query_params.get('page', 1),
                                 query_params.get('count', 20), language)
    error = course_search.execute()

    if error:
        redirect_page = get_new_landing_page_for_language(language)
        # redirect_page = get_page_for_language(language, SearchLandingPage.objects.all()).url
        return redirect(redirect_page + '?load_error=true&error_type=1')

    page = get_page_for_language(language, CourseFinderResults.objects.all())

    if not page:
        return render(request, '404.html')

    comparison_page = get_page_for_language(language,
                                            CourseComparisonPage.objects.all())
    bookmark_page = get_page_for_language(language,
                                          CourseManagePage.objects.all())

    full_path = '%s?%s' % (request.path, request.environ.get('QUERY_STRING'))
    welsh_url = '/cy' + full_path if language == enums.languages.ENGLISH else full_path
    english_url = full_path.replace('/cy/', '/')

    context = page.get_context(request)
    context.update({
        'page':
        page,
        'search':
        course_search,
        'pagination_url':
        'results',
        'comparison_link':
        comparison_page.url if comparison_page else '#',
        'manage_link':
        bookmark_page.url if bookmark_page else '#',
        'english_url':
        english_url,
        'welsh_url':
        welsh_url,
        'cookies_accepted':
        request.COOKIES.get('discoverUniCookies'),
    })

    return render(request, 'coursefinder/course_finder_results.html', context)