Exemple #1
0
  def post(self):
    user = users.get_current_user()
    if not user:
      nickname = user.nickname()
      self.redirect(users.create_login_url(self.request.uri))
      return

    #Form data
    try:
      isbn = ISBN(str(cgi.escape(self.request.get("isbn"))))
      isbn.to_isbn13()
      text_isbn = isbn.format('')
    except ValueError:
      text_isbn = None
    title = cgi.escape(self.request.get("title"))
    try:
      price = float(cgi.escape(self.request.get("price")))
    except BadValueError:
      price = 0.0

    condition = cgi.escape(self.request.get("condition"))
    
    book_id = cgi.escape(self.request.get("book_id"))
    book = models.Book.get(book_id)

    # if the book is valid, update it.
    if(book):
      book.price=price
      book.condition=condition
      book.title=title
      book.put()
      self.redirect("/user")
    else:
      self.redirect('/edit?'+urllib.urlencode({'badisbn':True,'price':price,'title':title}))
  def __init__(self,search_string,querysize = 10):
    """
    Performs a search with the search_string, you should
    also set the querysize if you wish to see more than 10 
    results returned from search.next
    """
    self.offset = 0
    self.limit = querysize
    
    self.search_text = search_string
    isbn = ISBN(search_string)
    
    if isbn.valid():
      self.isbn = isbn
      self.isbn_search = True
      self.isbn.to_isbn13()
      self.unique = UniqueBook(self.isbn.format(''))
      remote_books = models.Book.all().filter('isbn =',self.isbn.format('')).filter('is_local =', False).filter('date >=',datetime.datetime.now()-datetime.timedelta(days=10)).order('-date').get()
      
      if not self.unique.found or self.unique.book.requery or self.unique.book.requery==None:
      
        isbndb_query = isbndb()
        
        logging.info('making query to isbndb')

        isbnbooks = isbndb_query.searchBook(isbn=self.isbn.format(''))
        
        logging.info('found %d books on isbndb'%len(isbnbooks))
        
        if(len(isbnbooks) == 0):
          self.unique.create_book(title='ISBN valid, but book not found',requery=True)
        else:
          self.unique.create_book(title=isbnbooks[0].title,requery=False)
        
        for book in isbnbooks:
          book.add_to_database(self.unique.book)

      self.local_books = self.unique.get_local_books()
      self.remote_books = self.unique.get_remote_books()
      
      logging.info('%d local  AND %d remote'%(self.local_books.count(),self.remote_books.count()))

    else:
      self.isbn_search = False
      
      arrsearch = self.search_text.split(' ')
      books = models.UniqueBook.all().order('-lastAdded')
      self.text_books = []
      for book in books:
        arrtitle = [x.lower() for x in book.title.split(' ')]

        if any([x.lower() in arrtitle for x in arrsearch]):
          self.text_books.append(book)       
Exemple #3
0
  def post(self):
    user = users.get_current_user()
    if not user:
      self.redirect(users.create_login_url(self.request.uri))
      return

    #Form data
    try:
      isbn = ISBN(str(cgi.escape(self.request.get("isbn"))))
      isbn.to_isbn13()
      text_isbn = isbn.format('')
    except ValueError:
      text_isbn = None
    description = cgi.escape(self.request.get("description"))
    try:
      price = float(cgi.escape(self.request.get("price")))
    except BadValueError:
      price = 0.0

    condition = cgi.escape(self.request.get("condition"))
    
    if(text_isbn):
      # this will add the unique book if it doesn't exist
      search = mySearch(text_isbn)
      search.unique_book().update_date()
      
      book_to_insert = models.Book(unique=search.unique_book().book, 
                                 description=description, 
                                 price=price,
                                 condition=condition,
                                 user=user,
                                 is_local=True)
                                 
      book_to_insert.put()
      
      self.redirect("/browse")
    else:
      self.redirect('/sell?'+urllib.urlencode({'badisbn':True,'price':price,'description':description}))