Ejemplo n.º 1
0
def search_page(request, search, search_type):
    """View to render a different Page result than the first, where search results will be displayed.

    :param request: The http request
    :return: a render of the given HTML page.
    """

    form = PageForm()
    search_value = slugify(search)
    page = request.POST['page_value']

    response = isbn_utils.search_by(search_type, search_value, page=page)
    if search_type == "subject":
        html_template = "search_subject_result.html"
    else:
        html_template = "search_result.html"
    context = {
        'page_form': form,
        'data_list': response.data,
        'page_count': response.page_count,
        'current_page': response.current_page,
        'next_page': int(response.current_page) + 1,
        'search_value': search_value,
        'search_type': search_type
    }

    return render(request, 'taric_books/' + html_template, context)
Ejemplo n.º 2
0
def isbn(request, value):
    """View to render the information about a single book details, including its cover if it is available.
    Books could be found by ISBN or internal book_id according to ISBNdb API.

    :param request: The http request
    :return: a render of the given HTML page.
    """
    # filtering by "book" includes ISBN direct search and title direct search
    response = isbn_utils.search_by("book", value)
    isbn13 = response.data[0]["isbn13"]
    cover_url = gbooks_covers.find_cover_url_by_isbn(isbn13)
    context = {
        'book_details': response.data,
        'cover_url': cover_url,
    }

    return render(request, 'taric_books/isbn.html', context)
Ejemplo n.º 3
0
    def test_search_client_by_subject_page2(self, mock_get):
        """Tests if method gets the page 2 of a list of books that match with the subject."""

        response = isbn_utils.search_by(self.filter_subject, self.subject, page="2")
        self.assertEqual(response.data, json.loads(open(UNIT_TEST_RESOURCES_FOLDER +
                                                   FILE_NAME_SUBJECT_SEARCH_PAGE_RESPONSE).read())["data"])
Ejemplo n.º 4
0
    def test_search_client_by_publisher(self, mock_get):
        """Tests if method gets a list of books that match with the publisher."""

        response = isbn_utils.search_by(self.filter_publisher, self.publisher)
        self.assertEqual(response.data, json.loads(open(UNIT_TEST_RESOURCES_FOLDER +
                                                   FILE_NAME_PUBLISHER_SEARCH_RESPONSE).read())["data"])
Ejemplo n.º 5
0
    def test_search_client_by_isbn(self, mock_get):
        """Tests if method gets a book searching by ISBN."""

        response = isbn_utils.search_by(self.filter_isbn, self.ISBN)
        self.assertEqual(response.data, json.loads(open(UNIT_TEST_RESOURCES_FOLDER +
                                                   FILE_NAME_ISBN_SEARCH_RESPONSE).read())["data"])
Ejemplo n.º 6
0
    def test_search_client_by_title(self, mock_get):
        """Tests if method gets a list of books that match with the title."""

        response = isbn_utils.search_by(self.filter_title, self.title)
        self.assertEqual(response.data, json.loads(open(UNIT_TEST_RESOURCES_FOLDER +
                                                   FILE_NAME_TITLE_SEARCH_RESPONSE).read())["data"])
Ejemplo n.º 7
0
    def test_search_client_by_author_page2(self, mock_get):
        """Tests if method gets the page 2 of books list written by a provided author."""

        response = isbn_utils.search_by(self.filter_author, self.author, page="2")
        self.assertEqual(response.data, json.loads(open(UNIT_TEST_RESOURCES_FOLDER +
                                                   FILE_NAME_AUTHOR_SEARCH_PAGE_RESPONSE).read())["data"])