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