Permalink
Browse files

Added support for tagging

  • Loading branch information...
1 parent 7a93f49 commit 9d9e5644f4a72485dbbd293f1e8c9b4c35df78b4 @Arachnid Arachnid committed with Nicholas Johnson Oct 14, 2009
Showing with 85 additions and 13 deletions.
  1. +56 −13 generators.py
  2. +6 −0 index.yaml
  3. +1 −0 models.py
  4. +9 −0 themes/default/listing.html
  5. +13 −0 themes/default/post.html
View
@@ -84,48 +84,91 @@ def generate_resource(cls, post, resource):
generator_list.append(PostContentGenerator)
-class IndexContentGenerator(ContentGenerator):
- """ContentGenerator for the homepage of the blog and archive pages."""
+class ListingContentGenerator(ContentGenerator):
+ path = None
+ """The path for listing pages."""
- @classmethod
- def get_resource_list(cls, post):
- return ["index"]
+ first_page_path = None
+ """The path for the first listing page."""
@classmethod
def get_etag(cls, post):
return hashlib.sha1((post.title + post.summary).encode('utf-8')).hexdigest()
@classmethod
+ def _filter_query(cls, resource, q):
+ """Applies filters to the BlogPost query.
+
+ Args:
+ resource: The resource being generated.
+ q: The query to act on.
+ """
+ pass
+
+ @classmethod
def generate_resource(cls, post, resource, pagenum=1, start_ts=None):
import models
q = models.BlogPost.all().order('-published')
if start_ts:
q.filter('published <=', start_ts)
+ cls._filter_query(resource, q)
posts = q.fetch(config.posts_per_page + 1)
more_posts = len(posts) > config.posts_per_page
+ path_args = {
+ 'resource': resource,
+ }
+ path_args['pagenum'] = pagenum - 1
+ prev_page = cls.path % path_args
+ path_args['pagenum'] = pagenum + 1
+ next_page = cls.path % path_args
template_vals = {
'posts': posts[:config.posts_per_page],
- 'prev_page': "/page/%d" % (pagenum - 1,) if pagenum > 1 else None,
- 'next_page': "/page/%d" % (pagenum + 1,) if more_posts else None,
+ 'prev_page': prev_page if pagenum > 1 else None,
+ 'next_page': next_page if more_posts else None,
}
rendered = utils.render_template("listing.html", template_vals)
- path_args = {
- 'resource': resource,
- 'pagenum': pagenum,
- }
- static.set('/page/%d' % (pagenum,), rendered, config.html_mime_type)
+ path_args['pagenum'] = pagenum
+ static.set(cls.path % path_args, rendered, config.html_mime_type)
if pagenum == 1:
- static.set('/', rendered, config.html_mime_type)
+ static.set(cls.first_page_path % path_args, rendered,
+ config.html_mime_type)
if more_posts:
deferred.defer(cls.generate_resource, None, resource, pagenum + 1,
posts[-1].published)
+
+
+class IndexContentGenerator(ListingContentGenerator):
+ """ContentGenerator for the homepage of the blog and archive pages."""
+
+ path = '/page/%(pagenum)d'
+ first_page_path = '/'
+
+ @classmethod
+ def get_resource_list(cls, post):
+ return ["index"]
generator_list.append(IndexContentGenerator)
+class TagsContentGenerator(ListingContentGenerator):
+ """ContentGenerator for the tags pages."""
+
+ path = '/tag/%(resource)s/%(pagenum)d'
+ first_page_path = '/tag/%(resource)s'
+
+ @classmethod
+ def get_resource_list(cls, post):
+ return post.tags
+
+ @classmethod
+ def _filter_query(cls, resource, q):
+ q.filter('tags =', resource)
+generator_list.append(TagsContentGenerator)
+
+
class AtomContentGenerator(ContentGenerator):
"""ContentGenerator for Atom feeds."""
View
@@ -1,5 +1,11 @@
indexes:
+- kind: BlogPost
+ properties:
+ - name: tags
+ - name: published
+ direction: desc
+
# AUTOGENERATED
# This index.yaml is automatically updated whenever the dev_appserver
View
@@ -14,6 +14,7 @@ class BlogPost(db.Model):
path = db.StringProperty()
title = db.StringProperty(required=True, indexed=False)
body = db.TextProperty(required=True)
+ tags = db.StringListProperty()
published = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
deps = aetycoon.PickleProperty()
@@ -3,6 +3,15 @@
{% block body %}
{% for post in posts %}
<h2><a href="{{post.path}}">{{post.title}}</a></h2>
+ <p class="post-info">
+ Posted by {{config.author_name}}
+ {% if post.tags %}
+ | Filed under
+ {% for tag in post.tags %}
+ <a href="/tag/{{tag|escape}}">{{tag|escape}}</a>{% if not forloop.last %},{% endif %}
+ {% endfor %}
+ {% endif %}
+ </p>
{{post.summary|linebreaks}}
<p class="postmeta">
<a href="{{post.path}}" class="readmore">Read more</a> |
View
@@ -2,5 +2,18 @@
{% block title %}{{post.title}} - {{config.blog_name}}{% endblock %}
{% block body %}
<h2>{{post.title}}</h2>
+ <p class="post-info">
+ Posted by {{config.author_name}}
+ {% if post.tags %}
+ | Filed under
+ {% for tag in post.tags %}
+ <a href="/tag/{{tag|escape}}">{{tag|escape}}</a>{% if not forloop.last %},{% endif %}
+ {% endfor %}
+ {% endif %}
+ </p>
+ <p class="postmeta">
+ <a href="{{post.path}}" class="readmore">Read more</a> |
+ <span class="date">{{post.published|date:"d F, Y"}}</span>
+ </p>
{{post.body|linebreaks}}
{% endblock %}

0 comments on commit 9d9e564

Please sign in to comment.