Fix some bugs:
* Don't use cached objects if file has been removed * Replace subblock node with all of this nodes instead of appending them at the end of parent (respect order) * Disable Post cache cause it generates some random errors * Don't forget to update cur page number, even if Post creation has failed
This commit is contained in:
parent
f99bea97ef
commit
4b642fa48a
|
@ -33,7 +33,7 @@ class PostForm(ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Post
|
model = Post
|
||||||
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format')
|
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format', 'post_type')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PostForm, self).__init__(*args, **kwargs)
|
super(PostForm, self).__init__(*args, **kwargs)
|
||||||
|
@ -42,7 +42,7 @@ class PostForm(ModelForm):
|
||||||
class DraftForm(PostForm):
|
class DraftForm(PostForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Draft
|
model = Draft
|
||||||
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format', 'published')
|
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format', 'published', 'post_type')
|
||||||
|
|
||||||
class CategoryForm(ModelForm):
|
class CategoryForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -105,6 +105,10 @@ class DynastieGenerator:
|
||||||
else:
|
else:
|
||||||
cache_obj = cache_objs[0]
|
cache_obj = cache_objs[0]
|
||||||
|
|
||||||
|
if cache_obj and not os.path.exists(filename):
|
||||||
|
cache_obj.delete()
|
||||||
|
cache_obj = None
|
||||||
|
|
||||||
if cache_obj or os.path.exists(filename):
|
if cache_obj or os.path.exists(filename):
|
||||||
if not cache_obj:
|
if not cache_obj:
|
||||||
src_md5 = hashlib.md5()
|
src_md5 = hashlib.md5()
|
||||||
|
@ -262,7 +266,7 @@ class DynastieGenerator:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for child in target_block.childNodes:
|
for child in target_block.childNodes:
|
||||||
block.parentNode.appendChild(child.cloneNode(True))
|
block.parentNode.insertBefore(child.cloneNode(True),block)
|
||||||
block_found = True
|
block_found = True
|
||||||
break
|
break
|
||||||
block.parentNode.removeChild(block)
|
block.parentNode.removeChild(block)
|
||||||
|
|
|
@ -240,10 +240,11 @@ class Index(DynastieGenerator):
|
||||||
if not user: user = post.author
|
if not user: user = post.author
|
||||||
# Markdown replace
|
# Markdown replace
|
||||||
if not post or (post and post.content_format == Post.CONTENT_TEXT):
|
if not post or (post and post.content_format == Post.CONTENT_TEXT):
|
||||||
internal_posts = re.search('\[\[([0-9]+)\]\]', text)
|
internal_posts = re.finditer('\[\[([0-9]+)\]\]', text)
|
||||||
if internal_posts:
|
if internal_posts:
|
||||||
for post_id in internal_posts.groups():
|
for post in internal_posts:
|
||||||
post_id = int(post_id)
|
post_id = post.groups()
|
||||||
|
post_id = int(post_id[0])
|
||||||
if post_id in self.parent_posts: continue
|
if post_id in self.parent_posts: continue
|
||||||
_,post = self._have_I_right(user, post_id)
|
_,post = self._have_I_right(user, post_id)
|
||||||
if not post: continue
|
if not post: continue
|
||||||
|
@ -308,7 +309,7 @@ class Index(DynastieGenerator):
|
||||||
from dynastie.models import Post
|
from dynastie.models import Post
|
||||||
post = self.cur_post_obj
|
post = self.cur_post_obj
|
||||||
|
|
||||||
if post.id in self.hash_posts and not self.first_try:
|
if post.id > 0 and post.id in self.hash_posts.keys() and not self.first_try:
|
||||||
node,_ = self.hash_posts[post.id]
|
node,_ = self.hash_posts[post.id]
|
||||||
return node.cloneNode(0)
|
return node.cloneNode(0)
|
||||||
|
|
||||||
|
@ -335,26 +336,27 @@ class Index(DynastieGenerator):
|
||||||
new_node = dom.createTextNode(post_content)
|
new_node = dom.createTextNode(post_content)
|
||||||
content_node.appendChild(new_node)
|
content_node.appendChild(new_node)
|
||||||
|
|
||||||
writer = StrictUTF8Writer()
|
# Disable this cache
|
||||||
post_elem.writexml(writer)
|
# writer = StrictUTF8Writer()
|
||||||
content = writer.getvalue().encode('utf-8')
|
# post_elem.writexml(writer)
|
||||||
|
# content = writer.getvalue().encode('utf-8')
|
||||||
|
|
||||||
md5 = hashlib.md5()
|
# md5 = hashlib.md5()
|
||||||
md5.update(content)
|
# md5.update(content)
|
||||||
|
|
||||||
if post.id in self.hash_posts:
|
# if post.id in self.hash_posts:
|
||||||
# Here, we are in first_try, check that computed
|
# # Here, we are in first_try, check that computed
|
||||||
# post has the same result than the one in cache
|
# # post has the same result than the one in cache
|
||||||
self.first_try = False
|
# self.first_try = False
|
||||||
|
|
||||||
_,md5_2 = self.hash_posts[post.id]
|
# _,md5_2 = self.hash_posts[post.id]
|
||||||
|
|
||||||
# If not, clear cache
|
# # If not, clear cache
|
||||||
if md5.digest() != md5_2:
|
# if md5.digest() != md5_2:
|
||||||
self.hash_posts = {}
|
# self.hash_posts = {}
|
||||||
self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
# self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||||
else:
|
# else:
|
||||||
self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
# self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||||
|
|
||||||
return post_elem
|
return post_elem
|
||||||
|
|
||||||
|
@ -363,10 +365,9 @@ class Index(DynastieGenerator):
|
||||||
create_link = (node.getAttribute('link') == '1')
|
create_link = (node.getAttribute('link') == '1')
|
||||||
for i in range(0, self.posts_per_page):
|
for i in range(0, self.posts_per_page):
|
||||||
post_elem = self.createElement(dom, 'post')
|
post_elem = self.createElement(dom, 'post')
|
||||||
if len(posts) > self.cur_post:
|
if self.cur_post < len(posts):
|
||||||
self.cur_post_obj = posts[self.cur_post]
|
self.cur_post_obj = posts[self.cur_post]
|
||||||
post_elem = self.createPost(posts, dom, post_elem, node)
|
post_elem = self.createPost(posts, dom, post_elem, node)
|
||||||
if post_elem is None: continue
|
|
||||||
else:
|
else:
|
||||||
post_elem = self.createElement(dom, '', '<b>No posts yet</b>')
|
post_elem = self.createElement(dom, '', '<b>No posts yet</b>')
|
||||||
self.cur_post_obj = None
|
self.cur_post_obj = None
|
||||||
|
@ -554,8 +555,6 @@ class Index(DynastieGenerator):
|
||||||
self.cur_page = self.cur_page + 1
|
self.cur_page = self.cur_page + 1
|
||||||
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
||||||
|
|
||||||
filename = output + filename
|
|
||||||
|
|
||||||
while os.path.exists(filename):
|
while os.path.exists(filename):
|
||||||
self.addReport('Removing unused ' + filename)
|
self.addReport('Removing unused ' + filename)
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
|
@ -565,7 +564,6 @@ class Index(DynastieGenerator):
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
self.cur_page = self.cur_page + 1
|
self.cur_page = self.cur_page + 1
|
||||||
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
||||||
filename = output + filename
|
|
||||||
|
|
||||||
def generate(self, blog, src, output):
|
def generate(self, blog, src, output):
|
||||||
from dynastie.models import Post, Blog
|
from dynastie.models import Post, Blog
|
||||||
|
|
Loading…
Reference in New Issue
Block a user