Fix some bugs + add primary comment support

This commit is contained in:
2012-10-11 22:26:47 +02:00
parent 76cda68611
commit 01685868e2
6 changed files with 95 additions and 54 deletions

View File

@@ -142,6 +142,9 @@ class DynastieGenerator:
new_elem = self.createElement(dom, node.localName)
new_elem.appendChild(content)
elem.appendChild(new_elem)
else:
new_elem = node.cloneNode(True)
elem.appendChild(new_elem)
else:
new_elem = node.cloneNode(False)
self.simpleTransform(values, dom, new_elem, node)

View File

@@ -59,12 +59,12 @@ class Index(DynastieGenerator):
new_dom = parseString('<div class="navigation">' + nav + '</div>')
new_node = new_dom.getElementsByTagName('div')[0]
root.replaceChild(new_node.cloneNode(True), node)
def createPost(self, post, dom, post_elem, root):
values = {}
values['title'] = self.createLinkElem(dom, post.getPath(), post.title)
values['author'] = post.author.first_name + ' ' + post.author.last_name
values['date'] = post.creation_date.strftime("%A, %d %B %Y %H:%m")
values['date'] = post.creation_date.strftime('%A, %d %B %Y %H:%m')
values['post_content'] = ''
blog = post.blog
@@ -81,17 +81,17 @@ class Index(DynastieGenerator):
f.close()
self.simpleTransform(values, dom, post_elem, root)
content_nodes = post_elem.getElementsByTagName("div")
post_transform = ('post_content')
content_nodes = post_elem.getElementsByTagName('div')
post_transform = ['post_content']
for content_node in content_nodes:
the_class = content_node.getAttribute('class')
if not the_class in post_transform:
continue
if the_class == 'post_content':
new_node = dom.createTextNode(post_content)
content_node.appendChild(new_node)
new_node = dom.createTextNode(post_content)
content_node.appendChild(new_node)
def createPosts(self, posts, dom, root, node):
posts_elem = self.createElement(dom, 'posts')
for i in range(0, self.posts_per_page):

View File

@@ -7,6 +7,38 @@ from django.db import models
class Post(Index):
def createComments(self, post, dom, post_elem, root):
from dynastie.models import Post, Blog, Comment
base_url = root.getAttribute('base_url')
add_comment = (root.getAttribute('add_comment') == '1')
comments = Comment.objects.filter(post=post)
comment_list_list = []
for comment in comments:
try:
if comment.parent_id == 0:
comment_list_list.append([comment])
else:
for comment_list in comment_list_list:
if comment_list[0].id == comment.parent_id:
comment_list.append(comment)
break
except Comment.DoesNotExist:
comment_list_list.append([comment])
initial_root_comment = root_comment = self.createElement(dom, 'comments')
for comment_list in comment_list_list:
for comment in comment_list:
comment_element = self.createElement(dom, 'comment')
comment_content = self.createElement(dom, 'comment_content', comment.the_comment)
comment_element.appendChild(comment_content)
root_comment.appendChild(comment_element)
root_comment = comment_element
root_comment = initial_root_comment
post_elem.replaceChild(root_comment, root)
def createMetas(self, post, dom, meta_elem, root):
name = root.getAttribute('name')
if name is None:
@@ -29,7 +61,13 @@ class Post(Index):
self.addError('name attribute \'' + name + '\' unknown for dyn:meta' )
def _createPost(self, post, dom, post_elem, root):
import sys, traceback
if post.id == 122:
print post_elem.toxml()
self.createPost(post, dom, post_elem, root)
# Post are appended by index. Remove template
post_nodes = dom.getElementsByTagNameNS(self.URI, 'post')
post_elem = post_nodes[0]
post_elem.parentNode.removeChild(post_elem)
@@ -43,8 +81,10 @@ class Post(Index):
node.appendChild(dom.createTextNode(post.title))
def _generate(self, blog, src, output, posts):
import xml
hooks = {'post' : self._createPost,
'meta' : self.createMetas}
'meta' : self.createMetas,
'comments' : self.createComments}
if not os.path.exists(src + '/_post.html'):
self.addError('No _post.html found, exiting')
@@ -63,6 +103,7 @@ class Post(Index):
#print 'Generate ' + filename
nodes = dom.getElementsByTagName("*")
nodes[0] = self.parse(src, hooks, post, dom, nodes[0])
filename = output + '/post/'
filename = filename + post.creation_date.strftime("%Y") + '/' + post.creation_date.strftime("%m") + '/'
if not os.path.exists(filename):