def publish(post_meta): doc_id = Post.url_friendly_text(post_meta["title"]) # Open the database couch = couchdb.Server() db = couch["mrvoxel_blog"] # Load the database settings blog_settings = settings.loadSettings(db) # Check to see if we have a valid category if not post_meta["category"] in blog_settings["blog_categories"]: raise ValueError("No such category: %s" % post_meta["category"]) print "checking for [%s]" % doc_id # Load the post (if it exists in our database) post = Post.load(db, doc_id) # If it exists, warn the user if post: raw = raw_input("This will replace an existing post of the same title...\nContinue? (y/N)") # if the existing post is published but we're trying to preview if (post["published"] == False) and post_meta["published"]: raise ValueError("Cannot yet preview posts that are already published") if raw != "y": print "Canceling publish." return None else: for k, v in post_meta.iteritems(): if k not in ["published", "title"]: print k post[k] = v print post """ post.markdown = mdtext post.html = html post.author = author post.timestamp = timestamp post.published = not preview post.title = title post.tags = tags post.category = category """ post.store(db) else: post = Post.create(**post_meta) print post["_id"] post.store(db) print post["_id"] return post["_id"]