disabling comments on an entry after x days
will <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
Jordi hopped on IRC and reminded me I promised to implement "disabling comments on an entry after x days". It's not quite good enough to just write a comment rejection plugin because you really want to disable the form, too. No sense in tantalizing readers with forbidden fruit. So I made some changes to the one that's in SVN. Given I don't do much plugin hacking these days, I thought I would run the diff by people for peer review before I check it in. It's attached. It's had a meager amount of testing with PyBlosxom 1.4. Having said that, it's pretty trivial so I'm pretty confident it's safe. Comments are more than welcome. If I don't hear back from anyone and/or it looks ok, then I'll check it in unless someone beats me to it. /will ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Pyblosxom-devel mailing list Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
comments.py.diff
(text/x-diff, 2.8 KB)
Index: comments.py
===================================================================
--- comments.py (revision 1251)
+++ comments.py (working copy)
@@ -41,6 +41,9 @@
comment_nofollow - set this to 1 to add rel="nofollow" attributes to
links in the description -- these attributes are embedded
in the stored representation.
+ comment_disable_after_x_days - set this to a positive integer and users
+ won't be able to leave comments on entries older than
+ x days.
Comments are stored 1 per file in a parallel hierarchy to the datadir
hierarchy. The filename of the comment is the filename of the blog
@@ -576,6 +579,13 @@
tools.getLogger().error("error sending email: %s" %
traceback.format_exception(*sys.exc_info()))
+def check_comments_disabled(config, entry):
+ disabled_after_x_days = config.get("comment_disable_after_x_days", 0)
+ if disabled_after_x_days > 0:
+ if (time.time() - entry._mtime) / 60 / 60 / 24 > disabled_after_x_days:
+ return True
+ return False
+
def clean_author(s):
"""
Guard against blasterattacko style attacks that embedd SMTP commands in
@@ -728,10 +738,23 @@
# second, we check to see if they're posting a comment and we
# need to write the comment to disk.
posting = (('ajax' in form and form['ajax'].value == 'post') or
- not "preview" in form)
+ not "preview" in form)
+
if ("title" in form and "author" in form and
"body" in form and posting):
+ entry = data.get("entry_list", [])
+ if len(entry) == 0:
+ data["rejected"] = True
+ data["comment_message"] = "No such entry exists."
+ return
+ entry = entry[0]
+
+ if check_comments_disabled(config, entry):
+ data["rejected"] = True
+ data["comment_message"] = "Comments for that entry are disabled."
+ return
+
encoding = config.get('blog_encoding', 'iso-8859-1')
decode_form(form, encoding)
@@ -783,6 +806,7 @@
reject_code, reject_message = reject
else:
reject_code, reject_message = reject, "Comment rejected."
+
if reject_code == 1:
data["comment_message"] = reject_message
data["rejected"] = True
@@ -1011,7 +1035,8 @@
rejected['cmt_description'] = msg
rejected['cmt_description_escaped'] = escape(msg)
renderer.outputTemplate(output, rejected, 'comment')
- renderer.outputTemplate(output, entry, 'comment-form')
+ if not check_comments_disabled(config, entry):
+ renderer.outputTemplate(output, entry, 'comment-form')
args['template'] = template +u"".join(output)
setCommentCount(entry, config)