# HG changeset patch # User Paul Boddie # Date 1305067547 -7200 # Node ID 06b90003d8a54ddc4c0a2ed745e64c3a5fddbbe3 # Parent bfe0018145757d6d558f205afea86074d514e683 Fixed positioning so that an attempt is made to position a specified location before trying to make and position a normalised location. The first successful location is then stored and its position recalled when building the map. diff -r bfe001814575 -r 06b90003d8a5 EventAggregatorSupport.py --- a/EventAggregatorSupport.py Mon May 09 00:38:13 2011 +0200 +++ b/EventAggregatorSupport.py Wed May 11 00:45:47 2011 +0200 @@ -338,6 +338,24 @@ else: return None +def getLocationPosition(location, locations): + + """ + Attempt to return the position of the given 'location' using the 'locations' + dictionary provided. If no position can be found, return a latitude of None + and a longitude of None. + """ + + latitude, longitude = None, None + + if location is not None: + try: + latitude, longitude = map(getMapReference, locations[location].split()) + except (KeyError, ValueError): + pass + + return latitude, longitude + # Action support functions. def getPageRevision(page): diff -r bfe001814575 -r 06b90003d8a5 macros/EventAggregator.py --- a/macros/EventAggregator.py Mon May 09 00:38:13 2011 +0200 +++ b/macros/EventAggregator.py Wed May 11 00:45:47 2011 +0200 @@ -1542,18 +1542,33 @@ # Get events by position. events_by_location = {} + event_locations = {} for event in all_shown_events: event_details = event.getDetails() location = event_details.get("location") - # Use a normalised location if possible. - - location = location and getNormalisedLocation(location) or location + if not event_locations.has_key(location): + + # Look up the position of a location using the locations page. + + latitude, longitude = getLocationPosition(location, locations) + + # Use a normalised location if necessary. + + if latitude is None and longitude is None: + normalised_location = getNormalisedLocation(location) + if normalised_location is not None: + latitude, longitude = getLocationPosition(normalised_location, locations) + if latitude is not None and longitude is not None: + location = normalised_location + + event_locations[location] = latitude, longitude if not events_by_location.has_key(location): events_by_location[location] = [] + events_by_location[location].append(event) # Get the map image URL. @@ -1578,24 +1593,14 @@ output.append(fmt.number_list(on=1)) unpositioned_events = [] - event_locations = events_by_location.keys() + event_locations = event_locations.items() event_locations.sort() # Show the events in the map. - for location in event_locations: + for location, (latitude, longitude) in event_locations: events = events_by_location[location] - # Look up the position of a location using the locations page. - - latitude, longitude = None, None - - if location is not None: - try: - latitude, longitude = map(getMapReference, locations[location].split()) - except (KeyError, ValueError): - pass - # Skip unpositioned locations and locations outside the map. if latitude is None or longitude is None or \