Beispiel #1
0
 def publish(self):
   regenerate = False
   if not self.path:
     num = 0
     content = None
     while not content:
       path = utils.format_post_path(self, num)
       content = static.add(path, '', config.html_mime_type)
       num += 1
     self.path = path
     self.put()
     # Force regenerate on new publish. Also helps with generation of
     # chronologically previous and next page.
     regenerate = True 
     
     deferred.defer(self.mention)  # after publishing for the first time, try to ping sites you mention
   if not self.deps:
     self.deps = {}
   for generator_class, deps in self.get_deps(regenerate=regenerate):
     for dep in deps:
       if generator_class.can_defer:
         deferred.defer(generator_class.generate_resource, None, dep)
       else:
         generator_class.generate_resource(self, dep)
   self.put()
Beispiel #2
0
  def publish(self):
    regenerate = False
    if not self.path:
      num = 0
      content = None
      while not content:
        path = utils.format_post_path(self, num)
        content = static.add(path, '', config.html_mime_type)
        num += 1
      self.path = path
      self.put()
      # Force regenerate on new publish. Also helps with generation of
      # chronologically previous and next page.
      regenerate = True

    BlogDate.create_for_post(self)

    # force refresh of cache, before dependencies are run
    utils.clear_memoizer_cache(self)

    for generator_class, deps in self.get_deps(regenerate=regenerate):
      for dep in deps:
        if generator_class.can_defer:
          deferred.defer(generator_class.generate_resource, None, dep)
        else:
          generator_class.generate_resource(self, dep)
    self.put()
Beispiel #3
0
 def publish(self):
   """
   Publish a post
   TODO: we are generating new url every time post is saved!
   """
   regenerate = False
   if not self.path:
     num = 0
     content = None
     while not content:
       path = utils.format_post_path(self, num)
       content = StaticContent.add(path, '', config.html_mime_type)
       num += 1
     self.path = path
     self.put()
     # Force regenerate on new publish. Also helps with generation of
     # chronologically previous and next page.
     regenerate = True
   if not self.deps:
     self.deps = {}
   for generator_class, deps in self.get_deps(regenerate=regenerate):
     for dep in deps:
       if generator_class.can_defer:
         deferred.defer(generator_class.generate_resource, None, dep)
         #generator_class.generate_resource(self, dep)
       else:
         generator_class.generate_resource(self, dep)
   self.put()
Beispiel #4
0
    def publish(self):
        regenerate = False
        if not self.path:
            num = 0
            content = None
            while not content:
                path = utils.format_post_path(self, num)
                content = static.add(path, '', config.html_mime_type)
                num += 1
            self.path = path
            self.put()
            # Force regenerate on new publish. Also helps with generation of
            # chronologically previous and next page.
            regenerate = True

        BlogDate.create_for_post(self)

        for generator_class, deps in self.get_deps(regenerate=regenerate):
            for dep in deps:
                if generator_class.can_defer:
                    deferred.defer(generator_class.generate_resource, None,
                                   dep)
                else:
                    generator_class.generate_resource(self, dep)
        self.put()
Beispiel #5
0
  def update(self, body, is_draft=False):
    if is_draft:
      self.draft = body
    else:
      memcache.flush_all()
      self.updated = datetime.datetime.now()
      self.draft = None
      self.body = body

    if not self.path and not is_draft:
      # Post is being published for the first time
      self.published = self.updated = datetime.datetime.now()
      same_path = True
      count = 0
      while same_path:
        path = utils.format_post_path(self, count)
        same_path = BlogPost.get_by_key_name(path)
        count += 1

      self.path = path
      if self.is_saved() or not is_draft:
        new_post = self.set_key_name(path)
        new_post.put()
        self.is_saved() and self.delete()
        BlogDate.create_for_post(new_post)
        return new_post

    if not self.is_saved():
      new_post = self.set_key_name('/draft:' + utils.slugify(self.title))
      new_post.put()
      return new_post

    self.put()
    return self
