hello: new URI-scheme plugin + comment age threshold patch
Jon Dowland <[email protected]> Sun, 27 Jan 2008 13:15:00 +0000
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
Hello all, I am looking at moving my old, blosxom-based static weblog over to pyblosxom. One thing I want from pyblosxom is comments support, so I'm currently looking at that. I also want permalinks for my posts but I'm not too attached to the categories, so I've written a plugin which lets me have date-based permalinks (/YYYY/MM/DD/post-name). The current state of this is attached. I'm thinking about comments support now and one thing I want is to stop comments on old posts. I've made a first stab at patching comments.py as supplied in contrib-1.3.3 to support an age threshold option (also attached). Oh, in terms of versions, I'm using 1.3.2 at the moment since the contrib-1.3.3 contains comments.py (and the one linked to from pyblosxom.sf.net, hosted on Ted Leung's space, doesn't seem to work with 1.3 at all). I'm going to look at 1.4. too. I've just imported everything into a local git repository so it shouldn't be too hard for me to see if/how things break moving to 1.4. Comments/suggestions on my plugin and patch are most welcome. They are fairly rough :-) -- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ pyblosxom-users mailing list pyblosxom-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
comments_add_date_threshold.patch
(text/x-diff, 1.8 KB)
diff --git a/plugins/comments.py b/plugins/comments.py
index 4a1cc48..827b1ff 100644
--- a/plugins/comments.py
+++ b/plugins/comments.py
@@ -195,7 +195,7 @@ __url__ = "http://pyblosxom.sourceforge.net/"
__description__ = "Allows for comments on each blog entry."
import cgi, glob, os.path, re, time, cPickle, os, codecs, sys, popen2, \
- traceback, types
+ traceback, types, datetime
from email.MIMEText import MIMEText
from xml.sax.saxutils import escape
from Pyblosxom import tools
@@ -236,7 +236,8 @@ def verify_installation(request):
print("Missing comment SMTP property: '%s'" % i)
retval = 0
- optional_keys = ['comment_dir', 'comment_ext', 'comment_draft_ext']
+ optional_keys = ['comment_dir', 'comment_ext', 'comment_draft_ext',
+ 'comment_max_age']
for i in optional_keys:
if not config.has_key(i):
print("missing optional property: '%s'" % i)
@@ -726,6 +727,19 @@ def cb_prepare(args):
data["bl_type_file"] = "yes"
data['display_comment_default'] = 1
+ # check to see if the post is too old
+ # TODO: validate age? or in the validate section
+ log = tools.getLogger()
+ if config.has_key("comment_max_age") and data["bl_type"] == "file":
+ age = config["comment_max_age"]
+ thresh = datetime.date.today() - datetime.timedelta(days=age)
+ log.debug("comments: posting threshhold is %s"% str(thresh))
+ y,m,d = data['filestat_cache'].values()[0][0:3]
+ posttime = datetime.date(y,m,d)
+ log.debug("comments: post time is %s"% str(posttime))
+ if posttime <= thresh:
+ data['display_comment_default'] = 0
+
# second, we check to see if they're posting a comment and we
# need to write the comment to disk.
posting = ((form.has_key('ajax') and form['ajax'].value == 'post') or
date_permalinks.py
(text/x-python, 1.9 KB)
import re from Pyblosxom import tools from Pyblosxom.entries.fileentry import FileEntry from os.path import basename, splitext """ date-based permalinks support /YYYY/MM/DD/post-id as a URL scheme. We filter posts on the name criteria first, and then on the date criteria. It is possible that more than one post will match the criteria; this is just passed on, although data structures are adjusted so other plugins (e.g. the comments plugin) think this is just one post and annotate it accordingly. (Perhaps I should only let the first match through) """ __author__ = "Jon Dowland <[email protected]>" __version__ = "117695c0cc24b6e9694fb86a39b95054f50abb6c" __url__ = "http://alcopop.org/code/pyblosxom/" __description__ = "support /YYYY/MM/DD/post-id URLs" def cb_filelist(args): request = args['request'] data = request.getData() config = request.getConfiguration() # TODO :bug: /2008/01/25/ works, /2008/Jan/25 doesn't md = re.match(r'/\d\d\d\d/\d\d/\d\d/([^/]+)/?', data['pi_bl']) if md: postid = md.group(1) filelist = tools.Walk(request, config['datadir'], int(config['depth'])) # filter out those that don't match the post-id filelist = [x for x in filelist if postid == splitext(basename(x))[0]] entrylist = [] for ourfile in filelist: e = FileEntry(request, ourfile, config['datadir']) entrylist.append((e._mtime, e)) # filter out those that don't match the yyyy/mm/dd month = (data['pi_mo'] in tools.month2num.keys() and tools.month2num[data['pi_mo']] or data['pi_mo']) matchstr = "^" + data["pi_yr"] + month + data["pi_da"] entrylist = [x for x in entrylist if re.match(matchstr, x[1]._fulltime)] entrylist = [x[1] for x in entrylist] return entrylist return def verify_installation(request): return 1