# -*- coding: utf-8 -*- """ Copyright 2012-2014 Grégory Soutadé This file is part of Dynastie. Dynastie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Dynastie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Dynastie. If not, see . """ from datetime import datetime from dynastie.generators.index import Index from django.db import models class Archive(Index): def createArchive(self, posts, dom, root, node): if node.hasAttribute('year'): self.replaceByText(dom, root, node, str(self.cur_year)) return None def generate(self, blog, src, output): from dynastie.models import Post, Blog self.hooks['archive'] = self.createArchive dom = self.parseTemplate(blog, src, output, 'archive', 'archive') if dom is None: return self.report posts = Post.objects.filter(published=True, front_page=True).order_by('creation_date') if len(posts) == 0: return self.report first_post = posts[0] last_post = posts[len(posts)-1] start_year = first_post.creation_date.year end_year = last_post.creation_date.year now = datetime.now() for i in range(start_year, end_year+1): if i == now.year: continue self.cur_year = i posts = Post.objects.filter(published=True, creation_date__gt=datetime(i, 1, 1), creation_date__lt=datetime(i+1, 1, 1)).order_by('-creation_date') self.resetCounters() self.dirname = '/archive/' + str(i) self.generatePages(dom, posts, src, output, 'archive') if not self.somethingWrote: self.addReport('Nothing changed') return self.report