| 
									
										
										
										
											2013-02-09 08:55:06 +01:00
										 |  |  | # -*- coding: utf-8 -*- | 
					
						
							| 
									
										
										
										
											2013-02-07 18:50:54 +01:00
										 |  |  | """
 | 
					
						
							| 
									
										
										
										
											2014-01-04 13:55:30 +01:00
										 |  |  |   Copyright 2012-2014 Grégory Soutadé | 
					
						
							| 
									
										
										
										
											2013-02-07 18:50:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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/>. | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02: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 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 = '' | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  |     cur_category = None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 09:09:14 +02:00
										 |  |  |     def createCategory(self, posts, dom, root, node): | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  |         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) | 
					
						
							| 
									
										
										
										
											2012-10-16 22:06:33 +02:00
										 |  |  |         return None | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def generate(self, blog, src, output): | 
					
						
							| 
									
										
										
										
											2012-08-28 09:09:14 +02:00
										 |  |  |         from dynastie.models import Post, Blog, Category | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-06 12:10:29 +01:00
										 |  |  |         self.hooks['category'] = self.createCategory | 
					
						
							| 
									
										
										
										
											2012-12-10 19:30:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-31 13:58:47 +01:00
										 |  |  |         dom = self.parseTemplate(blog, src, output, 'category', 'category') | 
					
						
							|  |  |  |         if dom is None: return self.report | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         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') | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-17 08:38:58 +01:00
										 |  |  |             self.generatePages(dom, posts, src, output, 'category') | 
					
						
							| 
									
										
										
										
											2012-07-22 19:07:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if not self.somethingWrote: | 
					
						
							|  |  |  |             self.addReport('Nothing changed') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return self.report | 
					
						
							|  |  |  | 
 |