From 51ddda4bf9dd43d2ea74677af48ac9c872c6f87d Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Fri, 16 May 2014 15:19:49 +0200 Subject: [PATCH] [biplan] fix bugs --- modules/biplan/backend.py | 18 +++++++++++++++--- modules/biplan/browser.py | 2 +- modules/biplan/calendar.py | 2 +- modules/biplan/pages.py | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/biplan/backend.py b/modules/biplan/backend.py index e4478657..49f8901e 100644 --- a/modules/biplan/backend.py +++ b/modules/biplan/backend.py @@ -28,6 +28,14 @@ from.calendar import BiplanCalendarEvent __all__ = ['BiplanBackend'] +def cmp_start_date(p1, p2): + if p1.start_date == p2.start_date: + return 0 + if p1.start_date > p2.start_date: + return 1 + return -1 + + class BiplanBackend(BaseBackend, ICapCalendarEvent): NAME = 'biplan' DESCRIPTION = u'lebiplan.org website' @@ -53,11 +61,15 @@ class BiplanBackend(BaseBackend, ICapCalendarEvent): query.city, query.categories) - return itertools.chain(concert_events, theatre_events) + items = list(itertools.chain(concert_events, theatre_events)) + items.sort(cmp=cmp_start_date) + return items def list_events(self, date_from, date_to=None): - return itertools.chain(self.browser.list_events_concert(date_from, date_to), - self.browser.list_events_theatre(date_from, date_to)) + items = list(itertools.chain(self.browser.list_events_concert(date_from, date_to), + self.browser.list_events_theatre(date_from, date_to))) + items.sort(cmp=cmp_start_date) + return items def get_event(self, _id): return self.browser.get_event(_id) diff --git a/modules/biplan/browser.py b/modules/biplan/browser.py index 1d829974..466cc13e 100644 --- a/modules/biplan/browser.py +++ b/modules/biplan/browser.py @@ -43,7 +43,7 @@ class BiplanBrowser(PagesBrowser): date_to=date_to, city=city, categories=categories, - is_Concert=False) + is_concert=False) def get_event(self, _id, event=None): return self.event_page.go(_id=_id).get_event(obj=event) diff --git a/modules/biplan/calendar.py b/modules/biplan/calendar.py index 817bb2bc..711a6992 100644 --- a/modules/biplan/calendar.py +++ b/modules/biplan/calendar.py @@ -38,6 +38,6 @@ class BiplanCalendarEventConcert(BiplanCalendarEvent): class BiplanCalendarEventTheatre(BiplanCalendarEvent): - def __init__(self, _id): + def __init__(self): BiplanCalendarEvent.__init__(self) self.category = CATEGORIES.THEATRE diff --git a/modules/biplan/pages.py b/modules/biplan/pages.py index 0cd0c931..90f92050 100644 --- a/modules/biplan/pages.py +++ b/modules/biplan/pages.py @@ -85,7 +85,8 @@ class ProgramPage(HTMLPage): item_xpath = '//div[@class="ligne"]' class item(ItemElement): - klass = BiplanCalendarEventConcert if Env('is_concert') else BiplanCalendarEventTheatre + def klass(self): + return BiplanCalendarEventConcert() if self.env['is_concert'] else BiplanCalendarEventTheatre() def condition(self): return (self.el.xpath('./div'))