Permalink
Browse files

Changes corresponding to article.

  • Loading branch information...
1 parent e7b2c1b commit e199acb71a648e1b4cb64dd34ae938805260801e @bmc committed Aug 8, 2008
Showing with 25 additions and 18 deletions.
  1. +12 −9 admin.py
  2. +1 −2 blog.py
  3. +11 −6 models.py
  4. +1 −1 request.py
View
@@ -26,18 +26,20 @@ class ShowArticlesHandler(request.BlogRequestHandler):
def get(self):
articles = Article.get_all()
template_vars = {'articles' : articles}
- self.render_template('admin-main.html', template_vars)
-
+ self.response.out.write(self.render_template('admin-main.html',
+ template_vars))
+
class NewArticleHandler(request.BlogRequestHandler):
"""
Handles requests to create and edit a new article.
"""
def get(self):
- article = Article(title='New article',
+ article = Article(title='New article',
body='Content goes here',
draft=True)
template_vars = {'article' : article}
- self.render_template('admin-edit.html', template_vars)
+ self.response.out.write(self.render_template('admin-edit.html',
+ template_vars))
class SaveArticleHandler(request.BlogRequestHandler):
"""
@@ -76,7 +78,7 @@ def post(self):
draft=draft)
article.save()
-
+
edit_again = cgi.escape(self.request.get('edit_again'))
edit_again = edit_again and (edit_again.lower() == 'true')
if edit_again:
@@ -96,8 +98,9 @@ def get(self):
article.tag_string = ', '.join(article.tags)
template_vars = {'article' : article}
- self.render_template('admin-edit.html', template_vars)
-
+ self.response.out.write(self.render_template('admin-edit.html',
+ template_vars))
+
class DeleteArticleHandler(request.BlogRequestHandler):
"""
Handles form submissions to delete an article.
@@ -109,7 +112,7 @@ def get(self):
article.delete()
self.redirect('/admin/')
-
+
# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------
@@ -123,7 +126,7 @@ def get(self):
],
debug=True)
-
+
# -----------------------------------------------------------------------------
# Main program
# -----------------------------------------------------------------------------
View
@@ -225,8 +225,7 @@ def get_recent(self):
:rtype: list
:return: list of recent ``Article`` objects
"""
- if not articles:
- articles = Article.published()
+ articles = Article.published()
total_recent = min(len(articles), defs.TOTAL_RECENT)
if articles:
View
@@ -46,11 +46,16 @@ def get(cls, id):
return articles[0] if articles else None
@classmethod
- def published(cls):
+ def published_query(cls):
q = db.Query(Article)
q.filter('draft = ', False)
- q.order('-published_when')
- return q.fetch(FETCH_THEM_ALL)
+ return q
+
+ @classmethod
+ def published(cls):
+ return Article.published_query()\
+ .order('-published_when')\
+ .fetch(FETCH_THEM_ALL)
@classmethod
def get_all_tags(cls):
@@ -99,11 +104,11 @@ def all_for_month(cls, year, month):
next_month = start_date.month + 1
end_date = datetime.date(next_year, next_month, 1)
- query = Article.published()\
+ return Article.published_query()\
.filter('published_when >=', start_date)\
.filter('published_when <', end_date)\
- .order('-published_when')
- return query.fetch(FETCH_THEM_ALL)
+ .order('-published_when')\
+ .fetch(FETCH_THEM_ALL)
@classmethod
def all_for_tag(cls, tag):
View
@@ -50,4 +50,4 @@ def render_template(self, template_name, template_vars):
Can be empty.
"""
template_path = self.get_template(template_name)
- self.response.out.write(template.render(template_path, template_vars))
+ return template.render(template_path, template_vars)

0 comments on commit e199acb

Please sign in to comment.