1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - ApproveChanges library 4 5 @copyright: 2011 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 import re 10 11 __version__ = "0.1" 12 13 def get_queued_changes_area(request): 14 return getattr(request.cfg, "queued_changes_area", "ApprovalQueue") 15 16 def get_approved_editors_group(request): 17 return getattr(request.cfg, "approved_editors_group", "ApprovedGroup") 18 19 def match_queue_pages(pagename, queued_changes_area): 20 21 "Return a filter function which matches subpages of 'pagename'." 22 23 return re.compile(ur"^%s/%s/.*$" % (re.escape(pagename), re.escape(queued_changes_area)), re.UNICODE).match 24 25 def get_queue_pages(request, pagename, queued_changes_area): 26 27 """ 28 Return the queued pages given the 'request', 'pagename' and subpage folder 29 specified by 'queued_changes_area'. 30 """ 31 32 return request.rootpage.getPageList(exists=1, filter=match_queue_pages(pagename, queued_changes_area)) 33 34 def is_queued_page(pagename, queued_changes_area): 35 36 """ 37 Return whether 'pagename' is a queued page by testing for the presence of 38 the 'queued_changes_area' component in its page path. 39 """ 40 41 parts = pagename.split("/") 42 return len(parts) > 2 and parts[-2] == queued_changes_area 43 44 def get_target_page_name(pagename): 45 46 "Return the target page name for the given queued 'pagename'." 47 48 return "/".join(pagename.split("/")[:-2]) 49 50 # Utility classes and associated functions. 51 # NOTE: These are a subset of EventAggregatorSupport. 52 53 class Form: 54 55 """ 56 A wrapper preserving MoinMoin 1.8.x (and earlier) behaviour in a 1.9.x 57 environment. 58 """ 59 60 def __init__(self, form): 61 self.form = form 62 63 def get(self, name, default=None): 64 values = self.form.getlist(name) 65 if not values: 66 return default 67 else: 68 return values 69 70 def __getitem__(self, name): 71 return self.form.getlist(name) 72 73 class ActionSupport: 74 75 """ 76 Work around disruptive MoinMoin changes in 1.9, and also provide useful 77 convenience methods. 78 """ 79 80 def get_form(self): 81 return get_form(self.request) 82 83 def get_form(request): 84 85 "Work around disruptive MoinMoin changes in 1.9." 86 87 if hasattr(request, "values"): 88 return Form(request.values) 89 else: 90 return request.form 91 92 # vim: tabstop=4 expandtab shiftwidth=4