Beispiel #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
Beispiel #2
0
    def put(self, id):
        '''update a bucketlist of the user'''
        usr = g.user

        # get the bucketlist
        bl = get_bucketlist(usr, id)

        # update name of bucketlist
        if request.form['name']:
            bl.name = request.form['name']

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

        schema = BucketListSchema()
        return schema.dump(bl).data, 200
Beispiel #3
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
Beispiel #4
0
    def post(self):
        '''creates a user'''
        self.username = request.form['username']
        self.password = request.form['password']

        # check that arguments are not empty
        if self.username is None or self.password is None:
            abort(400, message='username/password missing')

        # check if user already exists
        if User.query.filter(User.username == self.username).first() is not None:
            abort(400, message='username unavailable')

        # create a user and commit to database
        u = User(self.username, self.password)
        db_session.add(u)
        db_session.commit()

        schema = UserSchema()
        return schema.dump(u).data, 200
Beispiel #5
0
    def post(self):
        '''create a bucketlist'''
        self.name = request.form['name']

        # check if bucketlist already exists
        bl = BucketList.query.filter(BucketList.name == self.name).first()

        if bl is not None:
            abort(409, message='a bucketlist with this name already exists')
        else:
            usr = g.user
            # create new bucketlist and add it to the user
            bl = BucketList(self.name, usr)
            usr.app_bucket_listing.append(bl)

            # add to session
            db_session.add(usr)
            db_session.commit()

            # return a json representation of the object
            schema = BucketListSchema()
            return schema.dump(bl).data, 200