示例#1
0
    def post(self):
        # Got client ID from environ
        user_id = request.environ['USER_ID']
        client_id = user_id.get().detail_id

        print request.json['id']
        screen = Screen_Layout.get_by_id(request.json['id'])
        screen.name = request.json['name']
        prev_client_id = screen.client_id
        print client_id
        if prev_client_id != client_id:  # Later this is to be changed with token.
            return jsonify({"code": 400, "message": "Not authorized."})
        screen.location = request.json['location']

        prev_rows = screen.max_rows
        prev_cols = screen.max_columns

        if prev_rows != int(request.json['max_rows']) or prev_cols != int(
                request.json['max_columns']):
            screen.max_rows = int(request.json['max_rows'])
            screen.max_columns = int(request.json['max_columns'])
            # Deleting the categories of a seat after changing the screen structure.
            options = ndb.QueryOptions(keys_only=True)
            prev_categories = Category.query().filter(
                Category.screen_id == ndb.Key('Screen_Layout',
                                              request.json['id'])).fetch(
                                                  options=options)
            ndb.delete_multi(prev_categories)
            # We should add the new seat list for new seat grid and new categories for the updated Layout..
            seats = []
            categories = request.json['categories']
            print categories
            try:
                for each in categories:
                    category = Category()
                    category.screen_id = ndb.Key('Screen',
                                                 int(request.json['id']))
                    category.name = each['name']
                    category.seats = each['seats']
                    map(lambda seat: seats.append(seat), each['seats'])
                    category.put(
                    )  # Create categories for seat for a particular screen.
                # Adding seats for the screen fetched from categories
                screen.seats = seats
                res = screen.put()
                return jsonify({
                    "code":
                    200,
                    "id":
                    res.id(),
                    "message":
                    "Success changed layout and other informations."
                })
            except:
                return jsonify({"code": 500, "message": "server error"})
        return jsonify({
            "code": 200,
            "message": "Success changed some minor informations."
        })
示例#2
0
 def post(self):
     category = Category()
     # category.key=ndb.Key('Category', int(request.form['id']))
     category.name = request.form['name']
     category.screen_id = ndb.Key('Screen_Layout', int(request.form['screen_id']))
     category.seats = list(json.loads(request.form['seats'].decode('ascii','ignore')))
     res = category.put()
     return jsonify({'id': res.id(),  'message': "Success"})
    def get_category(self):
        """Add the categories to the list"""
        all_category = []
        for category in liste_de_catégories:
            cat = Category()
            cat.name = category
            get_products = ProductDownloader()
            products = get_products.product_by_category(category)
            cat.products = get_products.filter_product(products)
            all_category.append(cat)

        return all_category
示例#4
0
文件: server.py 项目: myangeline/open
 def POST(self):
     category_name = web.input().get('category_name', None)
     if category_name:
         category_name = category_name.strip()
     category_id = web.input().get('category_id', None)
     category = Category()
     if category_id:
         category.id = category_id
     if category_name:
         category.name = category_name
     category.create_time = datetime.datetime.now()
     mu.update_category(category)
     raise web.seeother('/manage/category')
示例#5
0
    def post(self):
        screen = Screen_Layout()
        screen.name = request.json['name']
        user_id = request.environ['USER_ID']
        client_id = user_id.get().detail_id
        screen.client_id = client_id
        screen.location = request.json['location']
        screen.max_rows = int(request.json['max_rows'])
        screen.max_columns = int(request.json['max_columns'])
        res = screen.put()
        print res

        seats = [
        ]  # All the seats from categories needs to be added to the database.
        # Fetch seat categories
        categories = request.json['categories']
        print categories

        for each in categories:
            category = Category()
            category.screen_id = res
            category.name = each['name']
            category_seats = []
            for seat in each['seats']:
                row, column = seat.split('-')
                row = int(row)
                column = int(column)
                category_seats.append({'row': row, 'column': column})
            category.seats = category_seats
            seats.extend(category_seats)
            category.put(
            )  # Create categories for seat for a particular screen.
        screen = res.get(
        )  # Adding seats for the screen fetched from categories
        screen.seats = seats
        res = screen.put()

        return jsonify({"code": 200, "id": res.id(), "message": "Success"})
示例#6
0
ita = Category()
#
milan = Category()
turin = Category()
roma = Category()
#############

###
country_name = None
try:
    country_name = Translation.objects(key="france")[0]
except Exception as e:
    country_name = Translation(key="france", names={"fr-FR": "France"})
    country_name.save()

fr.name = country_name
savoie.name = Translation(key="savoie", names={"fr-FR": "Savoie"})
calvados.name = Translation(key="calvados", names={"fr-FR": "Calvados"})
idf.name = Translation(key="ile-de-france", names={"fr-FR": "Ile-de-France"})

restaut = Translation(key="restaurants", names={"fr-FR": "Restaurants"})
restausav.name = restaut

from models.corporation import Corporation
bestcorp = Corporation.objects(name="Restaurant le 59")[0]
restausav.corps = [bestcorp]

coiffsav.name = Translation(key="coiffeur", names={"fr-FR": "Coiffeurs"})
restaucal.name = restaut
lavcal.name = Translation(key="laverie", names={"fr-FR": "Laveries"})
restauidf.name = restaut