2011-12-01 17:42:34 +01:00
|
|
|
import datetime
|
|
|
|
|
2011-08-01 08:04:24 +02:00
|
|
|
from five import grok
|
|
|
|
from zope import schema
|
|
|
|
from zope.interface import implements
|
|
|
|
from Products.Five.browser import BrowserView
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2011-08-29 09:51:44 +02:00
|
|
|
from zope.schema.interfaces import IVocabularyFactory
|
|
|
|
from zope.schema.vocabulary import SimpleVocabulary
|
|
|
|
|
2011-08-01 08:04:24 +02:00
|
|
|
from plone.directives import form, dexterity
|
|
|
|
from plone.dexterity.content import Container
|
|
|
|
|
|
|
|
from tabellio.agenda.interfaces import MessageFactory as _
|
2011-08-29 09:51:44 +02:00
|
|
|
import tabellio.config.utils
|
2011-08-01 08:04:24 +02:00
|
|
|
|
2011-08-01 09:15:10 +02:00
|
|
|
import utils
|
|
|
|
|
2011-08-29 09:51:44 +02:00
|
|
|
class AgendaModeVocabulary(object):
|
|
|
|
grok.implements(IVocabularyFactory)
|
|
|
|
|
|
|
|
def __call__(self, context):
|
|
|
|
values = [('month', _(u'Month')), ('list', _(u'List')), ('seances', _(u'Seances'))]
|
|
|
|
terms = []
|
|
|
|
for key, value in values:
|
2011-11-08 14:20:33 +01:00
|
|
|
terms.append(SimpleVocabulary.createTerm(key, key, value))
|
2011-08-29 09:51:44 +02:00
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
grok.global_utility(AgendaModeVocabulary, name=u'tabellio.agenda.agendaModes')
|
|
|
|
|
2011-11-08 14:20:33 +01:00
|
|
|
class AgendaSelectorVocabulary(object):
|
|
|
|
grok.implements(IVocabularyFactory)
|
|
|
|
|
|
|
|
def __call__(self, context):
|
|
|
|
values = [('all', _(u'All events')),
|
|
|
|
('parlevent', _(u'Parlementary Events')),
|
2011-11-08 16:41:30 +01:00
|
|
|
('comevent', _(u'Commission Events')),
|
|
|
|
('parlcomevent', _(u'Parlmentary and Commission Events')),
|
2011-11-08 14:20:33 +01:00
|
|
|
('genevent', _(u'General Events'))]
|
|
|
|
terms = []
|
|
|
|
for key, value in values:
|
|
|
|
terms.append(SimpleVocabulary.createTerm(key, key, value))
|
|
|
|
return SimpleVocabulary(terms)
|
|
|
|
grok.global_utility(AgendaSelectorVocabulary, name=u'tabellio.agenda.agendaSelector')
|
|
|
|
|
2011-08-01 09:15:10 +02:00
|
|
|
|
2011-08-01 08:04:24 +02:00
|
|
|
class IAgendaFolder(form.Schema):
|
|
|
|
title = schema.TextLine(title=_(u'Title'))
|
2011-08-29 09:51:44 +02:00
|
|
|
mode = schema.Choice(title=_(u'Mode'),
|
|
|
|
vocabulary='tabellio.agenda.agendaModes')
|
2011-11-08 14:20:33 +01:00
|
|
|
selector = schema.Choice(title=_(u'Event Selector'), default=u'all',
|
|
|
|
vocabulary='tabellio.agenda.agendaSelector')
|
2011-11-10 18:34:05 +01:00
|
|
|
view_switcher = schema.Bool(title=_(u'Show view switcher'), default=False)
|
2011-08-01 08:04:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AgendaFolder(Container):
|
|
|
|
implements(IAgendaFolder)
|
|
|
|
|
2011-08-01 09:15:10 +02:00
|
|
|
|
|
|
|
class View(grok.View, utils.MonthlyView):
|
|
|
|
grok.context(IAgendaFolder)
|
|
|
|
grok.require('zope2.View')
|
2011-11-10 18:18:17 +01:00
|
|
|
viewname = ''
|
2011-08-01 09:15:10 +02:00
|
|
|
|
2011-11-10 18:34:05 +01:00
|
|
|
def has_view_switcher(self):
|
|
|
|
return self.context.view_switcher == True
|
|
|
|
|
2011-08-29 09:51:44 +02:00
|
|
|
def as_list(self):
|
|
|
|
return self.context.mode == 'list'
|
|
|
|
|
|
|
|
def as_month(self):
|
|
|
|
return self.context.mode == 'month'
|
|
|
|
|
|
|
|
def as_seances(self):
|
|
|
|
return self.context.mode == 'seances'
|
|
|
|
|
2011-08-01 09:15:10 +02:00
|
|
|
def update(self):
|
|
|
|
utils.MonthlyView.update(self)
|
|
|
|
return self.updated
|
|
|
|
|
|
|
|
def getYearAndMonthToDisplay(self):
|
2011-11-29 11:00:58 +01:00
|
|
|
year = self.request.form.get('navyear') or self.now[0]
|
|
|
|
month = self.request.form.get('navmonth') or self.now[1]
|
2011-08-01 09:15:10 +02:00
|
|
|
year, month = int(year), int(month)
|
|
|
|
return year, month
|
2011-08-01 10:26:22 +02:00
|
|
|
|
2011-11-10 18:53:27 +01:00
|
|
|
def shown_events(self):
|
|
|
|
if self.context.selector == 'parlevent':
|
|
|
|
return ['parl']
|
|
|
|
elif self.context.selector == 'comevent':
|
|
|
|
return ['com']
|
|
|
|
elif self.context.selector == 'genevent':
|
|
|
|
return ['gen']
|
|
|
|
elif self.context.selector == 'parlcomevent':
|
|
|
|
return ['parl', 'com']
|
|
|
|
else:
|
|
|
|
return ['parl', 'com', 'gen']
|
|
|
|
|
|
|
|
def get_events_from_catalog(self, start, end, **keywords):
|
2011-11-08 14:20:33 +01:00
|
|
|
if self.context.selector == 'parlevent':
|
|
|
|
portal_type = ['tabellio.agenda.parlevent']
|
2011-11-08 16:41:30 +01:00
|
|
|
elif self.context.selector == 'comevent':
|
|
|
|
portal_type = ['tabellio.agenda.comevent']
|
2011-11-08 14:20:33 +01:00
|
|
|
elif self.context.selector == 'genevent':
|
|
|
|
portal_type = ['tabellio.agenda.event']
|
2011-11-08 16:41:30 +01:00
|
|
|
elif self.context.selector == 'parlcomevent':
|
|
|
|
portal_type = ['tabellio.agenda.parlevent', 'tabellio.agenda.comevent']
|
2011-11-08 14:20:33 +01:00
|
|
|
else:
|
2011-11-08 16:41:30 +01:00
|
|
|
portal_type = ['tabellio.agenda.event', 'tabellio.agenda.parlevent',
|
|
|
|
'tabellio.agenda.comevent']
|
2011-11-08 14:20:33 +01:00
|
|
|
|
2011-11-21 10:58:49 +01:00
|
|
|
return utils.MonthlyView.get_events_from_catalog(self, start, end,
|
|
|
|
portal_type=portal_type, **keywords)
|
2011-11-10 18:53:27 +01:00
|
|
|
|
|
|
|
def getMonthEvents(self):
|
|
|
|
year, month = self.getYearAndMonthToDisplay()
|
|
|
|
last_day = self.calendar._getCalendar().monthrange(year, month)[1]
|
|
|
|
first_date = self.calendar.getBeginAndEndTimes(1, month, year)[0]
|
|
|
|
last_date = self.calendar.getBeginAndEndTimes(last_day, month, year)[1]
|
|
|
|
|
|
|
|
brains = self.get_events_from_catalog(last_date, first_date, sort_on='start')
|
2011-08-01 10:26:22 +02:00
|
|
|
return [x.getObject() for x in brains]
|
|
|
|
|
2011-12-01 17:42:34 +01:00
|
|
|
def getMonthEventsWithRepetition(self):
|
|
|
|
events = self.getMonthEvents()
|
|
|
|
for event in events[:]:
|
|
|
|
if not event.multidays():
|
|
|
|
continue
|
|
|
|
repeated = event.end.toordinal()-event.start.toordinal()
|
|
|
|
for i in range(repeated):
|
|
|
|
# duplicate event with minimal infos
|
|
|
|
new_event = event.__class__()
|
|
|
|
new_event.id = event.id
|
|
|
|
new_event.title = event.title
|
|
|
|
new_event.place = event.place
|
|
|
|
new_event.description = event.description
|
|
|
|
new_event.start = event.start+datetime.timedelta(i+1)
|
|
|
|
new_event.end = event.end
|
|
|
|
# it's kind of ugly but this is definitely the easiest way to
|
|
|
|
# get the item pointing to the right URL
|
|
|
|
new_event.absolute_url = event.absolute_url()
|
|
|
|
events.append(new_event)
|
|
|
|
events.sort(lambda x,y: cmp(x.start, y.start))
|
|
|
|
return events
|
2011-08-29 09:51:44 +02:00
|
|
|
|
2011-12-12 12:04:29 +01:00
|
|
|
def todayanchor(self):
|
|
|
|
return 'd%d-%d-%d' % datetime.datetime.today().timetuple()[:3]
|
|
|
|
|
2011-11-10 18:18:17 +01:00
|
|
|
class List(View):
|
|
|
|
grok.context(IAgendaFolder)
|
|
|
|
grok.require('zope2.View')
|
|
|
|
grok.template('view')
|
|
|
|
viewname = 'list'
|
|
|
|
|
|
|
|
def as_list(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def as_month(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def as_seances(self):
|
|
|
|
return False
|