Пример #1
0
  def get(self):
    # ensure all the beers are part of the ndb database. If they aren't, add them
    if len(Beer.query().fetch()) == 0:
      for beer in beers:
        ndbBeer = Beer()
        ndbBeer.beerid = int(beer['id'])
        ndbBeer.brewery = beer['brewery']
        ndbBeer.product = beer['product']
        ndbBeer.style = beer['style']
        ndbBeer.abv = float(beer['abv'])
        ndbBeer.price = beer['price']
        ndbBeer.key = ndb.Key('Beer', beer['id'])
        ndbBeer.put()

    email = get_user_email()
    user_is_admin = is_user_admin()
    if email:
      beerUser = BeerUser.get_user_profile(email)
      page_params = {
        'balance': "${:.2f}".format(beerUser.balance),
        'user_email': email,
        'user_is_admin': user_is_admin,
        'login_url': users.create_login_url('/home'),
        'logout_url': users.create_logout_url('/home')
      }
    else:
      page_params = {
          'user_email': email,
          'user_is_admin': user_is_admin,
          'login_url': users.create_login_url('/home'),
          'logout_url': users.create_logout_url('/home')
      }
    render_template(self, 'home.html', page_params)
Пример #2
0
  def post(self):
    email = get_user_email()
    if not email:
      self.redirect(users.create_login_url('/account'))

    # query ndb to get the current user
    beerUser = BeerUser.get_user_profile(email)
    if not beerUser.cart:
      beerUser.cart = ShoppingCart()
      beerUser.cart.price = "0.00"
      beerUser.cart.contents = {}

    data = json.loads(self.request.body)
    beer_id = int(data["beerID"])
    quantity = int(data["quant"])
    price = float(Beer.query(Beer.beerid == beer_id).fetch(1)[0].price) * quantity

    # check negative quantity
    if quantity < 0:
      return
    
    beerUser.cart.contents[beer_id] = quantity
    beerUser.cart.price = str(float(beerUser.cart.price) + price)

    beerUser.put()
Пример #3
0
  def get(self):
    email = get_user_email()
    user_is_admin = is_user_admin()
    beers_ndb = memcache.get('beerslist')
    if beers_ndb is None:
      beers_ndb = Beer.query().fetch()
      memcache.add('beerslist', beers_ndb)
    else:
      logging.info('beers are in memcache lets goooooo')
    
    if email:  
      beerUser = BeerUser.get_user_profile(email)
      template_params = {
        'balance': "${:.2f}".format(beerUser.balance),
        'user_email': email,
        'user_is_admin': user_is_admin,
        'login_url': users.create_login_url('/beer'),
        'logout_url': users.create_logout_url('/home'),
        'beers' : beers_ndb
      }

    else:
      template_params = {
        'user_email': email,
        'user_is_admin': user_is_admin,
        'login_url': users.create_login_url('/beer'),
        'logout_url': users.create_logout_url('/home'),
        'beers' : beers_ndb
      }
    render_template(self, 'beer.html', templatevalues=template_params)
Пример #4
0
  def post(self):
    email = get_user_email()
    if email:
      try:
        amount = float(self.request.get('amount'))
      except ValueError:
        self.redirect("loadfunds")
        return
      if amount <= 0 or amount > 100:
        self.redirect("loadfunds")
        return

      beerUser = BeerUser.get_user_profile(email)
      beerUser.balance += amount
      beerUser.put()

      mail.send_mail(sender="*****@*****.**",
      to=email,
      subject="Your balance is updated",
      body="""
Dear User:

You have added $""" + str(amount) +
""" to your account.
Your new balance is """ + '${:.2f}'.format(beerUser.balance) +
"""

Pitt Beer Delivery Service
""")

    self.redirect('/account')
Пример #5
0
  def post(self):
    email = get_user_email()
    if not email:
      self.redirect(users.create_login_url('/account'))
    # query ndb to get the current user
    beerUser = BeerUser.get_user_profile(email)
    cart = beerUser.cart.contents
    address = self.request.get("addressTxt")
    beers_in_cart = []

    if not address:
      render_template(self, "ordercomplete.html", {"msg":"Invalid delivery address!"})
      return

    if len(cart) != 0:
      order_string = ""
      totalcost=0
      # Build the order object and save it to the ndb
      new_order = BeerOrder()
      for beer in cart:
        ndb_beer = Beer.query(Beer.beerid == int(beer)).fetch(1)[0]
        totalcost += int(cart[beer]) * float(ndb_beer.price)

        quantity = cart[str(ndb_beer.beerid)]
        if quantity > 0:
          order_string += "{!s}x {!s}\n".format(quantity,ndb_beer.product)

      if totalcost > beerUser.balance:
        render_template(self, "ordercomplete.html", {"msg":"Insufficient funds."})
        return
      
      new_order.items = order_string
      new_order.priceSum = totalcost
      new_order.address = address
      new_order.status = "Verifying"
      new_order.orderedBy = email

      new_order.put()

      # save the address for the user
      beerUser.address = address
      beerUser.balance = beerUser.balance - new_order.priceSum
      #clear their shopping cart
      beerUser.cart = ShoppingCart()
      beerUser.cart.price = "0.00"
      beerUser.cart.contents = {}
      beerUser.put()

      mail.send_mail('*****@*****.**', email, 'Order Verifying', 'You have successfully placed a beer order! Your order will be verified shortly and completed! Thanks!')

      render_template(self, "ordercomplete.html", {"msg":"Your order has been placed."})
    else:
      render_template(self, "ordercomplete.html",{"msg":"Shopping cart is empty."})
