예제 #1
0
    def get(self):

        beer_id = int(self.request.get('beerId', 0))

        beer = Beer.get_by_id(beer_id)

        if beer != None:
            date = beer.creation_date
            date_string = date.strftime('%m/%d/%Y')
            beer_data = {
                'id': beer.key.id(),
                'name': beer.name,
                'style': beer.style,
                'tap_list_image': beer.tap_list_image,
                'description': beer.description,
                'description_image': beer.description_image,
                'price': beer.price,
                'abv': beer.abv,
                'ibus': beer.ibus,
                'srm': beer.srm,
                'on_tap': beer.on_tap,
                'review': beer.review,
                'review_count': beer.review_count,
                'creation_date': date_string
            }
        else:
            beer_data = {}

        self.response.out.write(json.dumps(beer_data))
예제 #2
0
    def get(self):

        self.response.headers['Content-Type'] = 'application/json'
        order_query = Order.query().order(-Order.timestamp)
        orders = order_query.fetch()
        order_list = []

        for order in orders:
            date = order.timestamp
            date_string = date.strftime('%m/%d/%Y %H:%M:%S')

            order_beer_query = OrderBeer.query(OrderBeer.order_id == order.key.
                                               id()).order(-OrderBeer.quantity)
            order_beers = order_beer_query.fetch()
            order_beer_list = []

            for order_beer in order_beers:

                beer = Beer.get_by_id(order_beer.beer_id)
                beer_list = ""

                if beer != None:
                    beer_name = beer.name
                else:
                    beer_name = "Unknown beer id " + beer_id

                order_beer_list.append({
                    'id': order_beer.beer_id,
                    'beer_name': beer_name,
                    'quantity': order_beer.quantity
                })

                customers = User.query(
                    User.fb_user_id == order.fb_user_id).fetch()
                customer_name = ""
                for customer in customers:
                    customer_name = customer.name

            order_list.append({
                'id': order.key.id(),
                'order_total': order.order_total,
                'customer_name': customer_name,
                'user_id': order.fb_user_id,
                'status': order.status,
                'reward_id': order.reward_id,
                'discount': order.discount,
                'invoice_number': order.invoice_number,
                'timestamp': date_string,
                'details': order_beer_list
            })

        self.response.out.write(json.dumps(order_list))
    def get(self):

        self.response.headers['Content-Type'] = 'application/json'

        user_id = self.request.get('userId', 0)
        limit = int(self.request.get('limit', 3))

        order_query = Order.query(
            Order.fb_user_id == user_id).order(-Order.timestamp)
        orders = order_query.fetch(limit)
        order_list = []

        for order in orders:
            date = order.timestamp
            # Please we need to use only 1 format!
            date_string = date.strftime('%m/%d/%Y %H:%M:%S')

            order_beer_query = OrderBeer.query(OrderBeer.order_id == order.key.
                                               id()).order(-OrderBeer.quantity)
            order_beers = order_beer_query.fetch()
            order_beer_list = []

            for order_beer in order_beers:

                beer = Beer.get_by_id(order_beer.beer_id)

                if beer != None:
                    beer_name = beer.name
                else:
                    beer_name = "Unknown beer id " + beer_id

                order_beer_list.append({
                    'id': order_beer.beer_id,
                    'beer_name': beer_name,
                    'quantity': order_beer.quantity
                })

            order_list.append({
                'id': order.key.id(),
                'order_total': order.order_total,
                'user_id': order.fb_user_id,
                'status': order.status,
                'reward_id': order.reward_id,
                'discount': order.discount,
                'invoice_number': order.invoice_number,
                'timestamp': date_string,
                'details': order_beer_list
            })

        self.response.out.write(json.dumps(order_list))
    def post(self):

        json_string = self.request.body
        dict_object = json.loads(json_string)

        review = int(dict_object['review'])
        beer_id = int(dict_object['beer_id'])

        beer = Beer.get_by_id(beer_id)

        if beer != None:
            beer.review_sum = beer.review_sum + review
            beer.review_count = beer.review_count + 1
            beer.review = beer.review_sum / beer.review_count

            beer.put()

            self.response.set_status(200)

        else:
            self.response.set_status(500)
    def post(self):

		json_string = self.request.body
		dict_object = json.loads(json_string)

		beer_id = int( dict_object['beerId'] ) 
		beer_name = dict_object['beerName']
		beer_style = dict_object['beerStyle']
		beer_price = float( dict_object['beerPrice'] )
		beer_abv = float( dict_object['beerAbv'] )
		beer_ibus = int( dict_object['beerIbus'] )
		beer_srm = int( dict_object['beerSrm'] ) 
		beer_on_tap = bool( dict_object['beerOnTap'] )
		beer_tap_list_image = dict_object['beerTapListImage']
		beer_description = dict_object['beerDescription']
		beer_description_image = dict_object['beerDescriptionImage']

		beer = Beer.get_by_id(beer_id)

		if beer != None:
			beer.name = beer_name
			beer.style = beer_style
			beer.price = beer_price
			beer.abv = beer_abv
			beer.ibus = beer_ibus
			beer.srm = beer_srm
			beer.on_tap = beer_on_tap
			beer.tap_list_image = beer_tap_list_image
			beer.description = beer_description
			beer.description_image = beer_description_image

			beer.put()

			res = { "msg" : "Beer successfully updated", "success": True, "beer_id" : beer_id }
			self.response.out.write(json.dumps(res))
		else:
			res = { "msg" : "Oops! Something went wrong. Please try again.", "success": False, "beer_id" : beer_id }
			self.response.out.write(json.dumps(res))
예제 #6
0
	def text_order(self, order_beers, user_id):
		account_sid = ""
		auth_token = ""
		client = Client(account_sid, auth_token)
		
		customers = User.query(User.fb_user_id == user_id).fetch()
		for customer in customers:
			customer_name = customer.name
		beer_list = ""

		for beer in order_beers:
			beer_name = Beer.get_by_id(int(beer['id'])).name
			beer_quantity = beer['quantity']
			beer = '\n{} x{}'.format(beer_name, beer_quantity)
			beer_list += beer;

		msg_body = 'Beer Order for {}! {}'.format(customer_name, beer_list)		

		bartending_employees = Employee.query(Employee.bartending == True).fetch()

		for employee in bartending_employees:
			msg_to = "+1"+employee.phone
			
			rv = client.messages.create(to=msg_to, from_="+15126400776 ",body=msg_body)
    def post(self):

        json_string = self.request.body
        dict_object = json.loads(json_string)

        beer_id = int(dict_object['beerId'])

        beer = Beer.get_by_id(beer_id)

        if beer != None:
            beer.key.delete()
            res = {
                "msg": "Beer successfully deleted",
                "success": True,
                "beer_id": beer_id
            }
            self.response.out.write(json.dumps(res))
        else:
            res = {
                "msg": "Oops! Something went wrong. Please try again.",
                "success": False,
                "beer_id": beer_id
            }
            self.response.out.write(json.dumps(res))