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
2.1 --- a/actions/EventAggregatorSummary.py Thu Mar 26 01:46:07 2009 +0100
2.2 +++ b/actions/EventAggregatorSummary.py Fri Mar 27 01:00:15 2009 +0100
2.3 @@ -4,37 +4,118 @@
2.4
2.5 @copyright: 2008, 2009 by Paul Boddie <paul@boddie.org.uk>
2.6 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
2.7 - 2005-2008 MoinMoin:ThomasWaldmann.
2.8 + 2005-2008 MoinMoin:ThomasWaldmann,
2.9 + 2007 MoinMoin:ReimarBauer.
2.10 @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.11 """
2.12
2.13 +from MoinMoin.action import ActionBase
2.14 from MoinMoin import config
2.15 import EventAggregatorSupport
2.16
2.17 Dependencies = ['pages']
2.18
2.19 -# Action function.
2.20 +# Action class and supporting functions.
2.21 +
2.22 +class EventAggregatorSummary(ActionBase):
2.23 +
2.24 + "A summary dialogue requesting various parameters."
2.25 +
2.26 + def get_form_html(self, buttons_html):
2.27 + _ = self._
2.28 + request = self.request
2.29 +
2.30 + category_list = []
2.31 +
2.32 + for category_name, category_pagename in \
2.33 + EventAggregatorSupport.getCategoryMapping(
2.34 + EventAggregatorSupport.getCategories(request),
2.35 + request):
2.36 +
2.37 + category_list.append('<option value="%s">%s</option>' % (category_pagename, category_name))
2.38 +
2.39 + d = {
2.40 + "buttons_html" : buttons_html,
2.41 + "category_label" : _("Categories"),
2.42 + "category_list" : "\n".join(category_list),
2.43 + "start_label" : _("Start year and month"),
2.44 + "start_default" : "",
2.45 + "end_label" : _("End year and month"),
2.46 + "end_default" : "",
2.47 + }
2.48
2.49 -def execute(pagename, request):
2.50 + return '''
2.51 +<table>
2.52 + <tr>
2.53 + <td class="label"><label>%(category_label)s</label></td>
2.54 + <td class="content">
2.55 + <select multiple="multiple" name="category">
2.56 + %(category_list)s
2.57 + </select>
2.58 + </td>
2.59 + </tr>
2.60 + <tr>
2.61 + <td class="label"><label>%(start_label)s</label></td>
2.62 + <td class="content">
2.63 + <input name="start" type="text" value="%(start_default)s" size="12" />
2.64 + </td>
2.65 + </tr>
2.66 + <tr>
2.67 + <td class="label"><label>%(end_label)s</label></td>
2.68 + <td class="content">
2.69 + <input name="end" type="text" value="%(end_default)s" size="12" />
2.70 + </td>
2.71 + </tr>
2.72 + <tr>
2.73 + <td></td>
2.74 + <td class="buttons">
2.75 + %(buttons_html)s
2.76 + </td>
2.77 + </tr>
2.78 +</table>
2.79 +''' % d
2.80 +
2.81 + def do_action(self):
2.82 +
2.83 + "Write the iCalendar resource."
2.84 +
2.85 + _ = self._
2.86 +
2.87 + # If no category names exist in the request, an error message is
2.88 + # returned.
2.89 +
2.90 + category_names = self.request.form.get("category", [])
2.91 +
2.92 + if not category_names:
2.93 + return 0, _("No categories specified.")
2.94 +
2.95 + write_resource(self.request)
2.96 + return 1, None
2.97 +
2.98 + def render_success(self, msg, msgtype):
2.99 +
2.100 + """
2.101 + Render neither 'msg' nor 'msgtype' since a resource has already been
2.102 + produced.
2.103 + """
2.104 +
2.105 + pass
2.106 +
2.107 +def write_resource(request):
2.108
2.109 """
2.110 - For the given 'pagename' and 'request', write an iCalendar summary of the
2.111 - event data found in the categories specified via the "category" request
2.112 - parameter, using the "start" and "end" parameters (if specified). Multiple
2.113 - "category" parameters can be specified.
2.114 + For the given 'request', write an iCalendar summary of the event data found
2.115 + in the categories specified via the "category" request parameter, using the
2.116 + "start" and "end" parameters (if specified). Multiple "category" parameters
2.117 + can be specified.
2.118 """
2.119
2.120 category_names = request.form.get("category", [])
2.121
2.122 - if request.form.has_key("start"):
2.123 - calendar_start = EventAggregatorSupport.getMonth(request.form["start"][0])
2.124 - else:
2.125 - calendar_start = None
2.126 + # Otherwise, produce an iCalendar resource.
2.127
2.128 - if request.form.has_key("end"):
2.129 - calendar_end = EventAggregatorSupport.getMonth(request.form["end"][0])
2.130 - else:
2.131 - calendar_end = None
2.132 + calendar_start = EventAggregatorSupport.getFormMonth(request, None, "start")
2.133 + calendar_end = EventAggregatorSupport.getFormMonth(request, None, "end")
2.134
2.135 events, shown_events, all_shown_events, earliest, latest = \
2.136 EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end)
2.137 @@ -49,14 +130,12 @@
2.138
2.139 for event_page, event_details in all_shown_events:
2.140
2.141 - # Get a pretty version of the page name.
2.142 -
2.143 - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page)
2.144 + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details)
2.145
2.146 # Output the event details.
2.147
2.148 request.write("BEGIN:VEVENT\r\n")
2.149 - request.write("SUMMARY:%s\r\n" % pretty_pagename)
2.150 + request.write("SUMMARY:%s\r\n" % event_summary)
2.151 request.write("UID:%s\r\n" % request.getQualifiedURL(event_page.url(request)))
2.152 request.write("URL:%s\r\n" % request.getQualifiedURL(event_page.url(request)))
2.153 request.write("DTSTART;VALUE=DATE:%04d%02d%02d\r\n" % event_details["start"])
2.154 @@ -67,4 +146,9 @@
2.155
2.156 request.write("END:VCALENDAR\r\n")
2.157
2.158 +# Action function.
2.159 +
2.160 +def execute(pagename, request):
2.161 + EventAggregatorSummary(pagename, request).render()
2.162 +
2.163 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/macros/EventAggregator.py Thu Mar 26 01:46:07 2009 +0100
3.2 +++ b/macros/EventAggregator.py Fri Mar 27 01:00:15 2009 +0100
3.3 @@ -44,39 +44,6 @@
3.4
3.5 # Macro functions.
3.6
3.7 -def getMonth(arg):
3.8 - n = None
3.9 -
3.10 - if arg.startswith("current"):
3.11 - date = EventAggregatorSupport.getCurrentMonth()
3.12 - if len(arg) > 8:
3.13 - n = int(arg[7:])
3.14 -
3.15 - elif arg.startswith("yearstart"):
3.16 - date = (EventAggregatorSupport.getCurrentYear(), 1)
3.17 - if len(arg) > 10:
3.18 - n = int(arg[9:])
3.19 -
3.20 - elif arg.startswith("yearend"):
3.21 - date = (EventAggregatorSupport.getCurrentYear(), 12)
3.22 - if len(arg) > 8:
3.23 - n = int(arg[7:])
3.24 -
3.25 - else:
3.26 - date = EventAggregatorSupport.getMonth(arg)
3.27 -
3.28 - if n is not None:
3.29 - date = EventAggregatorSupport.monthupdate(date, n)
3.30 -
3.31 - return date
3.32 -
3.33 -def getFormMonth(request, calendar_name, argname):
3.34 - arg = request.form.get("%s-%s" % (calendar_name, argname), [None])[0]
3.35 - if arg is not None:
3.36 - return getMonth(arg)
3.37 - else:
3.38 - return None
3.39 -
3.40 def execute(macro, args):
3.41
3.42 """
3.43 @@ -125,10 +92,10 @@
3.44
3.45 for arg in parsed_args:
3.46 if arg.startswith("start="):
3.47 - calendar_start = getMonth(arg[6:])
3.48 + calendar_start = EventAggregatorSupport.getParameterMonth(arg[6:])
3.49
3.50 elif arg.startswith("end="):
3.51 - calendar_end = getMonth(arg[4:])
3.52 + calendar_end = EventAggregatorSupport.getParameterMonth(arg[4:])
3.53
3.54 elif arg.startswith("mode="):
3.55 mode = arg[5:]
3.56 @@ -145,8 +112,8 @@
3.57 # Find request parameters to override settings.
3.58
3.59 if calendar_name is not None:
3.60 - calendar_start = getFormMonth(request, calendar_name, "start") or calendar_start
3.61 - calendar_end = getFormMonth(request, calendar_name, "end") or calendar_end
3.62 + calendar_start = EventAggregatorSupport.getFormMonth(request, calendar_name, "start") or calendar_start
3.63 + calendar_end = EventAggregatorSupport.getFormMonth(request, calendar_name, "end") or calendar_end
3.64
3.65 # Get the events.
3.66
3.67 @@ -383,9 +350,7 @@
3.68 if not (event_details["start"] <= date <= event_details["end"]):
3.69 continue
3.70
3.71 - # Get a pretty version of the page name.
3.72 -
3.73 - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page)
3.74 + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details)
3.75
3.76 # Generate a colour for the event.
3.77
3.78 @@ -414,10 +379,10 @@
3.79
3.80 if not hide_text:
3.81 output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=style))
3.82 - output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename)))
3.83 + output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary)))
3.84 else:
3.85 output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=hidden_style))
3.86 - output.append(fmt.text(pretty_pagename))
3.87 + output.append(fmt.text(event_summary))
3.88
3.89 output.append(fmt.div(on=0))
3.90
3.91 @@ -456,15 +421,13 @@
3.92
3.93 for event_page, event_details in shown_events.get((year, month), []):
3.94
3.95 - # Get a pretty version of the page name.
3.96 -
3.97 - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page)
3.98 + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details)
3.99
3.100 output.append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
3.101
3.102 - # Link to the page using the pretty name.
3.103 + # Link to the page using the summary.
3.104
3.105 - output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename)))
3.106 + output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary)))
3.107
3.108 # Add the event details.
3.109
4.1 --- a/pages/EventTemplate Thu Mar 26 01:46:07 2009 +0100
4.2 +++ b/pages/EventTemplate Fri Mar 27 01:00:15 2009 +0100
4.3 @@ -1,6 +1,11 @@
4.4 Start:: YYYY-MM-DD
4.5 End:: YYYY-MM-DD
4.6 Topics:: topics
4.7 +## Summary:: summary/title
4.8 +## To choose a title or summary different to the page name, or to
4.9 +## provide a specific form of the page name, uncomment the above entry
4.10 +## and write the appropriate title or summary, employing simple Wiki
4.11 +## syntax. For example: <<Verbatim(MoinMoin)>>
4.12
4.13 Description of event.
4.14 ----