Пример #6
0
 def get(self):
   email = get_user_email()
   user_is_admin = is_user_admin()
   beerUser = BeerUser.get_user_profile(email)
   beers_ndb = Beer.query().fetch()
   template_params = {
     #'balance': "${:.2f}".format(beerUser.balance),
     'user_email': email,
     'user_is_admin': user_is_admin,
     'login_url': users.create_login_url('/beer'),
     'logout_url': users.create_logout_url('/home'),
     'beers' : sorted(beers_ndb, key = lambda beer: beer["price"])
   }
   render_template(self, 'beer.html', templatevalues=template_params)
Пример #7
0
 def get(self):
   email = get_user_email()
   user_is_admin = is_user_admin()
   beerUser = BeerUser.get_user_profile(email)
   if email:
     page_params = {
       'balance': "${:.2f}".format(beerUser.balance),
       'user_email': email,
       'user_is_admin': user_is_admin,
       'login_url': users.create_login_url('/home'),
       'logout_url': users.create_logout_url('/home')
     }
     render_template(self, 'vieworders.html', page_params)
   else:
     self.redirect(users.create_login_url('/account'))
Пример #8
0
  def get(self):
    email = get_user_email()
    user_is_admin = is_user_admin()
    if email:
      beerUser = BeerUser.get_user_profile(email)
      balance = beerUser.balance

      page_params = {
        'user_email': email,
        'user_is_admin': user_is_admin,
        'login_url': users.create_login_url('/home'),
        'logout_url': users.create_logout_url('/home'),
        'balance': '${:.2f}'.format(balance),
      }
      render_template(self, 'redeemgift.html', page_params)
    else:
      self.redirect('/home')
Пример #9
0
  def get(self):
    email = get_user_email()
    user_is_admin = is_user_admin()
    if email:
      # query ndb to get funds
      beerUser = BeerUser.get_user_profile(email)
      balance = beerUser.balance

      page_params = {
        'balance': "${:.2f}".format(beerUser.balance),
        'user_email': email,
        'user_is_admin': user_is_admin,
      	'login_url': users.create_login_url('/account'),
       	'logout_url': users.create_logout_url('/home'),
        'balance': '${:.2f}'.format(balance)
      }
      render_template(self, 'account.html', page_params)
    else:
      self.redirect(users.create_login_url('/account'))
Пример #10
0
  def get(self):
    email = get_user_email()
    user_is_admin = is_user_admin()
    if email:
      beerUser = BeerUser.get_user_profile(email)
      balance = beerUser.balance

      process_url = blobstore.create_upload_url('/loadfunds_process')
      
      page_params = {
        'balance': "${:.2f}".format(beerUser.balance),
        'user_email': email,
        'user_is_admin': user_is_admin,
        'login_url': users.create_login_url('/home'),
        'logout_url': users.create_logout_url('/home'),
        'balance': '${:.2f}'.format(balance),
        'loadfunds_process_url': process_url
      }
      render_template(self, 'loadfunds.html', page_params)
    else:
      self.redirect('/home')
Пример #11
0
  def get(self):
    email = get_user_email()
    user_is_admin = is_user_admin()
    totalcost = 0.0
    if email:
      beerUser = BeerUser.get_user_profile(email)
      if not beerUser.cart:
        beerUser.cart = ShoppingCart()
        beerUser.cart.price = "0.00"
        beerUser.cart.contents = {}
        beerUser.put()
      cart = beerUser.cart.contents
      beers_in_cart = []
      if len(cart) != 0:
        for beer in cart:
          ndb_beer = Beer.query(Beer.beerid == int(beer)).fetch(1)[0]
          totalcost += int(cart[beer]) * float(ndb_beer.price)
          beers_in_cart.append({
            "beerid":beer,
            "brewery":ndb_beer.brewery,
            "product":ndb_beer.product,
            "price":ndb_beer.price,
            "quantity":cart[beer]
            })
          #beers_in_cart.append(Beer.query(Beer.beerid == int(beer)).fetch(1)[0])
          #quantities.append(cart[beer])

      template_params={
        'balance': "${:.2f}".format(beerUser.balance),
        'user_email': email,
        'login_url': users.create_login_url('/home'),
        'logout_url': users.create_logout_url('/home'),
        'user_is_admin': user_is_admin,
        "savedAddress":beerUser.address,
        "beers":beers_in_cart,
        "total":'${:.2f}'.format(totalcost)
      }
      render_template(self, 'order.html', template_params)
    else:
      self.redirect(users.create_login_url('/order'))