1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ApproveChangesSupport.py Sun Oct 09 21:17:09 2011 +0200
1.3 @@ -0,0 +1,92 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - ApproveChanges library
1.7 +
1.8 + @copyright: 2011 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +import re
1.13 +
1.14 +__version__ = "0.1"
1.15 +
1.16 +def get_queued_changes_area(request):
1.17 + return getattr(request.cfg, "queued_changes_area", "ApprovalQueue")
1.18 +
1.19 +def get_approved_editors_group(request):
1.20 + return getattr(request.cfg, "approved_editors_group", "ApprovedGroup")
1.21 +
1.22 +def match_queue_pages(pagename, queued_changes_area):
1.23 +
1.24 + "Return a filter function which matches subpages of 'pagename'."
1.25 +
1.26 + return re.compile(ur"^%s/%s/.*$" % (re.escape(pagename), re.escape(queued_changes_area)), re.UNICODE).match
1.27 +
1.28 +def get_queue_pages(request, pagename, queued_changes_area):
1.29 +
1.30 + """
1.31 + Return the queued pages given the 'request', 'pagename' and subpage folder
1.32 + specified by 'queued_changes_area'.
1.33 + """
1.34 +
1.35 + return request.rootpage.getPageList(exists=1, filter=match_queue_pages(pagename, queued_changes_area))
1.36 +
1.37 +def is_queued_page(pagename, queued_changes_area):
1.38 +
1.39 + """
1.40 + Return whether 'pagename' is a queued page by testing for the presence of
1.41 + the 'queued_changes_area' component in its page path.
1.42 + """
1.43 +
1.44 + parts = pagename.split("/")
1.45 + return len(parts) > 2 and parts[-2] == queued_changes_area
1.46 +
1.47 +def get_target_page_name(pagename):
1.48 +
1.49 + "Return the target page name for the given queued 'pagename'."
1.50 +
1.51 + return "/".join(pagename.split("/")[:-2])
1.52 +
1.53 +# Utility classes and associated functions.
1.54 +# NOTE: These are a subset of EventAggregatorSupport.
1.55 +
1.56 +class Form:
1.57 +
1.58 + """
1.59 + A wrapper preserving MoinMoin 1.8.x (and earlier) behaviour in a 1.9.x
1.60 + environment.
1.61 + """
1.62 +
1.63 + def __init__(self, form):
1.64 + self.form = form
1.65 +
1.66 + def get(self, name, default=None):
1.67 + values = self.form.getlist(name)
1.68 + if not values:
1.69 + return default
1.70 + else:
1.71 + return values
1.72 +
1.73 + def __getitem__(self, name):
1.74 + return self.form.getlist(name)
1.75 +
1.76 +class ActionSupport:
1.77 +
1.78 + """
1.79 + Work around disruptive MoinMoin changes in 1.9, and also provide useful
1.80 + convenience methods.
1.81 + """
1.82 +
1.83 + def get_form(self):
1.84 + return get_form(self.request)
1.85 +
1.86 +def get_form(request):
1.87 +
1.88 + "Work around disruptive MoinMoin changes in 1.9."
1.89 +
1.90 + if hasattr(request, "values"):
1.91 + return Form(request.values)
1.92 + else:
1.93 + return request.form
1.94 +
1.95 +# vim: tabstop=4 expandtab shiftwidth=4