# HG changeset patch # User Paul Boddie # Date 1353194157 -3600 # Node ID 5cc8a34d878310d9b4a84c009756f506f1e31b91 # Parent 5549389238c4875e4906ee4f090f70508e13ae08 Added support for explicitly choosing a page name for a new event, employing parameters for convenience and interoperability with the MonthCalendar macro. diff -r 5549389238c4 -r 5cc8a34d8783 actions/EventAggregatorNewEvent.py --- a/actions/EventAggregatorNewEvent.py Wed Nov 07 00:48:08 2012 +0100 +++ b/actions/EventAggregatorNewEvent.py Sun Nov 18 00:15:57 2012 +0100 @@ -2,7 +2,7 @@ """ MoinMoin - EventAggregatorNewEvent Action - @copyright: 2008, 2009, 2010, 2011 by Paul Boddie + @copyright: 2008, 2009, 2010, 2011, 2012 by Paul Boddie @copyright: 2000-2004 Juergen Hermann , 2003-2008 MoinMoin:ThomasWaldmann, 2004-2006 MoinMoin:AlexanderSchremmer, @@ -15,6 +15,7 @@ from MoinMoin.PageEditor import PageEditor from MoinMoin import config from EventAggregatorSupport import * +import re try: import pytz @@ -40,6 +41,11 @@ show_end_date = form.get("end-day") and not form.get("hide-end-date") or form.get("show-end-date") show_times = (form.get("start-hour") or form.get("end-hour")) and not form.get("hide-times") or form.get("show-times") show_location = form.get("show-location") or form.get("new-location") and not form.get("hide-location") + choose_page_name = form.get("page-name") and not form.get("auto-page-name") or form.get("choose-page-name") + + # Define the overridden page name, if appropriate. + + page_name = choose_page_name and form.get("page-name", ["@PARENT@/@TITLE@"])[0] or "" # Prepare the category list. @@ -184,6 +190,10 @@ "title_label" : escape(_("Event title/summary")), "title_default" : escattr(form.get("title", [""])[0]), + "choose_page_name_label": escape(_("Choose page name")), + "auto_page_name_label" : escape(_("Auto page name")), + "page_name_label" : escape(_("Page name")), + "page_name_default" : escattr(form.get("page-name", [page_name])[0]), "description_label" : escape(_("Event description")), "description_default" : escattr(form.get("description", [""])[0]), @@ -225,6 +235,28 @@ ''' % d + # Page name options. + + if choose_page_name: + html += ''' + + + + + + + + + + ''' % d + else: + html += ''' + + + + + ''' % d + # Location options. html += ''' @@ -651,6 +683,8 @@ start_zone = start_regime or start_offset end_zone = end_regime or end_offset + page_name = form.get("page-name", [None])[0] + # Validate certain fields. title = form.get("title", [""])[0].strip() @@ -725,9 +759,28 @@ full_title = getFullPageName(parent, title) + if page_name: + + # Allow parameters in the page name. This permits a degree of + # interoperability with MonthCalendar. + + page_name = page_name.replace("@PAGE@", request.page.page_name) + page_name = page_name.replace("@DATE@", str(start_date.as_date())) + page_name = page_name.replace("@STARTDATE@", str(start_date.as_date())) + page_name = page_name.replace("@ENDDATE@", str(end_date.as_date())) + page_name = page_name.replace("@PARENT@", parent) + page_name = page_name.replace("@TITLE@", title) + + # Normalise any page hierarchy separators. + + page_name = re.sub("/+", "/", page_name) + + else: + page_name = full_title + # Load the new page and replace the event details in the body. - new_page = PageEditor(request, full_title) + new_page = PageEditor(request, page_name) if new_page.exists(): return 0, _("The specified page already exists. Please choose another name.")