code: def publish(self):
          
          publisher_doc = self.get_publisher_doc()
  
          with self.published_context():
              # Select the published document
              published = self.one(Q._uid == self._uid)
  
              # If there's no published version of the document create one
              if not published:
                  published = self.__class__()
  
              # Update the document
              for field, value in publisher_doc.items():
                  setattr(published, field, value)
  
              # Save published version
              published.upsert()
  
          # Set the revisions number for draft/published version, we use PyMongo
          # directly as it's more convienent to use the shared `_uid`.
          now = datetime.now()
  
          with self.draft_context():
              self.get_collection().update(
                  {'_uid': self._uid},
                  {'$set': {'revision': now}}
                  )
  
          with self.published_context():
              self.get_collection().update(
                  {'_uid': self._uid},
                  {'$set': {'revision': now}}
                  )
docs: 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.