Example #1
0
    def post(self):
        show = Show()
        # show.key=ndb.Key('Show', int(request.form['id']))
        show.event_id = ndb.Key('Event', int(request.form['event_id']))
        show.client_id = ndb.Key('Client', int(request.form['client_id']))
        show.screen_id = ndb.Key('Screen_Layout', int(request.form['screen_id']))
        show.name = request.form['name']
        show.datetime = datetime.datetime.now()
        screen = ndb.Key('Screen_Layout', int(request.form['screen_id']))
        seats = screen.get().seats
        print type(seats)
        updated_seats = {}
        for each in seats:
            updated_seats[str(each['row'])+'-'+str(each['column'])]= {'status':4}
        show.seats = updated_seats
        res = show.put()

        # The below paragraph should be deleted later
        offset_id = 21
        prices = []
        print show.screen_id
        categories = Category.query(Category.screen_id == show.screen_id).fetch()
        for category in categories:
            price1 = Price(id=show.key.id() + offset_id, show_id=show.key, category_id=category.key, amount=500)
            offset_id += 1
            prices.append(price1)
        print "###"
        print prices
        for price in prices:
            price.put()

        # The above paragraph should be deleted later

        return jsonify({'id': res.id(), 'message': "Success"})
Example #2
0
    def post(self):
        # Got client ID from environ
        user_id = request.environ['USER_ID']
        client_id = user_id.get().detail_id

        show = Show()
        show.event_id = ndb.Key('Event', int(request.json['event_id']))
        show.client_id = client_id  # Fetched from the environ values.
        show.screen_id = ndb.Key('Screen_Layout',
                                 int(request.json['screen_id']))
        show.datetime = datetime.strptime(request.json['datetime'],
                                          "%d-%m-%Y %H:%M")
        screen = ndb.Key('Screen_Layout', int(request.json['screen_id']))
        seats = screen.get().seats
        updated_seats = {}
        for each in seats:
            updated_seats[str(each['row']) + '-' + str(each['column'])] = {
                'status': 4
            }
        show.seats = updated_seats

        categories_price = request.json['category-price']
        res = show.put()

        # Creating a price for each request
        try:
            for each in categories_price:
                price = Price(show_id=res,
                              category_id=ndb.Key('Category',
                                                  int(each['category'])),
                              amount=int(each['price']))
                print '########'
                print type(price.category_id.id())
                price.put()

        except:
            return jsonify({"code": 500, "message": "server error"})

        return jsonify({"code": 200, "id": res.id(), "message": "Success"})