Dynastie/generators/tag.py

51 lines
1.4 KiB
Python
Raw Normal View History

2012-11-10 11:35:48 +01:00
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
2012-12-10 19:30:25 +01:00
dom = self.parseTemplate(blog, src, output, 'tag', 'tag')
if dom is None: return self.report
2012-11-10 11:35:48 +01:00
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', 'tag')
2012-11-10 11:35:48 +01:00
if not self.somethingWrote:
self.addReport('Nothing changed')
return self.report