1.1 --- a/EventAggregatorSupport.py Sat Feb 18 16:37:58 2012 +0100
1.2 +++ b/EventAggregatorSupport.py Fri Mar 09 00:09:38 2012 +0100
1.3 @@ -85,7 +85,7 @@
1.4 return category_regexp
1.5
1.6 def getWikiDict(pagename, request):
1.7 - if Page(request, pagename).exists() and request.user.may.read(pagename):
1.8 + if pagename and Page(request, pagename).exists() and request.user.may.read(pagename):
1.9 if hasattr(request.dicts, "dict"):
1.10 return request.dicts.dict(pagename)
1.11 else:
1.12 @@ -124,6 +124,20 @@
1.13
1.14 "Extend the generic action support."
1.15
1.16 + def get_option_list(self, value, values):
1.17 +
1.18 + """
1.19 + Return a list of HTML element definitions for options describing the
1.20 + given 'values', selecting the option with the specified 'value' if
1.21 + present.
1.22 + """
1.23 +
1.24 + options = []
1.25 + for available_value in values:
1.26 + selected = self._get_selected(available_value, value)
1.27 + options.append('<option value="%s" %s>%s</option>' % (escattr(available_value), selected, escape(available_value)))
1.28 + return options
1.29 +
1.30 def get_month_lists(self, default_as_current=0):
1.31
1.32 """
1.33 @@ -1365,6 +1379,63 @@
1.34
1.35 return new_event_page.getBody()
1.36
1.37 +def getMapsPage(request):
1.38 + return getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
1.39 +
1.40 +def getLocationsPage(request):
1.41 + return getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
1.42 +
1.43 +class Location:
1.44 +
1.45 + """
1.46 + A representation of a location acquired from the locations dictionary.
1.47 +
1.48 + The locations dictionary is a mapping from location to a string containing
1.49 + white-space-separated values describing...
1.50 +
1.51 + * The latitude and longitude of the location.
1.52 + * Optionally, the time regime used by the location.
1.53 + """
1.54 +
1.55 + def __init__(self, location, locations):
1.56 +
1.57 + """
1.58 + Initialise the given 'location' using the 'locations' dictionary
1.59 + provided.
1.60 + """
1.61 +
1.62 + self.location = location
1.63 +
1.64 + try:
1.65 + self.data = locations[location].split()
1.66 + except KeyError:
1.67 + self.data = []
1.68 +
1.69 + def getPosition(self):
1.70 +
1.71 + """
1.72 + Attempt to return the position of this location. If no position can be
1.73 + found, return a latitude of None and a longitude of None.
1.74 + """
1.75 +
1.76 + try:
1.77 + latitude, longitude = map(getMapReference, self.data[:2])
1.78 + return latitude, longitude
1.79 + except ValueError:
1.80 + return None, None
1.81 +
1.82 + def getTimeRegime(self):
1.83 +
1.84 + """
1.85 + Attempt to return the time regime employed at this location. If no
1.86 + regime has been specified, return None.
1.87 + """
1.88 +
1.89 + try:
1.90 + return self.data[2]
1.91 + except IndexError:
1.92 + return None
1.93 +
1.94 # Colour-related functions.
1.95
1.96 def getColour(s):
1.97 @@ -2820,8 +2891,8 @@
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 + maps_page = getMapsPage(request)
1.104 + locations_page = getLocationsPage(request)
1.105
1.106 map_image = None
1.107
1.108 @@ -2894,7 +2965,7 @@
1.109 # page.
1.110
1.111 else:
1.112 - latitude, longitude = getLocationPosition(location, locations)
1.113 + latitude, longitude = Location(location, locations).getPosition()
1.114
1.115 # Use a normalised location if necessary.
1.116