2.1 --- a/macros/EventAggregator.py Sun Apr 10 23:52:09 2011 +0200
2.2 +++ b/macros/EventAggregator.py Sun Apr 10 23:52:35 2011 +0200
2.3 @@ -4,11 +4,12 @@
2.4
2.5 @copyright: 2008, 2009, 2010, 2011 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 @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.10 """
2.11
2.12 from MoinMoin import wikiutil
2.13 +from MoinMoin.action import AttachFile
2.14 from EventAggregatorSupport import *
2.15 import calendar
2.16
2.17 @@ -1047,6 +1048,23 @@
2.18 output.append(fmt.table_cell(on=0))
2.19 return "".join(output)
2.20
2.21 + def showDictError(self, text, pagename):
2.22 + page = self.page
2.23 + fmt = page.formatter
2.24 + request = page.request
2.25 +
2.26 + output = []
2.27 +
2.28 + output.append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
2.29 + output.append(fmt.paragraph(on=1))
2.30 + output.append(fmt.text(text))
2.31 + output.append(fmt.paragraph(on=0))
2.32 + output.append(fmt.paragraph(on=1))
2.33 + output.append(linkToPage(request, Page(request, pagename), pagename))
2.34 + output.append(fmt.paragraph(on=0))
2.35 +
2.36 + return "".join(output)
2.37 +
2.38 # HTML-related functions.
2.39
2.40 def getColour(s):
2.41 @@ -1087,9 +1105,7 @@
2.42 mode=day shows a calendar day view of events
2.43 mode=list shows a list of events by month
2.44 mode=table shows a table of events
2.45 -
2.46 - names=daily shows the name of an event on every day of that event
2.47 - names=weekly shows the name of an event once per week
2.48 + mode=map shows a map of events
2.49
2.50 calendar=NAME uses the given NAME to provide request parameters which
2.51 can be used to control the calendar view
2.52 @@ -1099,6 +1115,19 @@
2.53 if not specified)
2.54
2.55 parent=PAGE uses the given PAGE as the parent of any new event page
2.56 +
2.57 + Calendar view options:
2.58 +
2.59 + names=daily shows the name of an event on every day of that event
2.60 + names=weekly shows the name of an event once per week
2.61 +
2.62 + Map view options:
2.63 +
2.64 + map=NAME uses the given NAME as the map image, where an entry for
2.65 + the map must be found in the EventMaps page (or another
2.66 + page specified in the configuration by the
2.67 + 'event_aggregator_maps_page' setting) along with an
2.68 + attached map image
2.69 """
2.70
2.71 request = macro.request
2.72 @@ -1129,6 +1158,7 @@
2.73 calendar_name = None
2.74 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate")
2.75 parent_name = None
2.76 + map_name = None
2.77
2.78 for arg in parsed_args:
2.79 if arg.startswith("start="):
2.80 @@ -1152,6 +1182,9 @@
2.81 elif arg.startswith("parent="):
2.82 parent_name = arg[7:]
2.83
2.84 + elif arg.startswith("map="):
2.85 + map_name = arg[4:]
2.86 +
2.87 else:
2.88 category_names.append(arg)
2.89
2.90 @@ -1282,7 +1315,82 @@
2.91
2.92 output.append(fmt.table(on=0))
2.93
2.94 - # Output a list or month calendar.
2.95 + # Output a map view.
2.96 +
2.97 + elif mode == "map":
2.98 +
2.99 + # Special dictionary pages.
2.100 +
2.101 + maps_page = getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
2.102 + locations_page = getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
2.103 +
2.104 + map_image = None
2.105 +
2.106 + # Get the maps and locations.
2.107 +
2.108 + if request.user.may.read(maps_page):
2.109 + maps = request.dicts.dict(maps_page)
2.110 + else:
2.111 + maps = None
2.112 +
2.113 + if request.user.may.read(locations_page):
2.114 + locations = request.dicts.dict(locations_page)
2.115 + else:
2.116 + locations = None
2.117 +
2.118 + # Get the map image definition.
2.119 +
2.120 + if maps is not None and map_name is not None:
2.121 + try:
2.122 + map_bottom_left, map_top_right, map_width, map_height, map_image = maps[map_name].split()
2.123 + except (KeyError, ValueError):
2.124 + pass
2.125 +
2.126 + # Report errors.
2.127 +
2.128 + if maps is None:
2.129 + output.append(view.showDictError(
2.130 + _("You do not have read access to the maps page:"),
2.131 + maps_page))
2.132 +
2.133 + elif map_name is None:
2.134 + output.append(view.showDictError(
2.135 + _("Please specify a valid map name corresponding to an entry on the following page:"),
2.136 + maps_page))
2.137 +
2.138 + elif map_image is None:
2.139 + output.append(view.showDictError(
2.140 + _("Please specify a valid entry for %s on the following page:") % map_name,
2.141 + maps_page))
2.142 +
2.143 + elif locations is None:
2.144 + output.append(view.showDictError(
2.145 + _("You do not have read access to the locations page:"),
2.146 + locations_page))
2.147 +
2.148 + # Attempt to show the image.
2.149 +
2.150 + else:
2.151 +
2.152 + # Get the map image URL.
2.153 +
2.154 + map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
2.155 +
2.156 + # Start of map view output.
2.157 +
2.158 + output.append(fmt.div(on=1, css_class="event-map"))
2.159 +
2.160 + output.append(fmt.div(on=1, css_class="event-map-container",
2.161 + style="width: %spx; height: %spx; background-image: url('%s')" % (
2.162 + escattr(map_width), escattr(map_height), map_image_url)
2.163 + ))
2.164 +
2.165 + # End of map view output.
2.166 +
2.167 + output.append(fmt.div(on=0))
2.168 + output.append(fmt.div(on=0))
2.169 +
2.170 + # Output a list or month calendar. These views show month-by-month data.
2.171
2.172 elif mode in ("list", "calendar"):
2.173