You asked for it, you got it (comment previews)
Bill Mill <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
Comment previews!
I never worked on the comment module before, so it's probably not
perfect. Will, since I think you wrote it, would you mind critiquing
it? It seems to work for me, but it's totally untested.
I updated the readme in the comments plugin directory with directions
on how to install it; they're included below. When I did "cvs diff
readme", it said "cvs diff: I know nothing about readme"; if somebody
could help me with that I'd appreciate it.
Anyway, the section of instructions about the preview are below, and
the included patch needs to go on
contrib/plugins/comments/plugins/comments.py (what a silly directory
structure). I would appreciate critiques on both the code and the
documentation.
If you would like comment previews, you need to do 2 things.
1) Add a preview button to comment-form.html like this:
<input name="preview" type="submit" value="Preview" />
You may change the contents of the value attribute, but the name of
the input must be "preview".
2) Still in your comment-form.html template, you need to use the comment
values to fill in the values of your input fields like so:
<input name="author" type="text" value="$cmt_author">
<input name="email" type="text" value="$cmt_email">
<input name="url" type="text" value="$cmt_link">
<textarea name="body">$cmt_description</textarea>
If there is no preview available, these variables will be stripped
from the text and cause no problem.
3) Copy comment.html to a template called comment-preview.html. All of
the available variables from the comment template are available for
this template.
Peace
Bill Mill
bill.mill at gmail.com
comments.diff
(application/octet-stream, 1.5 KB)
Index: comments.py
===================================================================
RCS file: /cvsroot/pyblosxom/pyblosxom/contrib/plugins/comments/plugins/comments.py,v
retrieving revision 1.39
diff -r1.39 comments.py
399c399,400
< if form.has_key("title") and form.has_key("author") and form.has_key("body"):
---
> if form.has_key("title") and form.has_key("author") and \
> form.has_key("body") and not form.has_key("preview"):
451a453,471
> def build_preview_comment(form, entry):
> #generates a preview comment by brute force and adds it to the entry
> #so it can be used to refill the form
> c = {}
> try:
> c['cmt_time'] = str(time.time())
> c['cmt_author'] = form['author'].value
> c['cmt_title'] = form['title'].value
> c['cmt_link'] = form['url'].value
> c['cmt_item'] = sanitize(form['body'].value)
> c['cmt_pubDate'] = time.ctime(time.time())
> c['cmt_description'] = sanitize(form['body'].value)
> except KeyError, e:
> c['cmt_description'] = 'Missing value: %s' % e
> if form.has_key('email'):
> c['cmt_email'] = form['email'].value
> for key in c: entry[key] = c[key]
> return c
>
456a477
> form = request.getHttp()['form']
465a487,490
> if form.has_key('preview')\
> and renderer.flavour.has_key('comment-preview'):
> com = build_preview_comment(form, entry)
> renderer.outputTemplate(output, com, 'comment-preview')