Dynastie/generators/tag.py
Grégory Soutadé cce2361b75 Archive geenration was broken for tags
Change ALl rights reserved in Tous droits réservés
2013-02-17 08:38:58 +01:00

70 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""
Copyright 2012-2013 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 <http://www.gnu.org/licenses/>.
"""
import os
from xml.dom.minidom import parse, parseString
from dynastie.generators.generator import DynastieGenerator
from dynastie.generators.index import Index
from django.db import models
class Tag(Index):
cur_page = 0
nb_pages = 0
cur_post = 0
posts_per_page = 0
filename = 'index'
dirname = ''
cur_tag = None
def createTag(self, posts, dom, root, node):
if node.hasAttribute('name'):
self.replaceByText(dom, root, node, self.cur_tag.name)
if node.hasAttribute('description'):
self.replaceByText(dom, root, node, self.cur_tag.description)
return None
def generate(self, blog, src, output):
from dynastie.models import Post, Blog, Tag
self.hooks['tag'] = self.createTag
dom = self.parseTemplate(blog, src, output, 'tag', 'tag')
if dom is None: return self.report
tags = Tag.objects.all()
for tag in tags:
self.cur_tag = tag
posts = Post.objects.filter(tags__in=[tag.id], published=True).order_by('-creation_date')
self.nb_pages = 0
self.cur_page = 0
self.cur_post = 0
self.dirname = '/tag/' + tag.name_slug
self.generatePages(dom, posts, src, output, 'tag')
if not self.somethingWrote:
self.addReport('Nothing changed')
return self.report