1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - EventAggregator location handling 4 5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from LocationSupport import getMapReference 10 11 def getMapsPage(request): 12 return getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict") 13 14 def getLocationsPage(request): 15 return getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict") 16 17 class Location: 18 19 """ 20 A representation of a location acquired from the locations dictionary. 21 22 The locations dictionary is a mapping from location to a string containing 23 white-space-separated values describing... 24 25 * The latitude and longitude of the location. 26 * Optionally, the time regime used by the location. 27 """ 28 29 def __init__(self, location, locations): 30 31 """ 32 Initialise the given 'location' using the 'locations' dictionary 33 provided. 34 """ 35 36 self.location = location 37 38 try: 39 self.data = locations[location].split() 40 except KeyError: 41 self.data = [] 42 43 def getPosition(self): 44 45 """ 46 Attempt to return the position of this location. If no position can be 47 found, return a latitude of None and a longitude of None. 48 """ 49 50 try: 51 latitude, longitude = map(getMapReference, self.data[:2]) 52 return latitude, longitude 53 except ValueError: 54 return None, None 55 56 def getTimeRegime(self): 57 58 """ 59 Attempt to return the time regime employed at this location. If no 60 regime has been specified, return None. 61 """ 62 63 try: 64 return self.data[2] 65 except IndexError: 66 return None 67 68 # vim: tabstop=4 expandtab shiftwidth=4