Back to index

plone3  3.1.7
calendar.py
Go to the documentation of this file.
00001 from zope.interface import Interface
00002 from zope.component import adapts
00003 from zope.formlib.form import FormFields
00004 from zope.interface import implements
00005 from zope.schema import Choice
00006 from zope.schema import Int
00007 from zope.schema import Tuple
00008 
00009 from Products.CMFCore.utils import getToolByName
00010 from Products.CMFDefault.formlib.schema import ProxyFieldProperty
00011 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00012 from Products.CMFPlone import PloneMessageFactory as _
00013 from Products.CMFPlone.interfaces import IPloneSiteRoot
00014 
00015 from form import ControlPanelForm
00016 from widgets import MultiCheckBoxVocabularyWidget
00017 from widgets import WeekdayWidget
00018 
00019 
00020 class ICalendarSchema(Interface):
00021 
00022     firstweekday = Int(title=_(u'First day of week in the calendar'),
00023                        default=0,
00024                        required=True)
00025 
00026     calendar_states = Tuple(title=_(u'Workflow states to show in the calendar'),
00027                             required=True,
00028                             missing_value=set(),
00029                             value_type=Choice(
00030                                 vocabulary="plone.app.vocabularies.WorkflowStates"))
00031 
00032 
00033 class CalendarControlPanelAdapter(SchemaAdapterBase):
00034     adapts(IPloneSiteRoot)
00035     implements(ICalendarSchema)
00036 
00037     def __init__(self, context):
00038         super(CalendarControlPanelAdapter, self).__init__(context)
00039         self.context = getToolByName(context, 'portal_calendar')
00040 
00041     firstweekday = ProxyFieldProperty(ICalendarSchema['firstweekday'])
00042     calendar_states = ProxyFieldProperty(ICalendarSchema['calendar_states'])
00043 
00044 
00045 class CalendarControlPanel(ControlPanelForm):
00046 
00047     form_fields = FormFields(ICalendarSchema)
00048     form_fields['firstweekday'].custom_widget = WeekdayWidget
00049     form_fields['calendar_states'].custom_widget = MultiCheckBoxVocabularyWidget
00050 
00051     label = _("Calendar settings")
00052     description = None
00053     form_name = _("Calendar settings")