get all list of events to get next/prev event in the right order (#968)
This commit is contained in:
parent
336e823b5b
commit
dc61db21a2
|
@ -14,6 +14,8 @@ from plone.dexterity.content import Item
|
|||
|
||||
from tabellio.agenda.interfaces import MessageFactory as _
|
||||
|
||||
from utils import MonthlyView
|
||||
|
||||
|
||||
class IBaseEvent(form.Schema):
|
||||
title = schema.TextLine(title=_(u'Title'))
|
||||
|
@ -69,40 +71,57 @@ class Event(BaseEvent):
|
|||
def klass(self):
|
||||
return 'generic-event'
|
||||
|
||||
class EventBaseView:
|
||||
def next_event_url(self, portal_type=None):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
|
||||
class View(grok.View):
|
||||
# do not go more than 100 days in the future
|
||||
end = self.context.start + datetime.timedelta(100)
|
||||
start = self.context.start
|
||||
|
||||
if portal_type is None:
|
||||
portal_type = ('tabellio.agenda.parlevent', 'tabellio.agenda.comevent')
|
||||
|
||||
monthly_view = MonthlyView(self.context, init_calendar=True)
|
||||
serie_of_events = monthly_view.get_events_from_catalog(
|
||||
start, end, portal_type=portal_type)
|
||||
for i, event in enumerate(serie_of_events):
|
||||
event_id = ((type(event.getId) is str) and event.getId or event.getId())
|
||||
if event_id == self.context.id:
|
||||
try:
|
||||
return serie_of_events[i+1].getURL()
|
||||
except IndexError:
|
||||
return None
|
||||
return None
|
||||
|
||||
def previous_event_url(self, portal_type=None):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
|
||||
end = self.context.start
|
||||
# do not go back more than 100 days in the past
|
||||
start = self.context.start - datetime.timedelta(100)
|
||||
|
||||
if portal_type is None:
|
||||
portal_type = ('tabellio.agenda.event', 'tabellio.agenda.parlevent', 'tabellio.agenda.comevent')
|
||||
|
||||
monthly_view = MonthlyView(self.context, init_calendar=True)
|
||||
serie_of_events = monthly_view.get_events_from_catalog(
|
||||
start, end, portal_type=portal_type)
|
||||
for i, event in enumerate(serie_of_events):
|
||||
event_id = ((type(event.getId) is str) and event.getId or event.getId())
|
||||
if event_id == self.context.id:
|
||||
if i == 0:
|
||||
return None
|
||||
return serie_of_events[i-1].getURL()
|
||||
return None
|
||||
|
||||
|
||||
class View(grok.View, EventBaseView):
|
||||
grok.context(IEvent)
|
||||
grok.require('zope2.View')
|
||||
|
||||
def next_event_url(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
# do not go more than 100 days in the future
|
||||
end = self.context.start + datetime.timedelta(100)
|
||||
start = self.context.start
|
||||
r = catalog(
|
||||
portal_type=['tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent',
|
||||
'tabellio.agenda.event'],
|
||||
start={'query': start, 'range': 'min'},
|
||||
end={'query': end, 'range': 'max'},
|
||||
sort_on='start')
|
||||
if len(r) < 2: # r[0] will be the current event
|
||||
return ''
|
||||
return r[1].getURL()
|
||||
return EventBaseView.next_event_url(self)
|
||||
|
||||
def previous_event_url(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
end = self.context.start
|
||||
# do not go back more than 100 days in the past
|
||||
start = self.context.start - datetime.timedelta(100)
|
||||
r = catalog(
|
||||
portal_type=['tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent',
|
||||
'tabellio.agenda.event'],
|
||||
start={'query': start, 'range': 'min'},
|
||||
end={'query': end, 'range': 'max'},
|
||||
sort_on='start')
|
||||
if len(r) == 0:
|
||||
return ''
|
||||
return r[-1].getURL()
|
||||
|
||||
return EventBaseView.previous_event_url(self)
|
||||
|
|
|
@ -13,7 +13,7 @@ from plone.app.textfield import RichText
|
|||
from themis.datatypes.commission import ICommission
|
||||
|
||||
from tabellio.agenda.interfaces import MessageFactory as _
|
||||
from event import IBaseEvent, BaseEvent
|
||||
from event import IBaseEvent, BaseEvent, EventBaseView
|
||||
|
||||
|
||||
class IParlEvent(IBaseEvent):
|
||||
|
@ -31,36 +31,16 @@ class ParlEvent(BaseEvent):
|
|||
return 'parlementary-event'
|
||||
|
||||
|
||||
class ParlEventBaseView:
|
||||
class ParlEventBaseView(EventBaseView):
|
||||
def next_event_url(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
# do not go more than 100 days in the future
|
||||
end = self.context.start + datetime.timedelta(100)
|
||||
start = self.context.start
|
||||
r = catalog(
|
||||
portal_type=['tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent'],
|
||||
start={'query': start, 'range': 'min'},
|
||||
end={'query': end, 'range': 'max'},
|
||||
sort_on='start')
|
||||
if len(r) < 2: # r[0] will be the current event
|
||||
return ''
|
||||
return r[1].getURL()
|
||||
return EventBaseView.next_event_url(self,
|
||||
portal_type=('tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent'))
|
||||
|
||||
def previous_event_url(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
end = self.context.start
|
||||
# do not go back more than 100 days in the past
|
||||
start = self.context.start - datetime.timedelta(100)
|
||||
r = catalog(
|
||||
portal_type=['tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent'],
|
||||
start={'query': start, 'range': 'min'},
|
||||
end={'query': end, 'range': 'max'},
|
||||
sort_on='start')
|
||||
if len(r) == 0:
|
||||
return ''
|
||||
return r[-1].getURL()
|
||||
return EventBaseView.previous_event_url(self,
|
||||
portal_type=('tabellio.agenda.parlevent',
|
||||
'tabellio.agenda.comevent'))
|
||||
|
||||
def has_stream(self):
|
||||
# XXX
|
||||
|
|
|
@ -13,9 +13,11 @@ PLMF = MessageFactory('plonelocales')
|
|||
class MonthlyView:
|
||||
updated = False
|
||||
|
||||
def __init__(self, context):
|
||||
def __init__(self, context, init_calendar=False):
|
||||
self.context = context
|
||||
self.updated = False
|
||||
if init_calendar:
|
||||
self.calendar = getToolByName(context, 'portal_calendar')
|
||||
|
||||
def update(self):
|
||||
if self.updated:
|
||||
|
@ -49,6 +51,8 @@ class MonthlyView:
|
|||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
|
||||
def cmp_event(x, y):
|
||||
if x.start == y.start:
|
||||
return cmp(x.id, y.id)
|
||||
return cmp(x.start, y.start)
|
||||
|
||||
rs = []
|
||||
|
|
Reference in New Issue