1.1 --- a/macros/EventAggregator.py Sun Apr 10 23:52:09 2011 +0200
1.2 +++ b/macros/EventAggregator.py Sun Apr 10 23:52:35 2011 +0200
1.3 @@ -4,11 +4,12 @@
1.4
1.5 @copyright: 2008, 2009, 2010, 2011 by Paul Boddie <paul@boddie.org.uk>
1.6 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
1.7 - 2005-2008 MoinMoin:ThomasWaldmann.
1.8 + 2005-2008 MoinMoin:ThomasWaldmann
1.9 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 """
1.11
1.12 from MoinMoin import wikiutil
1.13 +from MoinMoin.action import AttachFile
1.14 from EventAggregatorSupport import *
1.15 import calendar
1.16
1.17 @@ -1047,6 +1048,23 @@
1.18 output.append(fmt.table_cell(on=0))
1.19 return "".join(output)
1.20
1.21 + def showDictError(self, text, pagename):
1.22 + page = self.page
1.23 + fmt = page.formatter
1.24 + request = page.request
1.25 +
1.26 + output = []
1.27 +
1.28 + output.append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
1.29 + output.append(fmt.paragraph(on=1))
1.30 + output.append(fmt.text(text))
1.31 + output.append(fmt.paragraph(on=0))
1.32 + output.append(fmt.paragraph(on=1))
1.33 + output.append(linkToPage(request, Page(request, pagename), pagename))
1.34 + output.append(fmt.paragraph(on=0))
1.35 +
1.36 + return "".join(output)
1.37 +
1.38 # HTML-related functions.
1.39
1.40 def getColour(s):
1.41 @@ -1087,9 +1105,7 @@
1.42 mode=day shows a calendar day view of events
1.43 mode=list shows a list of events by month
1.44 mode=table shows a table of events
1.45 -
1.46 - names=daily shows the name of an event on every day of that event
1.47 - names=weekly shows the name of an event once per week
1.48 + mode=map shows a map of events
1.49
1.50 calendar=NAME uses the given NAME to provide request parameters which
1.51 can be used to control the calendar view
1.52 @@ -1099,6 +1115,19 @@
1.53 if not specified)
1.54
1.55 parent=PAGE uses the given PAGE as the parent of any new event page
1.56 +
1.57 + Calendar view options:
1.58 +
1.59 + names=daily shows the name of an event on every day of that event
1.60 + names=weekly shows the name of an event once per week
1.61 +
1.62 + Map view options:
1.63 +
1.64 + map=NAME uses the given NAME as the map image, where an entry for
1.65 + the map must be found in the EventMaps page (or another
1.66 + page specified in the configuration by the
1.67 + 'event_aggregator_maps_page' setting) along with an
1.68 + attached map image
1.69 """
1.70
1.71 request = macro.request
1.72 @@ -1129,6 +1158,7 @@
1.73 calendar_name = None
1.74 template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate")
1.75 parent_name = None
1.76 + map_name = None
1.77
1.78 for arg in parsed_args:
1.79 if arg.startswith("start="):
1.80 @@ -1152,6 +1182,9 @@
1.81 elif arg.startswith("parent="):
1.82 parent_name = arg[7:]
1.83
1.84 + elif arg.startswith("map="):
1.85 + map_name = arg[4:]
1.86 +
1.87 else:
1.88 category_names.append(arg)
1.89
1.90 @@ -1282,7 +1315,82 @@
1.91
1.92 output.append(fmt.table(on=0))
1.93
1.94 - # Output a list or month calendar.
1.95 + # Output a map view.
1.96 +
1.97 + elif mode == "map":
1.98 +
1.99 + # Special dictionary pages.
1.100 +
1.101 + maps_page = getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
1.102 + locations_page = getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
1.103 +
1.104 + map_image = None
1.105 +
1.106 + # Get the maps and locations.
1.107 +
1.108 + if request.user.may.read(maps_page):
1.109 + maps = request.dicts.dict(maps_page)
1.110 + else:
1.111 + maps = None
1.112 +
1.113 + if request.user.may.read(locations_page):
1.114 + locations = request.dicts.dict(locations_page)
1.115 + else:
1.116 + locations = None
1.117 +
1.118 + # Get the map image definition.
1.119 +
1.120 + if maps is not None and map_name is not None:
1.121 + try:
1.122 + map_bottom_left, map_top_right, map_width, map_height, map_image = maps[map_name].split()
1.123 + except (KeyError, ValueError):
1.124 + pass
1.125 +
1.126 + # Report errors.
1.127 +
1.128 + if maps is None:
1.129 + output.append(view.showDictError(
1.130 + _("You do not have read access to the maps page:"),
1.131 + maps_page))
1.132 +
1.133 + elif map_name is None:
1.134 + output.append(view.showDictError(
1.135 + _("Please specify a valid map name corresponding to an entry on the following page:"),
1.136 + maps_page))
1.137 +
1.138 + elif map_image is None:
1.139 + output.append(view.showDictError(
1.140 + _("Please specify a valid entry for %s on the following page:") % map_name,
1.141 + maps_page))
1.142 +
1.143 + elif locations is None:
1.144 + output.append(view.showDictError(
1.145 + _("You do not have read access to the locations page:"),
1.146 + locations_page))
1.147 +
1.148 + # Attempt to show the image.
1.149 +
1.150 + else:
1.151 +
1.152 + # Get the map image URL.
1.153 +
1.154 + map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
1.155 +
1.156 + # Start of map view output.
1.157 +
1.158 + output.append(fmt.div(on=1, css_class="event-map"))
1.159 +
1.160 + output.append(fmt.div(on=1, css_class="event-map-container",
1.161 + style="width: %spx; height: %spx; background-image: url('%s')" % (
1.162 + escattr(map_width), escattr(map_height), map_image_url)
1.163 + ))
1.164 +
1.165 + # End of map view output.
1.166 +
1.167 + output.append(fmt.div(on=0))
1.168 + output.append(fmt.div(on=0))
1.169 +
1.170 + # Output a list or month calendar. These views show month-by-month data.
1.171
1.172 elif mode in ("list", "calendar"):
1.173