Simplify archive generation code
This commit is contained in:
parent
cce2361b75
commit
0e60732f26
|
@ -48,39 +48,27 @@ class Archive(Index):
|
||||||
dom = self.parseTemplate(blog, src, output, 'archive', 'archive')
|
dom = self.parseTemplate(blog, src, output, 'archive', 'archive')
|
||||||
if dom is None: return self.report
|
if dom is None: return self.report
|
||||||
|
|
||||||
posts = Post.objects.filter(published=True, front_page=True).order_by('creation_date')
|
first_post = Post.objects.filter(published=True, front_page=True).order_by('creation_date')[0]
|
||||||
|
last_post = Post.objects.filter(published=True, front_page=True).order_by('-creation_date')[0]
|
||||||
|
|
||||||
if posts.count() != 0:
|
start_year = first_post.creation_date.year
|
||||||
self.cur_year = int(posts[0].creation_date.year)
|
end_year = last_post.creation_date.year
|
||||||
|
|
||||||
my_post = []
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
nb_post = len(posts)
|
for i in range(start_year, end_year):
|
||||||
for i in range(0, nb_post):
|
if i == now.year: continue
|
||||||
if self.cur_year == now.year:
|
|
||||||
break
|
|
||||||
|
|
||||||
if i < nb_post-1:
|
self.cur_year = i
|
||||||
if posts[i].creation_date.year != posts[i+1].creation_date.year:
|
|
||||||
my_post.reverse()
|
posts = Post.objects.filter(published=True, front_page=True, creation_date__gt=datetime(i, 1, 1), creation_date__lt=datetime(i+1, 1, 1)).order_by('-creation_date')
|
||||||
|
|
||||||
self.nb_pages = 0
|
self.nb_pages = 0
|
||||||
self.cur_page = 0
|
self.cur_page = 0
|
||||||
self.cur_post = 0
|
self.cur_post = 0
|
||||||
|
|
||||||
self.dirname = '/archive/' + str(self.cur_year)
|
self.dirname = '/archive/' + str(i)
|
||||||
|
|
||||||
self.generatePages(dom, my_post, src, output, 'archive')
|
self.generatePages(dom, posts, src, output, 'archive')
|
||||||
self.cur_year = int(posts[i+1].creation_date.year)
|
|
||||||
#print 'New year ' + str(self.cur_year)
|
|
||||||
my_post = []
|
|
||||||
else:
|
|
||||||
my_post.append(posts[i])
|
|
||||||
else:
|
|
||||||
# Last post
|
|
||||||
my_post.append(posts[i])
|
|
||||||
if nb_post != 1 and posts[i].creation_date.year != posts[i-1].creation_date.year:
|
|
||||||
self.cur_year = int(posts[i].creation_date.year)
|
|
||||||
|
|
||||||
if not self.somethingWrote:
|
if not self.somethingWrote:
|
||||||
self.addReport('Nothing changed')
|
self.addReport('Nothing changed')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user