Commits

David Chambers committed e29fb4a

Added `include_pages` parameter to `utils.posts`. The category template now displays pages.

  • Participants
  • Parent commits da07ac2

Comments (0)

Files changed (3)

templates/excerpt.dhtml

 {% load mango_extras %}
 			<article>
 				<header>
-					<h2><a href="{{ post.canon_urls.abs }}">{{ post.meta.title|safe }}</a></h2>
-					<time datetime="{{ post.meta.datetime|datetime }}">{{ post.meta.datetime|display_date }}</time>
+					<h2><a href="{{ post.canon_urls.abs }}">{{ post.meta.title|safe }}</a></h2>{% if post.meta.datetime %}
+					<time datetime="{{ post.meta.datetime|datetime }}">{{ post.meta.datetime|display_date }}</time>{% endif %}
 				</header>
 				{{ post.excerpt|safe }}
 			</article>
 
     return (short_urls, canon_urls)
 
-def get_posts(path_to_posts, reverse=True):
+def get_posts(path_to_posts, include_pages=False, reverse=True):
     """
     Returns all of the posts in the directory and all directories below it
     
     >>> get_posts('mango/examples')[1]['html']
     u"\\n<p>Welcome to Mango. ... <strong>Congratulations!</strong></p>"
     """
-    posts = []
+    documents = []
     for dirpath, dirnames, filenames in os.walk(path_to_posts):
         filenames[:] = [f for f in filenames if not f.startswith('.')]
         for filename in filenames:
                 short_urls, canon_urls = post_urls(absolute_path)
                 this['short_urls'] = short_urls
                 this['canon_urls'] = canon_urls
-                posts.append(this)
+                documents.append(this)
 
-    dated_posts = [post for post in posts if post['meta'].get('datetime')] # display a post only if it has both a date and a time
-    dated_posts.sort(key=lambda post: post['meta']['datetime'], reverse=reverse)
-    return dated_posts
+    posts = []
+    pages = []
+    for document in documents:
+        if document['meta'].get('datetime'):
+            posts.append(document)
+        else:
+            pages.append(document)
 
-def posts(path_to_posts=PATH_TO_POSTS):
+    posts.sort(key=lambda post: post['meta']['datetime'], reverse=reverse)
+    pages.sort(key=lambda page: page['meta'].get('title'))
+
+    if include_pages:
+        return pages + posts
+
+    return posts
+
+def posts(path_to_posts=PATH_TO_POSTS, include_pages=False):
     """
     Simple wrapper for `get_posts` which returns cached posts if appropriate
     
     >>> posts('mango/examples')[1]['html']
     u"\\n<p>Welcome to Mango. ... <strong>Congratulations!</strong></p>"
     """
-    cache_key = u'posts:%s' % path_to_posts
+    cache_key = u'posts%s:%s' % ('+pages' if include_pages else '', path_to_posts)
     posts = cache.get(cache_key)
     if posts:
         return posts
 
-    posts = get_posts(path_to_posts)
+    posts = get_posts(path_to_posts, include_pages=include_pages)
     cache.set(cache_key, posts, INDEX_CACHE_SECONDS)
     return posts
 
         match = re.match(RE['alias=>canon'], os.path.split(filepath)[1])
         html = render_to_response('category.dhtml', dict({
             'name': match.group('canon'),
-            'category': utils.posts(filepath),
+            'category': utils.posts(filepath, include_pages=True),
         }, **context_defaults(request)))
         return HttpResponse(html)