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@3 | 13 | def get_queued_changes_page(request): |
paul@3 | 14 | return getattr(request.cfg, "queued_changes_page", "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@3 | 19 | def is_queued_changes_page(request, pagename): |
paul@1 | 20 | |
paul@3 | 21 | "Return whether 'pagename' is a queued changes page by testing its name." |
paul@1 | 22 | |
paul@1 | 23 | parts = pagename.split("/") |
paul@3 | 24 | return len(parts) > 1 and parts[-1] == get_queued_changes_page(request) |
paul@1 | 25 | |
paul@1 | 26 | def get_target_page_name(pagename): |
paul@1 | 27 | |
paul@3 | 28 | "Return the target page name for the given queued changes 'pagename'." |
paul@1 | 29 | |
paul@3 | 30 | return "/".join(pagename.split("/")[:-1]) |
paul@1 | 31 | |
paul@1 | 32 | # Utility classes and associated functions. |
paul@1 | 33 | # NOTE: These are a subset of EventAggregatorSupport. |
paul@1 | 34 | |
paul@1 | 35 | class Form: |
paul@1 | 36 | |
paul@1 | 37 | """ |
paul@1 | 38 | A wrapper preserving MoinMoin 1.8.x (and earlier) behaviour in a 1.9.x |
paul@1 | 39 | environment. |
paul@1 | 40 | """ |
paul@1 | 41 | |
paul@1 | 42 | def __init__(self, form): |
paul@1 | 43 | self.form = form |
paul@1 | 44 | |
paul@1 | 45 | def get(self, name, default=None): |
paul@1 | 46 | values = self.form.getlist(name) |
paul@1 | 47 | if not values: |
paul@1 | 48 | return default |
paul@1 | 49 | else: |
paul@1 | 50 | return values |
paul@1 | 51 | |
paul@1 | 52 | def __getitem__(self, name): |
paul@1 | 53 | return self.form.getlist(name) |
paul@1 | 54 | |
paul@1 | 55 | class ActionSupport: |
paul@1 | 56 | |
paul@1 | 57 | """ |
paul@1 | 58 | Work around disruptive MoinMoin changes in 1.9, and also provide useful |
paul@1 | 59 | convenience methods. |
paul@1 | 60 | """ |
paul@1 | 61 | |
paul@1 | 62 | def get_form(self): |
paul@1 | 63 | return get_form(self.request) |
paul@1 | 64 | |
paul@1 | 65 | def get_form(request): |
paul@1 | 66 | |
paul@1 | 67 | "Work around disruptive MoinMoin changes in 1.9." |
paul@1 | 68 | |
paul@1 | 69 | if hasattr(request, "values"): |
paul@1 | 70 | return Form(request.values) |
paul@1 | 71 | else: |
paul@1 | 72 | return request.form |
paul@1 | 73 | |
paul@1 | 74 | # vim: tabstop=4 expandtab shiftwidth=4 |