1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/EventAggregatorSupport/Locations.py Tue Apr 30 23:49:32 2013 +0200
1.3 @@ -0,0 +1,68 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - EventAggregator location handling
1.7 +
1.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +from LocationSupport import getMapReference
1.13 +
1.14 +def getMapsPage(request):
1.15 + return getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
1.16 +
1.17 +def getLocationsPage(request):
1.18 + return getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
1.19 +
1.20 +class Location:
1.21 +
1.22 + """
1.23 + A representation of a location acquired from the locations dictionary.
1.24 +
1.25 + The locations dictionary is a mapping from location to a string containing
1.26 + white-space-separated values describing...
1.27 +
1.28 + * The latitude and longitude of the location.
1.29 + * Optionally, the time regime used by the location.
1.30 + """
1.31 +
1.32 + def __init__(self, location, locations):
1.33 +
1.34 + """
1.35 + Initialise the given 'location' using the 'locations' dictionary
1.36 + provided.
1.37 + """
1.38 +
1.39 + self.location = location
1.40 +
1.41 + try:
1.42 + self.data = locations[location].split()
1.43 + except KeyError:
1.44 + self.data = []
1.45 +
1.46 + def getPosition(self):
1.47 +
1.48 + """
1.49 + Attempt to return the position of this location. If no position can be
1.50 + found, return a latitude of None and a longitude of None.
1.51 + """
1.52 +
1.53 + try:
1.54 + latitude, longitude = map(getMapReference, self.data[:2])
1.55 + return latitude, longitude
1.56 + except ValueError:
1.57 + return None, None
1.58 +
1.59 + def getTimeRegime(self):
1.60 +
1.61 + """
1.62 + Attempt to return the time regime employed at this location. If no
1.63 + regime has been specified, return None.
1.64 + """
1.65 +
1.66 + try:
1.67 + return self.data[2]
1.68 + except IndexError:
1.69 + return None
1.70 +
1.71 +# vim: tabstop=4 expandtab shiftwidth=4