1.1 --- a/EventAggregatorSupport.py Thu Mar 26 01:46:07 2009 +0100
1.2 +++ b/EventAggregatorSupport.py Fri Mar 27 01:00:15 2009 +0100
1.3 @@ -22,6 +22,15 @@
1.4 definition_list_regexp = re.compile(ur'^\s+(?P<term>.*?)::\s(?P<desc>.*?)$', re.UNICODE | re.MULTILINE)
1.5 date_regexp = re.compile(ur'(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})', re.UNICODE)
1.6 month_regexp = re.compile(ur'(?P<year>[0-9]{4})-(?P<month>[0-9]{2})', re.UNICODE)
1.7 +verbatim_regexp = re.compile(ur'(?:'
1.8 + ur'<<Verbatim\((?P<verbatim>.*?)\)>>'
1.9 + ur'|'
1.10 + ur'\[\[Verbatim\((?P<verbatim2>.*?)\)\]\]'
1.11 + ur'|'
1.12 + ur'`(?P<monospace>.*?)`'
1.13 + ur'|'
1.14 + ur'{{{(?P<preformatted>.*?)}}}'
1.15 + ur')', re.UNICODE)
1.16
1.17 # Utility functions.
1.18
1.19 @@ -41,6 +50,36 @@
1.20 category_regexp = re.compile(u'^%s$' % ur'(?P<all>Category(?P<key>(?!Template)\S+))', re.UNICODE)
1.21 return category_regexp
1.22
1.23 +# Action support functions.
1.24 +
1.25 +def getCategories(request):
1.26 +
1.27 + """
1.28 + From the AdvancedSearch macro, return a list of category page names using
1.29 + the given 'request'.
1.30 + """
1.31 +
1.32 + # This will return all pages with "Category" in the title.
1.33 +
1.34 + cat_filter = getCategoryPattern(request).search
1.35 + return request.rootpage.getPageList(filter=cat_filter)
1.36 +
1.37 +def getCategoryMapping(category_pagenames, request):
1.38 +
1.39 + """
1.40 + For the given 'category_pagenames' return a list of tuples of the form
1.41 + (category name, category page name) using the given 'request'.
1.42 + """
1.43 +
1.44 + cat_pattern = getCategoryPattern(request)
1.45 + mapping = []
1.46 + for pagename in category_pagenames:
1.47 + name = cat_pattern.match(pagename).group("key")
1.48 + if name != "Category":
1.49 + mapping.append((name, pagename))
1.50 + mapping.sort()
1.51 + return mapping
1.52 +
1.53 # The main activity functions.
1.54
1.55 def getPages(pagename, request):
1.56 @@ -61,12 +100,6 @@
1.57 pages.append(page)
1.58 return pages
1.59
1.60 -def getPrettyPageName(page):
1.61 -
1.62 - "Return a nicely formatted title/name for the given 'page'."
1.63 -
1.64 - return page.split_title(force=1).replace("_", " ").replace("/", u" » ")
1.65 -
1.66 def getEventDetails(page):
1.67
1.68 "Return a dictionary of event details from the given 'page'."
1.69 @@ -83,16 +116,43 @@
1.70
1.71 # Special value type handling.
1.72
1.73 + # Dates.
1.74 +
1.75 if term in ("start", "end"):
1.76 desc = getDate(desc)
1.77 +
1.78 + # Lists.
1.79 +
1.80 elif term in ("topics",):
1.81 desc = [value.strip() for value in desc.split(",")]
1.82
1.83 + # Labels which may well be quoted.
1.84 + # NOTE: Re-implementing support for verbatim text and linking
1.85 + # NOTE: avoidance.
1.86 +
1.87 + elif term in ("title", "summary"):
1.88 + desc = "".join([s for s in verbatim_regexp.split(desc) if s is not None])
1.89 +
1.90 if desc is not None:
1.91 event_details[term] = desc
1.92
1.93 return event_details
1.94
1.95 +def getEventSummary(event_page, event_details):
1.96 +
1.97 + """
1.98 + Return either the given title or summary of the event described by the given
1.99 + 'event_page', according to the given 'event_details', or return the pretty
1.100 + version of the page name.
1.101 + """
1.102 +
1.103 + if event_details.has_key("title"):
1.104 + return event_details["title"]
1.105 + elif event_details.has_key("summary"):
1.106 + return event_details["summary"]
1.107 + else:
1.108 + return getPrettyPageName(event_page)
1.109 +
1.110 def getDate(s):
1.111
1.112 "Parse the string 's', extracting and returning a date string."
1.113 @@ -417,4 +477,50 @@
1.114
1.115 return full_coverage, all_events
1.116
1.117 +# User interface functions.
1.118 +
1.119 +def getParameterMonth(arg):
1.120 + n = None
1.121 +
1.122 + if arg.startswith("current"):
1.123 + date = getCurrentMonth()
1.124 + if len(arg) > 8:
1.125 + n = int(arg[7:])
1.126 +
1.127 + elif arg.startswith("yearstart"):
1.128 + date = (getCurrentYear(), 1)
1.129 + if len(arg) > 10:
1.130 + n = int(arg[9:])
1.131 +
1.132 + elif arg.startswith("yearend"):
1.133 + date = (getCurrentYear(), 12)
1.134 + if len(arg) > 8:
1.135 + n = int(arg[7:])
1.136 +
1.137 + else:
1.138 + date = getMonth(arg)
1.139 +
1.140 + if n is not None:
1.141 + date = monthupdate(date, n)
1.142 +
1.143 + return date
1.144 +
1.145 +def getFormMonth(request, calendar_name, argname):
1.146 + if calendar_name is None:
1.147 + calendar_prefix = argname
1.148 + else:
1.149 + calendar_prefix = "%s-%s" % (calendar_name, argname)
1.150 +
1.151 + arg = request.form.get(calendar_prefix, [None])[0]
1.152 + if arg is not None:
1.153 + return getParameterMonth(arg)
1.154 + else:
1.155 + return None
1.156 +
1.157 +def getPrettyPageName(page):
1.158 +
1.159 + "Return a nicely formatted title/name for the given 'page'."
1.160 +
1.161 + return page.split_title(force=1).replace("_", " ").replace("/", u" » ")
1.162 +
1.163 # vim: tabstop=4 expandtab shiftwidth=4