def archive_year(request, year): posts = Post.query(Post.active == True).order(-Post.created_at).fetch() posts_filtered = [] for post in posts: if post.created_at.year == int(year): posts_filtered.append(post) archive = build_archive() return render_to_response('index.html', {'posts': posts_filtered, 'archive': archive})
def build_archive(): posts = Post.query(Post.active == True).order(-Post.created_at).fetch() archive = {} for post in posts: year = post.created_at.year month = post.created_at.strftime('%m-%B') if year not in archive: archive[year] = [] if month not in archive[year]: archive[year].append(month) return archive
def index(request): posts = Post.query(Post.active == True).order(-Post.created_at).fetch() archive = build_archive() return render_to_response('index.html', {'posts': posts, 'archive': archive})