def update_post(self, post, data): """ Update title, content, and tags of the given post. """ post.title = atom.data.Title(type='text', text=data['title']) post.content = atom.data.Content(type='html', text=data['content']) if post.control \ and post.control.draft \ and post.control.draft.text == 'yes' \ and data.get('draft','no') == 'no': post.control.draft.text = 'no' # synchronize tags declared_tags = self.taglist(data) current_tags = [category.term for category in post.category] tags_to_add = [tag for tag in declared_tags if tag not in current_tags] tags_to_remove = [tag for tag in current_tags if tag not in declared_tags] for tag in tags_to_add: post.add_label(tag) for tag in tags_to_remove: for category in post.category: if category.term == tag: post.category.remove(category) return self.client.update(post)
def add_post(self, data): """ Add a post to the blog. ``data`` is a dictionary object that provides the following attributes: - *title* -- post title - *content* -- post content (HTML) - *tags* -- post's tags, specified as a comma-separated list - *draft* -- if this post is a draft """ return self.client.add_post( self.blog_id, data['title'], data['content'], labels=self.taglist(data), draft=data.get('draft','no').lower() == 'yes' )
def taglist(self,data): """ Generates a tag list from a comma-separated string value """ tags = data.get('tags','').strip() return [tag.strip() for tag in tags.split(',')] if len(tags) > 0 else []