Exemplo n.º 1
0
  def post(self):
    user = users.get_current_user()

    if user:
      nickname = user.nickname()
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      nickname = ""
      url = users.create_login_url(self.request.uri)
      url_linktext = "Log In"
    
    text_isbn = str(cgi.escape(self.request.get('search')))
    #logging.info(text_isbn)
    #try:
    search = mySearch(text_isbn)
    (search_type,arg1,arg2) = search.next()
    #except:
    #  search_type = True
    #  arg1 = 'Not Found'
    #  arg2 = []

    if(search_type):
      books = arg2
      template_values = {
        'url' : url,
        'url_linktext': url_linktext,
        'books': books,
        'nickname' : nickname,
        'bookTitle':search.unique_book().title,
        'text_isbn':text_isbn,
        'book_not_found':False
      }

    
      template = jinja_environment.get_template('html/search.html')
      self.response.out.write(template.render(template_values))
    
    else:
      template_values = {
        'url' : url,
        'url_linktext' : url_linktext,
        'search_text' : arg1,
        'books' : arg2
      }
      template = jinja_environment.get_template('html/browse.html')
      self.response.out.write(template.render(template_values))
Exemplo n.º 2
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}))