Dynastie/dynastie/generators/category.py
2014-09-24 20:27:27 +02:00

59 lines
1.9 KiB
Python
Executable File

# -*- 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 <http://www.gnu.org/licenses/>.
"""
from dynastie.generators.index import Index
from django.db import models
class Category(Index):
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):
from dynastie.models import Post, Blog, Category
self.cur_category = None
self.hooks['category'] = self.createCategory
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
posts = Post.objects.filter(category__exact=category, published=True).order_by('-creation_date')
self.resetCounters()
self.dirname = '/category/' + category.name_slug
self.generatePages(dom, posts, src, output, 'category')
if not self.somethingWrote:
self.addReport('Nothing changed')
return self.report