# HG changeset patch # User Paul Boddie # Date 1238112015 -3600 # Node ID a7c274e2932c423453c5eb28b14b322fd8ba6297 # Parent 83350447c60655f9e18bf4ba1fbdcf901d978f3c Added title/summary support for events so that the automatic, pretty page name can be overridden. Moved parameter retrieval functions to the support module. Added category retrieval functions (from CategoryMenu) to the support module. Made the action an ActionBase subclass, providing a form to enter parameter values. diff -r 83350447c606 -r a7c274e2932c EventAggregatorSupport.py --- a/EventAggregatorSupport.py Thu Mar 26 01:46:07 2009 +0100 +++ b/EventAggregatorSupport.py Fri Mar 27 01:00:15 2009 +0100 @@ -22,6 +22,15 @@ definition_list_regexp = re.compile(ur'^\s+(?P.*?)::\s(?P.*?)$', re.UNICODE | re.MULTILINE) date_regexp = re.compile(ur'(?P[0-9]{4})-(?P[0-9]{2})-(?P[0-9]{2})', re.UNICODE) month_regexp = re.compile(ur'(?P[0-9]{4})-(?P[0-9]{2})', re.UNICODE) +verbatim_regexp = re.compile(ur'(?:' + ur'<.*?)\)>>' + ur'|' + ur'\[\[Verbatim\((?P.*?)\)\]\]' + ur'|' + ur'`(?P.*?)`' + ur'|' + ur'{{{(?P.*?)}}}' + ur')', re.UNICODE) # Utility functions. @@ -41,6 +50,36 @@ category_regexp = re.compile(u'^%s$' % ur'(?PCategory(?P(?!Template)\S+))', re.UNICODE) return category_regexp +# Action support functions. + +def getCategories(request): + + """ + From the AdvancedSearch macro, return a list of category page names using + the given 'request'. + """ + + # This will return all pages with "Category" in the title. + + cat_filter = getCategoryPattern(request).search + return request.rootpage.getPageList(filter=cat_filter) + +def getCategoryMapping(category_pagenames, request): + + """ + For the given 'category_pagenames' return a list of tuples of the form + (category name, category page name) using the given 'request'. + """ + + cat_pattern = getCategoryPattern(request) + mapping = [] + for pagename in category_pagenames: + name = cat_pattern.match(pagename).group("key") + if name != "Category": + mapping.append((name, pagename)) + mapping.sort() + return mapping + # The main activity functions. def getPages(pagename, request): @@ -61,12 +100,6 @@ pages.append(page) return pages -def getPrettyPageName(page): - - "Return a nicely formatted title/name for the given 'page'." - - return page.split_title(force=1).replace("_", " ").replace("/", u" » ") - def getEventDetails(page): "Return a dictionary of event details from the given 'page'." @@ -83,16 +116,43 @@ # Special value type handling. + # Dates. + if term in ("start", "end"): desc = getDate(desc) + + # Lists. + elif term in ("topics",): desc = [value.strip() for value in desc.split(",")] + # Labels which may well be quoted. + # NOTE: Re-implementing support for verbatim text and linking + # NOTE: avoidance. + + elif term in ("title", "summary"): + desc = "".join([s for s in verbatim_regexp.split(desc) if s is not None]) + if desc is not None: event_details[term] = desc return event_details +def getEventSummary(event_page, event_details): + + """ + Return either the given title or summary of the event described by the given + 'event_page', according to the given 'event_details', or return the pretty + version of the page name. + """ + + if event_details.has_key("title"): + return event_details["title"] + elif event_details.has_key("summary"): + return event_details["summary"] + else: + return getPrettyPageName(event_page) + def getDate(s): "Parse the string 's', extracting and returning a date string." @@ -417,4 +477,50 @@ return full_coverage, all_events +# User interface functions. + +def getParameterMonth(arg): + n = None + + if arg.startswith("current"): + date = getCurrentMonth() + if len(arg) > 8: + n = int(arg[7:]) + + elif arg.startswith("yearstart"): + date = (getCurrentYear(), 1) + if len(arg) > 10: + n = int(arg[9:]) + + elif arg.startswith("yearend"): + date = (getCurrentYear(), 12) + if len(arg) > 8: + n = int(arg[7:]) + + else: + date = getMonth(arg) + + if n is not None: + date = monthupdate(date, n) + + return date + +def getFormMonth(request, calendar_name, argname): + if calendar_name is None: + calendar_prefix = argname + else: + calendar_prefix = "%s-%s" % (calendar_name, argname) + + arg = request.form.get(calendar_prefix, [None])[0] + if arg is not None: + return getParameterMonth(arg) + else: + return None + +def getPrettyPageName(page): + + "Return a nicely formatted title/name for the given 'page'." + + return page.split_title(force=1).replace("_", " ").replace("/", u" » ") + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 83350447c606 -r a7c274e2932c actions/EventAggregatorSummary.py --- a/actions/EventAggregatorSummary.py Thu Mar 26 01:46:07 2009 +0100 +++ b/actions/EventAggregatorSummary.py Fri Mar 27 01:00:15 2009 +0100 @@ -4,37 +4,118 @@ @copyright: 2008, 2009 by Paul Boddie @copyright: 2000-2004 Juergen Hermann , - 2005-2008 MoinMoin:ThomasWaldmann. + 2005-2008 MoinMoin:ThomasWaldmann, + 2007 MoinMoin:ReimarBauer. @license: GNU GPL (v2 or later), see COPYING.txt for details. """ +from MoinMoin.action import ActionBase from MoinMoin import config import EventAggregatorSupport Dependencies = ['pages'] -# Action function. +# Action class and supporting functions. + +class EventAggregatorSummary(ActionBase): + + "A summary dialogue requesting various parameters." + + def get_form_html(self, buttons_html): + _ = self._ + request = self.request + + category_list = [] + + for category_name, category_pagename in \ + EventAggregatorSupport.getCategoryMapping( + EventAggregatorSupport.getCategories(request), + request): + + category_list.append('' % (category_pagename, category_name)) + + d = { + "buttons_html" : buttons_html, + "category_label" : _("Categories"), + "category_list" : "\n".join(category_list), + "start_label" : _("Start year and month"), + "start_default" : "", + "end_label" : _("End year and month"), + "end_default" : "", + } -def execute(pagename, request): + return ''' + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ %(buttons_html)s +
+''' % d + + def do_action(self): + + "Write the iCalendar resource." + + _ = self._ + + # If no category names exist in the request, an error message is + # returned. + + category_names = self.request.form.get("category", []) + + if not category_names: + return 0, _("No categories specified.") + + write_resource(self.request) + return 1, None + + def render_success(self, msg, msgtype): + + """ + Render neither 'msg' nor 'msgtype' since a resource has already been + produced. + """ + + pass + +def write_resource(request): """ - For the given 'pagename' and 'request', write an iCalendar summary of the - event data found in the categories specified via the "category" request - parameter, using the "start" and "end" parameters (if specified). Multiple - "category" parameters can be specified. + For the given 'request', write an iCalendar summary of the event data found + in the categories specified via the "category" request parameter, using the + "start" and "end" parameters (if specified). Multiple "category" parameters + can be specified. """ category_names = request.form.get("category", []) - if request.form.has_key("start"): - calendar_start = EventAggregatorSupport.getMonth(request.form["start"][0]) - else: - calendar_start = None + # Otherwise, produce an iCalendar resource. - if request.form.has_key("end"): - calendar_end = EventAggregatorSupport.getMonth(request.form["end"][0]) - else: - calendar_end = None + calendar_start = EventAggregatorSupport.getFormMonth(request, None, "start") + calendar_end = EventAggregatorSupport.getFormMonth(request, None, "end") events, shown_events, all_shown_events, earliest, latest = \ EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end) @@ -49,14 +130,12 @@ for event_page, event_details in all_shown_events: - # Get a pretty version of the page name. - - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page) + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details) # Output the event details. request.write("BEGIN:VEVENT\r\n") - request.write("SUMMARY:%s\r\n" % pretty_pagename) + request.write("SUMMARY:%s\r\n" % event_summary) request.write("UID:%s\r\n" % request.getQualifiedURL(event_page.url(request))) request.write("URL:%s\r\n" % request.getQualifiedURL(event_page.url(request))) request.write("DTSTART;VALUE=DATE:%04d%02d%02d\r\n" % event_details["start"]) @@ -67,4 +146,9 @@ request.write("END:VCALENDAR\r\n") +# Action function. + +def execute(pagename, request): + EventAggregatorSummary(pagename, request).render() + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 83350447c606 -r a7c274e2932c macros/EventAggregator.py --- a/macros/EventAggregator.py Thu Mar 26 01:46:07 2009 +0100 +++ b/macros/EventAggregator.py Fri Mar 27 01:00:15 2009 +0100 @@ -44,39 +44,6 @@ # Macro functions. -def getMonth(arg): - n = None - - if arg.startswith("current"): - date = EventAggregatorSupport.getCurrentMonth() - if len(arg) > 8: - n = int(arg[7:]) - - elif arg.startswith("yearstart"): - date = (EventAggregatorSupport.getCurrentYear(), 1) - if len(arg) > 10: - n = int(arg[9:]) - - elif arg.startswith("yearend"): - date = (EventAggregatorSupport.getCurrentYear(), 12) - if len(arg) > 8: - n = int(arg[7:]) - - else: - date = EventAggregatorSupport.getMonth(arg) - - if n is not None: - date = EventAggregatorSupport.monthupdate(date, n) - - return date - -def getFormMonth(request, calendar_name, argname): - arg = request.form.get("%s-%s" % (calendar_name, argname), [None])[0] - if arg is not None: - return getMonth(arg) - else: - return None - def execute(macro, args): """ @@ -125,10 +92,10 @@ for arg in parsed_args: if arg.startswith("start="): - calendar_start = getMonth(arg[6:]) + calendar_start = EventAggregatorSupport.getParameterMonth(arg[6:]) elif arg.startswith("end="): - calendar_end = getMonth(arg[4:]) + calendar_end = EventAggregatorSupport.getParameterMonth(arg[4:]) elif arg.startswith("mode="): mode = arg[5:] @@ -145,8 +112,8 @@ # Find request parameters to override settings. if calendar_name is not None: - calendar_start = getFormMonth(request, calendar_name, "start") or calendar_start - calendar_end = getFormMonth(request, calendar_name, "end") or calendar_end + calendar_start = EventAggregatorSupport.getFormMonth(request, calendar_name, "start") or calendar_start + calendar_end = EventAggregatorSupport.getFormMonth(request, calendar_name, "end") or calendar_end # Get the events. @@ -383,9 +350,7 @@ if not (event_details["start"] <= date <= event_details["end"]): continue - # Get a pretty version of the page name. - - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page) + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details) # Generate a colour for the event. @@ -414,10 +379,10 @@ if not hide_text: output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=style)) - output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename))) + output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary))) else: output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=hidden_style)) - output.append(fmt.text(pretty_pagename)) + output.append(fmt.text(event_summary)) output.append(fmt.div(on=0)) @@ -456,15 +421,13 @@ for event_page, event_details in shown_events.get((year, month), []): - # Get a pretty version of the page name. - - pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page) + event_summary = EventAggregatorSupport.getEventSummary(event_page, event_details) output.append(fmt.listitem(on=1, attr={"class" : "event-listing"})) - # Link to the page using the pretty name. + # Link to the page using the summary. - output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename))) + output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary))) # Add the event details. diff -r 83350447c606 -r a7c274e2932c pages/EventTemplate --- a/pages/EventTemplate Thu Mar 26 01:46:07 2009 +0100 +++ b/pages/EventTemplate Fri Mar 27 01:00:15 2009 +0100 @@ -1,6 +1,11 @@ Start:: YYYY-MM-DD End:: YYYY-MM-DD Topics:: topics +## Summary:: summary/title +## To choose a title or summary different to the page name, or to +## provide a specific form of the page name, uncomment the above entry +## and write the appropriate title or summary, employing simple Wiki +## syntax. For example: <> Description of event. ----