Permalink
Browse files

Ensured that the Creation and Deletion of Pages and BlogPosts is done…

… deferred.

Also, the original algorithm to use dependency to calculate what to delete was 'silly'.
I think I made it more robust now.

Still, given that now the Page and the BlogPost deletion in the respective Generators
is practically the same, it would be ideal to DRY their code.
  • Loading branch information...
1 parent 1f9b94f commit fae004bf3173ff06b64f3b5bfbd59315af17dffe @detro committed Mar 11, 2011
Showing with 20 additions and 14 deletions.
  1. +8 −6 generators.py
  2. +12 −8 models.py
View
@@ -63,7 +63,7 @@ def generate_resource(cls, post, resource):
class PostContentGenerator(ContentGenerator):
"""ContentGenerator for the actual blog post itself."""
- can_defer = False
+ can_defer = True;
@classmethod
def get_resource_list(cls, content):
@@ -100,6 +100,7 @@ def generate_resource(cls, post, resource, action='post'):
# Handle deletion
if action == 'delete':
static.remove(post.path);
+ post.delete();
return;
template_vals = { 'post': post };
prev, next = cls.get_prev_next(post);
@@ -131,16 +132,17 @@ def get_etag(cls, page):
@classmethod
def generate_resource(cls, page, resource, action='post'):
- page_to_regen = models.Page.get_by_id(resource);
+ curr_page = models.Page.get_by_id(resource);
- if ( page_to_regen ):
+ if ( curr_page ):
# Handle deletion
if action == 'delete':
- static.remove(page_to_regen.path);
+ static.remove(curr_page.path);
+ curr_page.delete();
return;
- template_vals = { 'page': page_to_regen };
+ template_vals = { 'page': curr_page };
rendered = utils.render_template("page.html", template_vals);
- static.set(page_to_regen.path, rendered, config.html_mime_type);
+ static.set(curr_page.path, rendered, config.html_mime_type);
generator_list.append(PageContentGenerator);
View
@@ -115,11 +115,13 @@ def remove(self):
for generator_class, deps in self.get_deps(regenerate=True):
for dep in deps:
if generator_class.can_defer:
- deferred.defer(generator_class.generate_resource, None, dep);
+ if dep == self.key().id():
+ deferred.defer(generator_class.generate_resource, None, dep, action="delete");
+ else:
+ deferred.defer(generator_class.generate_resource, None, dep); # Regenerate dependency
else:
- if generator_class.name() == 'PageContentGenerator':
+ if dep == self.key().id():
generator_class.generate_resource(self, dep, action='delete');
- self.delete();
else:
generator_class.generate_resource(self, dep);
@@ -232,13 +234,15 @@ def remove(self):
for generator_class, deps in self.get_deps(regenerate=True):
for dep in deps:
if generator_class.can_defer:
- deferred.defer(generator_class.generate_resource, None, dep)
+ if dep == self.key().id():
+ deferred.defer(generator_class.generate_resource, None, dep, action="delete");
+ else:
+ deferred.defer(generator_class.generate_resource, None, dep); # Regenerate dependency
else:
- if generator_class.name() == 'PostContentGenerator':
- generator_class.generate_resource(self, dep, action='delete')
- self.delete()
+ if dep == self.key().id():
+ generator_class.generate_resource(self, dep, action='delete');
else:
- generator_class.generate_resource(self, dep)
+ generator_class.generate_resource(self, dep);
# no longer needed; clear cache for this post
if self.path:

0 comments on commit fae004b

Please sign in to comment.