Skip to content
Browse files

Fixes and tweaks to Gert-Jan's static page support

  • Loading branch information...
1 parent 76d8f6c commit e5017df4e557683f095e209429ce2cbb36de8c0f Nick Johnson committed Feb 3, 2011
View
1 admin.py
@@ -22,7 +22,6 @@
(config.url_prefix + '/admin/newpage', handlers.PageHandler),
(config.url_prefix + '/admin/page/delete/(/.*)', handlers.PageDeleteHandler),
(config.url_prefix + '/admin/page/(/.*)', handlers.PageHandler),
- (config.url_prefix + '/admin/regeneratepages', handlers.PageRegenerateHandler),
])
View
15 generators.py
@@ -330,15 +330,16 @@ def send_hubbub_ping(cls, hub_url):
raise Exception("Hub ping failed", response.status_code, response.content)
generator_list.append(AtomContentGenerator)
-class PageContentGenerator:
+class PageContentGenerator(ContentGenerator):
@classmethod
def generate_resource(cls, page, resource, action='post'):
# Handle deletion
if action == 'delete':
static.remove(page.path)
- return
- template_vals = {
- 'page': page,
- }
- rendered = utils.render_template('pages/%s' % (page.template,), template_vals)
- static.set(page.path, rendered, config.html_mime_type)
+ else:
+ template_vals = {
+ 'page': page,
+ }
+ rendered = utils.render_template('pages/%s' % (page.template,),
+ template_vals)
+ static.set(page.path, rendered, config.html_mime_type)
View
41 handlers.py
@@ -128,21 +128,21 @@ def get(self, post):
'post': post,
'is_admin': True}))
+
class RegenerateHandler(BaseHandler):
def post(self):
- regen = post_deploy.PostRegenerator()
- deferred.defer(regen.regenerate)
+ deferred.defer(post_deploy.PostRegenerator().regenerate)
+ deferred.defer(post_deploy.PageRegenerator().regenerate)
@rctay
rctay added a note May 21, 2011

why the repeat deferred call on .regenerate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
deferred.defer(post_deploy.try_post_deploy, force=True)
self.render_to_response("regenerating.html")
class PageForm(djangoforms.ModelForm):
path = forms.RegexField(
widget=forms.TextInput(attrs={'id':'path'}),
- regex='(/[a-zA-Z0-9].*)')
+ regex='(/[a-zA-Z0-9/]+)')
title = forms.CharField(widget=forms.TextInput(attrs={'id':'title'}))
- template = forms.ChoiceField(
- choices=[(k, v) for k, v in config.page_templates.iteritems()])
+ template = forms.ChoiceField(choices=config.page_templates.items())
body = forms.CharField(widget=forms.Textarea(attrs={
'id':'body',
'rows': 10,
@@ -158,13 +158,13 @@ def clean_path(self):
raise forms.ValidationError("The given path already exists.")
return data
+
class PageAdminHandler(BaseHandler):
def get(self):
offset = int(self.request.get('start', 0))
count = int(self.request.get('count', 20))
pages = models.Page.all().order('-updated').fetch(count, offset)
template_vals = {
- 'is_admin': True,
'offset': offset,
'count': count,
'prev_offset': max(0, offset - count),
@@ -174,6 +174,7 @@ def get(self):
}
self.render_to_response("indexpage.html", template_vals)
+
def with_page(fun):
def decorate(self, page_key=None):
page = None
@@ -187,6 +188,7 @@ def decorate(self, page_key=None):
fun(self, page)
return decorate
+
class PageHandler(BaseHandler):
def render_form(self, form):
self.render_to_response("editpage.html", {'form': form})
@@ -212,30 +214,19 @@ def post(self, page):
if page:
oldpath = page.path
page = form.save(commit=False)
- if page.path:
- page.updated = datetime.datetime.now()
- if not page.created:
- page.created = page.updated
- page.publish()
- # path edited, remove old stuff
- if page.path != oldpath:
- oldpage = models.Page.get_by_key_name(oldpath)
- oldpage.remove()
- self.render_to_response("publishedpage.html", {'page': page})
- else:
- self.render_form(form)
+ page.updated = datetime.datetime.now()
+ page.publish()
+ # path edited, remove old stuff
+ if page.path != oldpath:
+ oldpage = models.Page.get_by_key_name(oldpath)
+ oldpage.remove()
+ self.render_to_response("publishedpage.html", {'page': page})
else:
self.render_form(form)
+
class PageDeleteHandler(BaseHandler):
@with_page
def post(self, page):
page.remove()
self.render_to_response("deletedpage.html", None)
-
-class PageRegenerateHandler(BaseHandler):
- def post(self):
- regen = post_deploy.PageRegenerator()
- deferred.defer(regen.regenerate)
- deferred.defer(post_deploy.post_deploy, post_deploy.BLOGGART_VERSION)
- self.render_to_response("regeneratingpage.html")
View
2 models.py
@@ -153,7 +153,7 @@ class Page(db.Model):
title = db.TextProperty(required=True)
template = db.StringProperty(required=True)
body = db.TextProperty(required=True)
- created = db.DateTimeProperty()
+ created = db.DateTimeProperty(required=True, auto_now_add=True)
updated = db.DateTimeProperty()
@property
View
2 themes/default/admin/index.html
@@ -59,6 +59,6 @@
{% endif %}
<h2>Actions</h2>
<form method="post" action="{{config.url_prefix}}/admin/regenerate">
- <input type="submit" value="Regenerate all posts" />
+ <input type="submit" value="Regenerate all content" />
</form>
{% endblock %}
View
4 themes/default/admin/indexpage.html
@@ -56,7 +56,7 @@
<a href="?start={{next_offset}}&count={{count}}">Next -></a>
{% endif %}
<h2>Actions</h2>
- <form method="post" action="{{config.url_prefix}}/admin/regeneratepages">
- <input type="submit" value="Regenerate all pages" />
+ <form method="post" action="{{config.url_prefix}}/admin/regenerate">
+ <input type="submit" value="Regenerate all content" />
</form>
{% endblock %}
View
2 themes/default/admin/regenerating.html
@@ -1,6 +1,6 @@
{% extends "admin/base.html" %}
{% block title %}Regenerating posts{% endblock %}
{% block body %}
- <p>All posts are now being regenerated. Check the admin console's Task Queue
+ <p>All content is now being regenerated. Check the admin console's Task Queue
page to determine when the process is complete.</p>
{% endblock %}
View
6 themes/default/admin/regeneratingpage.html
@@ -1,6 +0,0 @@
-{% extends "admin/base.html" %}
-{% block title %}Regenerating pages{% endblock %}
-{% block body %}
- <p>All pages are now being regenerated. Check the admin console's Task Queue
- page to determine when the process is complete.</p>
-{% endblock %}

0 comments on commit e5017df

Please sign in to comment.
Something went wrong with that request. Please try again.