Пример #1
0
def addNewBucketlist(name, user_id, items=[]):
    day = time.time()
    date_created = str(
        datetime.datetime.fromtimestamp(day).strftime("%y-%m-%d"))
    date_modified = date_created
    bucketlist = Bucketlists(name=name)
    bucketlist.name = name
    bucketlist.date_modified = date_modified
    bucketlist.date_created = date_created
    bucketlist.created_by = user_id
    db.session.add(bucketlist)
    db.session.commit()
    if items is None:
        items = []
    if len(items) > 0:
        for each in items:
            item = Items(name=name, bucketlist=bucketlist)
            item.name = each['name']
            item.date_created = date_created
            item.date_modified = date_modified
            item.done = each['done']
            db.session.add(item)
            db.session.commit()
    return jsonify({
        'bucketlist name': bucketlist.name,
        'items': items,
        'date created': bucketlist.date_created,
        'created by': bucketlist.created_by
    }), 201
Пример #2
0
def addBucketlistItem(id, name, done, user_id):
    try:
        bucketlist = db.session.query(Bucketlists).filter_by(
            created_by=user_id, id=id).one()
        day = time.time()
        date_created = str(
            datetime.datetime.fromtimestamp(day).strftime("%y-%m-%d"))
        item = Items(name=name)
        item.name = name
        item.bucketlist_id = id
        item.done = done
        item.date_created = date_created
        item.date_modified = date_created
        db.session.add(item)
        db.session.commit()
        return jsonify({
            'item name': item.name,
            'date created': item.date_created,
            'date modified': item.date_modified,
            'done': item.done
        }), 201
    except:
        return jsonify({"message": "Sorry bucketlist does not exist"}), 404