Esempio n. 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

    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()
Esempio n. 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 
     
     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()
Esempio n. 3
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()
Esempio n. 4
0
 def publish(self):
     if not self.namepath:
         num = 0
         content = None
         while not content:
             """ Tries to find a unique URL for this user, and adds the content
             to the datastore when it finds one. """
             path = utils.format_user_path(self, num)
             content = static.add(path, '', config.html_mime_type)
             num += 1
         self.namepath = path
         self.put()
Esempio n. 5
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()
Esempio n. 6
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()
Esempio n. 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()
Esempio n. 8
0
  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()
Esempio n. 9
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()