16 May 16:53
Comments plugin and AJAXy posts
If you enable AJAX form submission for the comments plugin, hitting the
'Submit' button will return "Empty response from server".
This is caused by (oh dear) an unfortunate interaction of the pieces.
cb_renderer notices the AJAX submission and switches to AjaxRenderer.
Which tries to avoid filtering bits of the output to get only the
single comment. Unfortunately, since rendering cb_story is what *loads*
the comments, when we get to cb_story_end we have entry['comments'] is
None and thus no output.
I fixed it by patching cb_story_end and adding
if entry['num_comments'] is None:
# During AJAX rendering we skip cb_story which would load the
# comments, so do that here
entry['comments'] = readComments(entry, config)
entry['num_comments'] = len(entry['comments'])
just in front of
if entry['comments']:
This fix is sufficient if you don't have comment approval enabled. It
is not sufficient if comment_draft_ext != comment_ext. In the latter
case I looked at how comment preview was implemented and did the same
thing, by rendering a new comment-moderated template that says "Comment was
submitted for approval. Thanks!":
Index: plugins/comments.py
===================================================================
--- plugins/comments.py (revision 240)
+++ plugins/comments.py (revision 241)
@@ -785,6 +785,8 @@ def cb_prepare(args):
else:
data["comment_message"] = writeComment(request, config, data, \
cdict, encoding)
+ if config['comment_draft_ext'] != config['comment_ext']:
+ data["moderated"] = True
class AjaxRenderer(blosxom.Renderer):
""" The renderer used when responding to AJAX requests to preview and post
@@ -805,6 +807,8 @@ class AjaxRenderer(blosxom.Renderer):
elif (self._ajax_type == 'post' and template_name == 'comment' and
round(self._data.get('cmt_time', 0)) == round(entry['cmt_time'])):
return True
+ elif self._ajax_type == 'post' and template_name == 'comment-moderated':
+ return True
else:
return False
@@ -1011,6 +1015,9 @@ def cb_story_end(args):
rejected['cmt_description'] = msg
rejected['cmt_description_escaped'] = escape(msg)
renderer.outputTemplate(output, rejected, 'comment')
+ elif ('moderated' in data and 'comment-moderated' in renderer.flavour):
+ moderated = build_preview_comment(form, entry, config)
+ renderer.outputTemplate(output, moderated, 'comment-moderated')
renderer.outputTemplate(output, entry, 'comment-form')
args['template'] = template +u"".join(output)
This fix is slightly broken: it doesn't handle error reporting. I'd
like writeComment to return two bits of information instead of one: a
message and a success status, indicating whether the comment written
will now be included in entry['comments'] or not. That message should
be displayed with the comment-moderated template if and only if the
comment did not already appear in the list, to avoid displaying the
comment twice.
Marius Gedminas
--
--
An algorithm must be seen to be believed.
-- D.E. Knuth
------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects
_______________________________________________ Pyblosxom-devel mailing list Pyblosxom-devel@... https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
RSS Feed