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