Beispiel #6
0
    def publish(self):
        regenerate = False
        if not self.path:
            num = 0
            content = None
            while not content:
                """ Tries to find a unique URL for this post, and adds the content
                to the datastore when it finds one. """
                path = utils.format_post_path(self, num)
                content = static.add(path, '', config.html_mime_type)
                num += 1
            self.path = path
            self.put()
            # Force regenerate on new publish. Also helps with generation of
            # chronologically previous and next page.
            regenerate = True

        # Create BlogDate and TagCounter objects given the data for this post.
        BlogDate.create_for_post(self)
        TagCounter.create_for_post(self)

        """ For every type of generated content (indexes, tags, etc) dependent
        upon this particular post:
        i) Fetch the current list of resources and etag from the current
        ContentGenerator
        ii) Fetch the stored list of resources and etag from self.deps
        iii) If the etag has changed, we need to regenerate all resources - so we
        set to_regenerate to the union of the old and new resources.
        iv) If the etag has not changed, we only need to regenerate added or
        removed resources - so we set to_regenerate to the symmetric difference of
        the old and new resources.
        v) For each resource that needs regenerating, we call generate_resource().
        vi) Finally, we update the BlogPost's list of deps with the new set of
        resources and etag.
        
        Later edit: The only change here is that we check if the ContentGenerator
        permits deferred execution. If it doesn't, we execute generate_resource
        as normal, but if it does, we call deferred.defer for each changed
        dependency.
        
        (Some of this sequence is now encapsulated in other functions, but it's
        doing roughly the same thing still.)
        """
        for generator_class, deps in self.get_deps(regenerate=regenerate):
            for dep in deps:
                if generator_class.can_defer:
                    deferred.defer(generator_class.generate_resource, None, dep)
                else:
                    generator_class.generate_resource(self, dep)
        self.put()
Beispiel #7
0
 def publish(self):
   if not self.path:
     num = 0
     content = None
     while not content:
       path = utils.format_post_path(self, num)
       content = static.add(path, '', config.html_mime_type)
       num += 1
     self.path = path
     self.put()
   if not self.deps:
     self.deps = {}
   for generator_class, deps in self.get_deps():
     for dep in deps:
       if generator_class.can_defer:
         deferred.defer(generator_class.generate_resource, None, dep)
       else:
         generator_class.generate_resource(self, dep)
   self.put()
Beispiel #8
0
 def publish(self):
     if not self.path:
         num = 0
         content = None
         while not content:
             path = utils.format_post_path(self, num)
             content = static.add(path, '', config.html_mime_type)
             num += 1
         self.path = path
         self.put()
     if not self.deps:
         self.deps = {}
     for generator_class, deps in self.get_deps():
         for dep in deps:
             if generator_class.can_defer:
                 deferred.defer(generator_class.generate_resource, None,
                                dep)
             else:
                 generator_class.generate_resource(self, dep)
     self.put()
  def publish(self):
    """Method called to publish or edit (non draft) posts.
    Give post a path if required and checks/regenerate
    dependencies."""

    regenerate = False

    if not self.path:
      # Post does not have a path (first time published).
      # Need to get one.
      num = 0
      content = None
      while not content:
        # Append incremental counter to path until a non used
        # path is found.
        path = utils.format_post_path(self, num)
        # 'static.add' returns 'None' if path is already in use.
        content = static.add(path, '', config.html_mime_type)
        num += 1
      self.path = path
      self.put()

      # Force regenerate on new publish. Also helps with generation of
      # chronologically previous and next page.
      regenerate = True

    # Post has a path, save post date in 'BlogDate' model.
    BlogDate.create_for_post(self)

    # Run through the deps, generate now what must be generated now,
    # defer the rest and save post to datastore (again).
    for generator_class, deps in self.get_deps(regenerate=regenerate):
      for dep in deps:
        if generator_class.can_defer:
          deferred.defer(generator_class.generate_resource, None, dep)
        else:
          generator_class.generate_resource(self, dep)
    self.put()
Beispiel #10
0
 def publish(self):
   if not self.path:
     num = 0
     content = None
     while not content:
       path = utils.format_post_path(self, num)
       content = static.add(path, '', config.html_mime_type)
       num += 1
     self.path = path
   if not self.deps:
     self.deps = {}
   self.put()
   for generator_class in generators.generator_list:
     new_deps = set(generator_class.get_resource_list(self))
     new_etag = generator_class.get_etag(self)
     old_deps, old_etag = self.deps.get(generator_class.name(), (set(), None))
     if new_etag != old_etag:
       to_regenerate = new_deps | old_deps
     else:
       to_regenerate = new_deps ^ old_deps
     for dep in to_regenerate:
       generator_class.generate_resource(self, dep)
     self.deps[generator_class.name()] = (new_deps, new_etag)
   self.put()