def login_check_search(user):
    ''' Checks that the user has logged in before granting access to the
    feature. If yes the search module is run, if no the 
    appropriate error message is displayed.
    '''
    if user == 0:
        please_login()
    else:
        booksearch.search(user, accept_char_book_id, database, log,
                          'database.txt')
示例#2
0
def btn1clicked():
    """
    This function is called when Btn3 is clicked. 
    The module to search books is called within the button
    and a search is performed. 
    the outputs from book search function 
    is then outputted into the tree structre.
    also additional checks are carried out
    for example checks if the searched books/s 
    is available or currently out on loan 
    """
    tree.delete(
        *tree.get_children())  #clears the data that may already be in tree
    search_word = inp1.get()  #gets user input
    search_word = search_word.lower()
    outpt = booksearch.search(search_word)  #imporeted search function executed
    for l in outpt:  #loops through the returned list
        item = l.split(',')
        id = tree.insert('', 'end', text="BookID=" + item[0])
        tree.columnconfigure(
            1, weight=100)  #output added to the tree view structure
        tree.insert(id, 'end', text="Title:" + item[1])
        tree.insert(id, 'end', text="Author:" + item[2])
        if item[3] == '0':  #condition checks if the serached book is available for checkout
            tree.insert(id, 'end', text="Book available for checkout")
        else:
            tree.insert(id, 'end', text="Book currently out on loan")
示例#3
0
文件: app.py 项目: zaim/bukutip
    def _get(self, isbn):
        context = {
            "isbn": isbn,
            "page_title": 'Book %s not found' % isbn,
            "book": None,
            "shops": bookshop.SHOPS.keys()
        }

        # 1) directly from memcache or datastore
        book = models.Book.get_by_isbn(isbn, create=False)
        results = []

        if not book:
            # 2) from "booktmp" cached during session in SearchHandler
            key = 'booktmp:%s' % isbn
            book_dict = memcache.get(key)
            if book_dict:
                results = [book_dict]
                memcache.delete(key)

        # 3) actual google/amazon search
        if (not book and not results) or (book and (not book.google_id or not book.amazon_id)):
            results = booksearch.search('isbn:%s' % isbn)

        # store or update the book
        if results:
            book = models.store_books(results, update=True)
            book = book[0] if book else None

        context['book'] = book
        context['page_title'] = book.title if book else title

        return ('view.html', context)
示例#4
0
文件: app.py 项目: zaim/bukutip
    def _get(self):
        query = self.request.get('q', '').strip()

        # modify query to do an ISBN: keyword search if given query is one
        if models.Book.ISBN13_REGEX.match(query) or models.Book.ISBN10_REGEX.match(query):
            query = 'isbn:%s' % query

        context = {
            "page_title": u'Search: "%s"' % query,
            "page_id": 'search',
            "query": query,
            "books": []
        }
        hashed  = booksearch.hash_query(query)
        results = booksearch.search(query, hashed=hashed)

        if results:
            # if only has 1 result, immediately save and redirect
            if len(results) == 1:
                # no need to update=True since google book search results
                # rarely change...
                models.store_books(results, update=False)
                self.redirect('/%s' % results[0]['isbn13'])
                return (None, None)

            # convert the resulting dict objects into temporary faux Book
            # entities for use in the template, then defer the actual
            # creation of the entities to BookHandler
            cache = {}
            for res in results:
                res['permalink'] = '/%s' % res['isbn13']
                res['links'] = {}
                for ln in res.get('_links', []):
                    res['links'][ln['name']] = ln['url']
                cache['booktmp:%s' % res['isbn13']] = res

            # temporarily cache the dicts for later saving in BookHandler
            # we give the user 20 minutes to browse/search before
            # clicking a book
            memcache.set_multi(cache, 1200)
            context['books'] = results

        return ('search.html', context)
示例#5
0
def search():
    """
    Searches for book matching entered value and field.
    Populates values onto the table.
    """
    import booksearch as bs

    opt = var.get()
    term = searchBox.get()
    term2 = dateBox.get()

    # Case statement (substitute) for different search areas
    # Each key is an option in the OptionMenu
    searchBy = {
        "Title & Author": bs.search(term),
        "ID": bs.bookID(term),
        "Date": bs.dateRange(term, term2),
    }
    query = searchBy[opt]  # Make & stores a query (2D list)

    # Repopulates table
    if term != "":
        populate(query)