def post(self):
        categoryName = self.request.get('categoryName')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name == photoName.upper()).get()

        #check to see if a category with that name already exists
        existingCategory = Category.query(
            Category.categoryName == categoryName).get()

        if existingCategory:
            #if an category with that name already exists, then update the information with the form data
            existingCategory.categoryName = categoryName
            existingCategory.picture = photo.key
            existingCategory.uploaded_by = users.get_current_user()

            existingCategory.put()
            existingCategory.add_to_search_index()
            message = "Successfully updated category record: " + existingCategory.categoryName

        else:
            #add a new category entry if no category with that name already exists
            category = Category(categoryName=categoryName,
                                picture=photo.key,
                                uploaded_by=users.get_current_user())
            category.put()
            category.add_to_search_index()
            message = "Successfully created category record: " + category.categoryName

        self.response.write(message)
示例#2
0
    def post(self):
        screen = Screen_Layout()
        # screen.key=ndb.Key('Screen_Layout', int(request.form['id']))
        screen.name = request.form['name']
        screen.client_id = ndb.Key('Client', int(request.form['client_id']))
        screen.location = request.form['location']
        screen.max_rows = int(request.form['max_rows'])
        screen.max_columns = int(request.form['max_columns'])
        screen.seats = list(json.loads(request.form['seats'].decode('ascii','ignore')))
        # max_rows = int(request.form['max_rows'])
        # max_columns = int(request.form['max_columns'])
        # i = 1
        # j = 1
        # while (i <= max_rows):
        #     while (j <= max_columns):
        #         seats.append({'row': i, 'column': j})
        #         j = j + 1
        #     j = 1
        #     i = i + 1
        # screen.seats = seats
        result = screen.put()

        # the below paragraph should be deleted later
        category1 = Category(id=screen.key.id() + 23, seats=screen.seats, screen_id=screen.key,
                             name="something something")
        category1.put()
        # the above paragraph should be deleted later

        if result:
            client = screen.client_id.get()
            client.screen_list_id.append(result.id())
            client.put()
        return jsonify({'id': result.id(), 'seats': screen.seats, 'message': "Success"})
    def post(self):
        categoryName = self.request.get('categoryName')
        photoName = self.request.get('photoName')

        #get the photo specified by the user
        photo = File.query(File.file_name==photoName.upper()).get()

        #check to see if a category with that name already exists
        existingCategory = Category.query(Category.categoryName==categoryName).get()

        if existingCategory:
            #if an category with that name already exists, then update the information with the form data
            existingCategory.categoryName=categoryName
            existingCategory.picture=photo.key
            existingCategory.uploaded_by=users.get_current_user()

            existingCategory.put()
            existingCategory.add_to_search_index()
            message = "Successfully updated category record: " + existingCategory.categoryName

        else:
            #add a new category entry if no category with that name already exists
            category = Category(categoryName=categoryName, picture=photo.key, uploaded_by=users.get_current_user())
            category.put()
            category.add_to_search_index()
            message = "Successfully created category record: " + category.categoryName

        self.response.write(message)
示例#4
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."
        })
示例#5
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"})
示例#6
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"})