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
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
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
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"]}
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]
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"] }