예제 #1
0
 def get(self, request, year, month=None):
     posts = Post.objects.filter(status='p')
     data = dict(archives=Post.archive_tree())
     if year:
         try:
             data['date'] = datetime.strptime(
                 "%s" % year, "%Y").strftime("%Y")
         except ValueError:
             raise Http404('Invalid year')
         posts = posts.filter(created__year=year)
     if month:
         date_str = "%s,%s" % (month, year)
         try:
             data['date'] = datetime.strptime(
                 date_str, "%m,%Y").strftime("%B %Y")
         except ValueError:
             raise Http404('Invalid year or month')
         posts = posts.filter(created__month=month)
     data['posts'] = posts
     return render(request, 'archive.tpl', data)