def publish(self):
publisher_doc = self.get_publisher_doc()<EOL>with self.published_context():<EOL><INDENT>published = self.one(Q._uid == self._uid)<EOL>if not published:<EOL><INDENT>published = self.__class__()<EOL><DEDENT>for field, value in publisher_doc.items():<EOL><INDENT>setattr(published, field, value)<EOL><DEDENT>published.upsert()<EOL><DEDENT>now = datetime.now()<EOL>with self.draft_context():<EOL><INDENT>self.get_collection().update(<EOL>{'<STR_LIT>': self._uid},<EOL>{'<STR_LIT>': {'<STR_LIT>': now}}<EOL>)<EOL><DEDENT>with self.published_context():<EOL><INDENT>self.get_collection().update(<EOL>{'<STR_LIT>': self._uid},<EOL>{'<STR_LIT>': {'<STR_LIT>': now}}<EOL>)<EOL><DEDENT>
Publish the current document.

NOTE: You must have saved any changes to the draft version of the
document before publishing, unsaved changes wont be published.