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:
|
||||
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):
|
||||
super(PostForm, self).__init__(*args, **kwargs)
|
||||
|
@ -42,7 +42,7 @@ class PostForm(ModelForm):
|
|||
class DraftForm(PostForm):
|
||||
class Meta:
|
||||
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 Meta:
|
||||
|
|
|
@ -105,6 +105,10 @@ class DynastieGenerator:
|
|||
else:
|
||||
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 not cache_obj:
|
||||
src_md5 = hashlib.md5()
|
||||
|
@ -262,7 +266,7 @@ class DynastieGenerator:
|
|||
continue
|
||||
|
||||
for child in target_block.childNodes:
|
||||
block.parentNode.appendChild(child.cloneNode(True))
|
||||
block.parentNode.insertBefore(child.cloneNode(True),block)
|
||||
block_found = True
|
||||
break
|
||||
block.parentNode.removeChild(block)
|
||||
|
|
|
@ -240,10 +240,11 @@ class Index(DynastieGenerator):
|
|||
if not user: user = post.author
|
||||
# Markdown replace
|
||||
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:
|
||||
for post_id in internal_posts.groups():
|
||||
post_id = int(post_id)
|
||||
for post in internal_posts:
|
||||
post_id = post.groups()
|
||||
post_id = int(post_id[0])
|
||||
if post_id in self.parent_posts: continue
|
||||
_,post = self._have_I_right(user, post_id)
|
||||
if not post: continue
|
||||
|
@ -308,7 +309,7 @@ class Index(DynastieGenerator):
|
|||
from dynastie.models import Post
|
||||
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]
|
||||
return node.cloneNode(0)
|
||||
|
||||
|
@ -335,26 +336,27 @@ class Index(DynastieGenerator):
|
|||
new_node = dom.createTextNode(post_content)
|
||||
content_node.appendChild(new_node)
|
||||
|
||||
writer = StrictUTF8Writer()
|
||||
post_elem.writexml(writer)
|
||||
content = writer.getvalue().encode('utf-8')
|
||||
# Disable this cache
|
||||
# writer = StrictUTF8Writer()
|
||||
# post_elem.writexml(writer)
|
||||
# content = writer.getvalue().encode('utf-8')
|
||||
|
||||
md5 = hashlib.md5()
|
||||
md5.update(content)
|
||||
# md5 = hashlib.md5()
|
||||
# md5.update(content)
|
||||
|
||||
if post.id in self.hash_posts:
|
||||
# Here, we are in first_try, check that computed
|
||||
# post has the same result than the one in cache
|
||||
self.first_try = False
|
||||
# if post.id in self.hash_posts:
|
||||
# # Here, we are in first_try, check that computed
|
||||
# # post has the same result than the one in cache
|
||||
# self.first_try = False
|
||||
|
||||
_,md5_2 = self.hash_posts[post.id]
|
||||
# _,md5_2 = self.hash_posts[post.id]
|
||||
|
||||
# If not, clear cache
|
||||
if md5.digest() != md5_2:
|
||||
self.hash_posts = {}
|
||||
self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||
else:
|
||||
self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||
# # If not, clear cache
|
||||
# if md5.digest() != md5_2:
|
||||
# self.hash_posts = {}
|
||||
# self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||
# else:
|
||||
# self.hash_posts[post.id] = (post_elem.cloneNode(0), md5.digest())
|
||||
|
||||
return post_elem
|
||||
|
||||
|
@ -363,10 +365,9 @@ class Index(DynastieGenerator):
|
|||
create_link = (node.getAttribute('link') == '1')
|
||||
for i in range(0, self.posts_per_page):
|
||||
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]
|
||||
post_elem = self.createPost(posts, dom, post_elem, node)
|
||||
if post_elem is None: continue
|
||||
else:
|
||||
post_elem = self.createElement(dom, '', '<b>No posts yet</b>')
|
||||
self.cur_post_obj = None
|
||||
|
@ -554,8 +555,6 @@ class Index(DynastieGenerator):
|
|||
self.cur_page = self.cur_page + 1
|
||||
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
||||
|
||||
filename = output + filename
|
||||
|
||||
while os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
|
@ -565,7 +564,6 @@ class Index(DynastieGenerator):
|
|||
os.unlink(filename)
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = self.dirname + '/' + self.filename + str(self.cur_page) + '.html'
|
||||
filename = output + filename
|
||||
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Post, Blog
|
||||
|
|
Loading…
Reference in New Issue
Block a user