This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
tabellio.agenda/tabellio/agenda/folder.py

73 lines
2.2 KiB
Python

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
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleVocabulary
from plone.directives import form, dexterity
from plone.dexterity.content import Container
from tabellio.agenda.interfaces import MessageFactory as _
import tabellio.config.utils
import utils
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:
terms.append(SimpleVocabulary.createTerm(key, value.encode('utf-8'), key))
return SimpleVocabulary(terms)
grok.global_utility(AgendaModeVocabulary, name=u'tabellio.agenda.agendaModes')
class IAgendaFolder(form.Schema):
title = schema.TextLine(title=_(u'Title'))
mode = schema.Choice(title=_(u'Mode'),
vocabulary='tabellio.agenda.agendaModes')
class AgendaFolder(Container):
implements(IAgendaFolder)
class View(grok.View, utils.MonthlyView):
grok.context(IAgendaFolder)
grok.require('zope2.View')
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'
def update(self):
utils.MonthlyView.update(self)
return self.updated
def getYearAndMonthToDisplay(self):
year = self.request.form.get('year') or self.now[0]
month = self.request.form.get('month') or self.now[1]
year, month = int(year), int(month)
return year, month
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')
return [x.getObject() for x in brains]