コード例 #1
0
ファイル: amendpoem.py プロジェクト: andybalaam/poemtube
def amendpoem( db, id, newprops, user ):

    if not is_valid_user( db, user ):
        raise InvalidRequest( "You must be logged in to amend a poem.", 401 )

    if id not in db.poems:
        raise InvalidRequest(
            '"%s" is not the ID of an existing poem.' % id, 404 )

    existing_doc = db.poems[id]

    # You can only edit a poem you created
    if existing_doc["contributor"] != user:
        raise InvalidRequest( "This poem was not contributed by you.", 403 )

    newdoc = copy( existing_doc )
    del newdoc["_id"]
    del newdoc["_rev"]

    for k in newprops:
        if not known_prop( k ):
            raise InvalidRequest(
                '"%s" is not a valid property of a poem.' % k, 400 )

        newdoc[k] = newprops[k]

    db.poems[id] = newdoc
コード例 #2
0
ファイル: addpoem.py プロジェクト: andybalaam/poemtube
def addpoem( db, title, author, text, user ):

    if not is_valid_user( db, user ):
        raise InvalidRequest( "You must be logged in to add a poem.", 401 )

    id = make_id( db, title )
    db.poems[id] = {
        "title"       : title,
        "author"      : author,
        "text"        : text,
        "contributor" : user
    }
    return id
コード例 #3
0
ファイル: addpoem.py プロジェクト: rje4242/poemtube
def addpoem(db, title, author, text, user):

    if not is_valid_user(db, user):
        raise InvalidRequest("You must be logged in to add a poem.", 401)

    id = make_id(db, title)
    db.poems[id] = {
        "title": title,
        "author": author,
        "text": text,
        "contributor": user
    }
    return id
コード例 #4
0
ファイル: replacepoem.py プロジェクト: simonyuau/poemtube
def replacepoem(db, id, title, author, text, user):

    if not is_valid_user(db, user):
        raise InvalidRequest("You must be logged in to replace a poem.", 401)

    if id not in db.poems:
        raise InvalidRequest('"%s" is not the ID of an existing poem.' % id, 404)

    existing_doc = db.poems[id]

    # You can only replace a poem you created
    if existing_doc["contributor"] != user:
        raise InvalidRequest("This poem was not contributed by you.", 403)

    db.poems[id] = {"title": title, "author": author, "text": text, "contributor": existing_doc["contributor"]}
コード例 #5
0
ファイル: deletepoem.py プロジェクト: rje4242/poemtube
def deletepoem( db, id, user ):

    if not is_valid_user( db, user ):
        raise InvalidRequest( "You must be logged in to delete a poem.", 401 )

    if id not in db.poems:
        raise InvalidRequest(
            '"%s" is not the ID of an existing poem.' % id, 404 )

    existing_doc = db.poems[id]

    # You can only delete a poem you created
    if existing_doc["contributor"] != user:
        raise InvalidRequest(
            "This poem was not contributed by you.", 403 )

    del db.poems[id]
コード例 #6
0
ファイル: replacepoem.py プロジェクト: rje4242/poemtube
def replacepoem(db, id, title, author, text, user):

    if not is_valid_user(db, user):
        raise InvalidRequest("You must be logged in to replace a poem.", 401)

    if id not in db.poems:
        raise InvalidRequest('"%s" is not the ID of an existing poem.' % id,
                             404)

    existing_doc = db.poems[id]

    # You can only replace a poem you created
    if existing_doc["contributor"] != user:
        raise InvalidRequest("This poem was not contributed by you.", 403)

    db.poems[id] = {
        "title": title,
        "author": author,
        "text": text,
        "contributor": existing_doc["contributor"]
    }