Dynastie/generators/category.py

51 lines
1.5 KiB
Python
Raw Normal View History

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 Category(Index):
cur_page = 0
nb_pages = 0
2012-08-28 09:09:14 +02:00
cur_post = 0
posts_per_page = 0
2012-08-04 21:21:04 +02:00
filename = 'index'
2012-08-14 21:26:48 +02:00
dirname = ''
cur_category = None
2012-08-28 09:09:14 +02:00
def createCategory(self, posts, dom, root, node):
if node.hasAttribute('name'):
self.replaceByText(dom, root, node, self.cur_category.name)
if node.hasAttribute('description'):
self.replaceByText(dom, root, node, self.cur_category.description)
return None
def generate(self, blog, src, output):
2012-08-28 09:09:14 +02:00
from dynastie.models import Post, Blog, Category
self.hooks['category'] = self.createCategory
2012-12-10 19:30:25 +01:00
dom = self.parseTemplate(blog, src, output, 'category', 'category')
if dom is None: return self.report
categories = Category.objects.all()
for category in categories:
self.cur_category = category
2012-08-28 09:09:14 +02:00
posts = Post.objects.filter(category__exact=category, published=True).order_by('-creation_date')
self.nb_pages = 0
self.cur_page = 0
2012-08-28 09:09:14 +02:00
self.cur_post = 0
2012-08-04 21:21:04 +02:00
2012-08-14 21:26:48 +02:00
self.dirname = '/category/' + category.name_slug
self.generatePages(dom, posts, src, output, 'category', 'category')
if not self.somethingWrote:
self.addReport('Nothing changed')
return self.report