def _get_post(self,postid): postdoc = yield self.settings['db'].posts.find_one(ObjectId(postid)) if not postdoc: self.result(xmlrpclib.Fault(404,"Not found")) else: post = Post(**postdoc) self.result(post.to_metaweblog(self.application))
def _new_post(self,user,password,struct,type): new_post = Post.from_metaweblog(struct,type) if new_post.status == 'publish': new_post.pub_date = datetime.datetime.utcnow() _id = yield self.settings['db'].posts.insert(new_post.to_python()) self.result(str(_id))
def _edit_post(self,postid,struct,post_type): new_post = Post.from_metaweblog(struct,post_type,is_edit=True) db = self.settings['db'] old_post_doc = yield db.posts.find_one(ObjectId(postid)) if not old_post_doc: self.result(xmlrpclib.Fault(404,"Not found")) else: old_post = Post(**old_post_doc) if not old_post.pub_date and new_post.status =='publish': new_post.pub_date = datetime.datetime.utcnow() #do update update_result = yield db.posts.update( {'_id':old_post_doc['_id']}, {'$set':new_post.to_python()} ) if update_result['n'] != 1: self.result(xmlrpclib.Fault(404,'Not found')) else: # If link changes, add redirect from old if old_post.slug != new_post.slug and old_post['status'] == 'publish': redirect_post = Post( redirect=new_post.slug, slug=old_post.slug, status='publish', type='redirect', mod=datetime.datetime.utcnow() ) yield db.posts.insert(redirect_post.to_python()) #Done self.result(True)