Browse files

add by category in archive view

  • Loading branch information...
1 parent af73fb0 commit 62d3e7ea04b4fa6e280aa095589316420cd53167 @zhili committed Apr 16, 2011
Showing with 36 additions and 29 deletions.
  1. +12 −3 blog.py
  2. +24 −26 templates/archive.html
View
15 blog.py
@@ -31,7 +31,8 @@
from google.appengine.datastore import entity_pb
import logging
-ARCHIVES_CACHE_TIME = 600
+ARCHIVES_CACHE_TIME = 43200
+CATEGORIES_REFRESH_TIME = 3600
class Entry(search.Searchable, db.Model):
"""A single blog entry."""
@@ -142,7 +143,7 @@ def get(self, slug):
nextEntry = db.Query(Entry).filter('published >', entry.published).order('published').get()
prevEntry = db.Query(Entry).filter('published <', entry.published).order('-published').get()
prevNextEntry = (prevEntry, nextEntry)
- comments = db.Query(Comment).filter("slug =", slug).fetch(100)
+ comments = db.Query(Comment).filter("slug =", slug).fetch(1000)
self.render("entry.html", entry=entry, comments=comments, archives=self.get_archives(), prevnextentry=prevNextEntry)
class PagingHandler(BaseHandler):
@@ -166,7 +167,15 @@ def get(self, page):
class ArchiveHandler(BaseHandler):
def get(self):
- self.render("archive.html", entries=self.get_archives(fullArchives=True), archives=self.get_archives())
+ allCategories = memcache.get("categories")
+ if not allCategories:
+ entries = Entry.all()
+ allCategories = set()
+ for entry in entries:
+ # logging.info(entry.categories)
+ allCategories = allCategories.union(set(entry.categories))
+ memcache.set("categories", allCategories, CATEGORIES_REFRESH_TIME)
+ self.render("archive.html", categories = allCategories, archive_list=self.get_archives(fullArchives=True), archives=self.get_archives())
class MonthArchiveHandler(BaseHandler):
def get(self, year, month):
View
50 templates/archive.html
@@ -1,32 +1,30 @@
{% extends "base.html" %}
-{% block head %}
- <style type="text/css">
- ul.archive {
- list-style-type: none;
- margin: 0;
- padding: 0;
- }
-
- ul.archive li {
- margin-bottom: 1em;
- }
-
- ul.archive .title {
- font-family: "Helvetica Nue", Helvetica, Arial, sans-serif;
- font-size: 14pt;
- }
- </style>
-{% end %}
-
{% block body %}
- <ul class="archive">
- {% for entry in entries %}
- <li>
- <div class="title"><a href="/{{ entry[0] }}/{{ entry[1]}}">{{ entry[2] }}</a></div>
- </li>
- {% end %}
- </ul>
+ <div class="entry">
+ <h3>The Archives</h3>
+ </div>
+
+ <div class="entry">
+ <div style="float:right;width:250px;">
+ <h4>By Month</h4>
+ <ul class="archive">
+ {% for month_archive in archive_list %}
+ <li>
+ <div class="title"><a href="/{{ month_archive[0] }}/{{ month_archive[1] }}">{{ month_archive[2] }}</a></div>
+ </li>
+ {% end %}
+ </ul>
+ </div>
+ <h4>By Category</h4>
+ <ul class="categories">
+ {% for cat in categories %}
+ <li>
+ <div class="title"><a href="/categories/{{ cat }}/">{{cat}}</a>
+ </li>
+ {% end %}
+ </ul>
+ </div>
{% end %}
{% block paging %}

0 comments on commit 62d3e7e

Please sign in to comment.