Exemple #1
0
    def put(self, id, item_id):
        '''update a bucket list item'''
        usr = g.user
        bl = get_bucketlist(usr, id)

        # get the bucketlist item
        bl_item = get_bucketlist_item(bl, item_id)

        # update name
        if 'name' in request.form:
            bl_item.name = request.form['name']

        # set if done
        if 'done' in request.form:
            if request.form['done'].lower() == 'true':
                bl_item.end()
            elif request.form['done'].lower() == 'false':
                bl_item.start()
            else:
                abort(406, message='unsupported value for done')

        # commit to database
        db_session.add(bl_item)
        db_session.commit()

        schema = BucketListItemSchema()
        return schema.dump(bl_item).data, 200
Exemple #2
0
    def post(self, id):
        '''creates a new item in a bucketlist'''
        usr = g.user
        bl = get_bucketlist(usr, id)
        self.name = request.form['name']

        # create new bucketlist item and append to bucketlist
        item = BucketListItem(self.name, bl)
        item.start()
        bl.app_bucketlist_items.append(item)

        # commit to database
        db_session.add(bl)
        db_session.commit()

        schema = BucketListItemSchema()
        return schema.dump(item).data, 200