Add verifications during blog generation when user/category is suppressed

Delete comments when a post is deleted
Forgot to set email input as hidden in comment responses
Forgot to setup cache for post comment generation
This commit is contained in:
Grégory Soutadé 2013-01-29 18:51:23 +01:00
parent 8d02850017
commit 0150b9f6cd
7 changed files with 40 additions and 22 deletions

View File

@ -44,11 +44,13 @@ class Atom(RSS):
modificationDate = post.modification_date.strftime('%Y-%m-%dT%H:%M:%SZ')
self.appendElement(dom, item, 'updated', modificationDate)
self.appendElement(dom, item, 'id', path)
author = dom.createElement('author')
self.appendElement(dom, author, 'name', post.author.first_name + ' ' + post.author.last_name)
self.appendElement(dom, author, 'email', post.author.email)
item.appendChild(author)
try:
author = dom.createElement('author')
self.appendElement(dom, author, 'name', post.author.first_name + ' ' + post.author.last_name)
self.appendElement(dom, author, 'email', post.author.email)
item.appendChild(author)
except:
pass
filename = blog.src_path + '/_post/' + str(post.id)
if not os.path.exists(filename):

View File

@ -125,7 +125,10 @@ class Index(DynastieGenerator):
return node.cloneNode(0)
values = {}
values['author'] = post.author.first_name + ' ' + post.author.last_name
try:
values['author'] = post.author.first_name + ' ' + post.author.last_name
except:
values['author'] = 'Unknown'
values['post_content'] = ''
blog = post.blog

View File

@ -108,7 +108,10 @@ class Post(Index):
elif name == 'description':
new_elem = self.createMeta(dom, name, post.description)
elif name == 'author':
new_elem = self.createMeta(dom, name, post.author.first_name + ' ' + post.author.last_name)
try:
new_elem = self.createMeta(dom, name, post.author.first_name + ' ' + post.author.last_name)
except:
return None
if not new_elem is None:
root.parentNode.replaceChild(new_elem, root)

View File

@ -61,10 +61,13 @@ class RSS(DynastieGenerator):
self.appendElement(dom, item, 'description', '<![CDATA[' + post_content + ']]>')
author = post.author.email
author += ' (' + post.author.first_name + ' ' + post.author.last_name + ')'
self.appendElement(dom, item, 'author', author)
self.appendElement(dom, item, 'category', post.category.name)
try:
author = post.author.email
author += ' (' + post.author.first_name + ' ' + post.author.last_name + ')'
self.appendElement(dom, item, 'author', author)
self.appendElement(dom, item, 'category', post.category.name)
except:
pass
creationDate = post.creation_date.strftime('%a, %d %b %Y %H:%M:%S')
self.appendElement(dom, item, 'pubDate', creationDate)

View File

@ -362,3 +362,8 @@ def delete_tag_signal(sender, **kwargs):
@receiver(post_delete, sender=Post)
def delete_post_signal(sender, **kwargs):
kwargs['instance'].remove()
@receiver(pre_delete, sender=Post)
def pre_delete_post_signal(sender, **kwargs):
post = kwargs['instance']
comments = Comment.objects.filter(post=post.id).delete()

View File

@ -16,7 +16,7 @@
<dyn:replace div_name="a" href="javascript:void(0);" onClick="javascript:display('response_dyn:comment_index');">Répondre</dyn:replace><br/>
<dyn:replace div_name="form" id="response_dyn:comment_index" class="response" method="POST" action="/comment/add/dyn:post_id/dyn:comment_id" onsubmit="return validateComment('response_dyn:comment_index');">
Auteur :<br/><input type="text" name="author"/><br/><br/>
e-mail* :<br/><input type="text" name="email"/><input type="text" name="mel"/><br/><br/>
e-mail* :<br/><input id="email" type="text" name="email"/><input type="text" name="mel"/><br/><br/>
Le commentaire :<br/><textarea name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
<input type="submit" value="Commenter"/>
</dyn:replace>

View File

@ -181,7 +181,7 @@ def category(request, blog_id):
@login_required
def add_category(request, blog_id):
b,_ = have_I_right(request, blog_id)
if request.method == 'POST':
if 'add' in request.POST:
form = CategoryForm(request.POST)
@ -302,7 +302,7 @@ def blog(request):
def add_blog(request):
if not request.user.is_superuser:
return HttpResponseRedirect('/blog')
if request.method == 'POST':
if 'add' in request.POST:
form = BlogForm(request.POST)
@ -452,9 +452,9 @@ def edit_post(request, post_id):
comment_list.append(comment)
return render(request, 'edit_post.html', {
'form': form, 'post_id' : post_id, 'content' : content,
'blog_id' : blog_id, 'comments' : comment_list
})
'form': form, 'post_id' : post_id, 'content' : content,
'blog_id' : blog_id, 'comments' : comment_list
})
@login_required
def delete_post(request, post_id):
@ -528,7 +528,7 @@ def search(request, blog_id):
text = request.POST['text']
else:
return HttpResponseRedirect(ref)
s = Search()
post_list = s.search(b, text)
@ -552,8 +552,8 @@ def preview(request, blog_id):
(b, p) = have_I_right(request, blog_id)
values = {'title' : request.POST['title'], \
'author' : request.user.first_name + ' ' + request.user.last_name, \
'content' : request.POST['content']
'author' : request.user.first_name + ' ' + request.user.last_name, \
'content' : request.POST['content']
}
engine = globals()['post']
@ -577,7 +577,7 @@ def preview(request, blog_id):
c = {'content' : content}
return HttpResponseRedirect('http://' + b.name + '/preview.html')
# return HttpResponseRedirect('http://' + 'localhost:8080' + '/preview.html')
# return HttpResponseRedirect('http://' + 'localhost:8080' + '/preview.html')
def _tinymcelist(request, b, year, month):
ret = 'var tinyMCEImageList = new Array('
@ -683,10 +683,12 @@ def add_comment(request, post_id, parent_id):
engine = globals()['post']
post_list = [post]
hash_post = {}
hash_post_content = {}
for name, obj in inspect.getmembers(engine):
if inspect.isclass(obj) and obj.__module__.startswith("dynastie.generators") \
and obj.__module__.endswith("post"):
e = obj()
e = obj(hash_post, hash_post_content)
content = e._generate(blog, blog.src_path, blog.output_path, post_list)
break