# HG changeset patch # User Paul Boddie # Date 1359762444 -3600 # Node ID c91e6fd46631a3ba85d7baf391a6e01445bea23f # Parent 8896dbbf5fe480355e5323e6e15a1997f760b05e Encoded map location pop-up headings as plain text in order to handle locations specified using Wiki formatting. Moved the map marker and pop-up generation code into its own method. Simplified various methods and added some docstrings. diff -r 8896dbbf5fe4 -r c91e6fd46631 EventAggregatorSupport.py --- a/EventAggregatorSupport.py Wed Jan 30 18:46:41 2013 +0100 +++ b/EventAggregatorSupport.py Sat Feb 02 00:47:24 2013 +0100 @@ -54,6 +54,14 @@ # Utility functions. +def to_plain_text(s, request): + + "Convert 's' to plain text." + + fmt = getFormatterClass(request, "plain")(request) + fmt.setPage(request.page) + return formatText(s, request, fmt) + def getLocationPosition(location, locations): """ @@ -1507,19 +1515,22 @@ navigation_link) def getFullDateLabel(self, date): - page = self.page - request = page.request - return getFullDateLabel(request, date) + return getFullDateLabel(self.page.request, date) def getFullMonthLabel(self, year_month): - page = self.page - request = page.request - return getFullMonthLabel(request, year_month) + return getFullMonthLabel(self.page.request, year_month) def getFullLabel(self, arg): return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg) def _getCalendarPeriod(self, start_label, end_label, default_label): + + """ + Return a label describing a calendar period in terms of the given + 'start_label' and 'end_label', with the 'default_label' being used where + the supplied start and end labels fail to produce a meaningful label. + """ + output = [] append = output.append @@ -2626,7 +2637,57 @@ return "".join(output) + def writeMapMarker(self, marker_x, marker_y, map_x_scale, map_y_scale, location, events): + + "Put a marker on the map." + + page = self.page + request = page.request + fmt = request.formatter + + output = [] + append = output.append + + append(fmt.listitem(on=1, css_class="event-map-label")) + + # Have a positioned marker for the print mode. + + append(fmt.div(on=1, css_class="event-map-label-only", + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( + marker_x, marker_y, map_x_scale, map_y_scale)) + append(fmt.div(on=0)) + + # Have a marker containing a pop-up when using the screen mode, + # providing a normal block when using the print mode. + + append(fmt.div(on=1, css_class="event-map-label", + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( + marker_x, marker_y, map_x_scale, map_y_scale)) + append(fmt.div(on=1, css_class="event-map-details")) + append(fmt.div(on=1, css_class="event-map-shadow")) + append(fmt.div(on=1, css_class="event-map-location")) + + # The location may have been given as formatted text, but this will not + # be usable in a heading, so it must be first converted to plain text. + + append(fmt.heading(on=1, depth=2)) + append(fmt.text(to_plain_text(location, request))) + append(fmt.heading(on=0, depth=2)) + + append(self.writeMapEventSummaries(events)) + + append(fmt.div(on=0)) + append(fmt.div(on=0)) + append(fmt.div(on=0)) + append(fmt.div(on=0)) + append(fmt.listitem(on=0)) + + return "".join(output) + def writeMapEventSummaries(self, events): + + "Write summaries of the given 'events' for the map." + page = self.page request = page.request fmt = request.formatter @@ -2944,38 +3005,9 @@ map_x_scale, map_y_scale), map_x_scale, map_y_scale) - # Put a marker on the map. - - append(fmt.listitem(on=1, css_class="event-map-label")) - - # Have a positioned marker for the print mode. - - append(fmt.div(on=1, css_class="event-map-label-only", - style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( - marker_x, marker_y, map_x_scale, map_y_scale)) - append(fmt.div(on=0)) - - # Have a marker containing a pop-up when using the screen mode, - # providing a normal block when using the print mode. - - append(fmt.div(on=1, css_class="event-map-label", - style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( - marker_x, marker_y, map_x_scale, map_y_scale)) - append(fmt.div(on=1, css_class="event-map-details")) - append(fmt.div(on=1, css_class="event-map-shadow")) - append(fmt.div(on=1, css_class="event-map-location")) - - append(fmt.heading(on=1, depth=2)) - append(fmt.text(location)) - append(fmt.heading(on=0, depth=2)) - - append(self.writeMapEventSummaries(events)) - - append(fmt.div(on=0)) - append(fmt.div(on=0)) - append(fmt.div(on=0)) - append(fmt.div(on=0)) - append(fmt.listitem(on=0)) + # Add the map marker. + + append(self.writeMapMarker(marker_x, marker_y, map_x_scale, map_y_scale, location, events)) append(fmt.number_list(on=0)) append(fmt.div(on=0)) diff -r 8896dbbf5fe4 -r c91e6fd46631 README.txt --- a/README.txt Wed Jan 30 18:46:41 2013 +0100 +++ b/README.txt Sat Feb 02 00:47:24 2013 +0100 @@ -339,6 +339,8 @@ * Added support for search patterns so that event pages can be obtained through arbitrary searches and do not have to belong to particular categories. + * Encoded map location pop-up headings as plain text in order to handle + locations specified using Wiki formatting. New in EventAggregator 0.8.5 (Changes since EventAggregator 0.8.4) ------------------------------------------------------------------