Back to index

plone3  3.1.7
event.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """Browser views for events.
00014 
00015 $Id: event.py 77019 2007-06-24 19:01:14Z hannosch $
00016 """
00017 
00018 from zope.app.form.browser import DatetimeI18nWidget
00019 from zope.app.schema.vocabulary import IVocabularyFactory
00020 from zope.component import adapts
00021 from zope.component import getUtility
00022 from zope.formlib import form
00023 from zope.interface import implements
00024 from zope.interface import Interface
00025 from zope.schema import Choice
00026 from zope.schema import Datetime
00027 from zope.schema import Set
00028 from zope.schema import Text
00029 from zope.schema import TextLine
00030 from zope.schema import URI
00031 
00032 from Products.CMFCore.interfaces import IMetadataTool
00033 from Products.CMFDefault.formlib.form import ContentEditFormBase
00034 from Products.CMFDefault.formlib.form import DisplayFormBase
00035 from Products.CMFDefault.formlib.schema import EmailLine
00036 from Products.CMFDefault.formlib.schema import ProxyFieldProperty
00037 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00038 from Products.CMFDefault.formlib.vocabulary import SimpleVocabulary
00039 
00040 from Products.CMFCalendar.interfaces import IMutableEvent
00041 from Products.CMFCalendar.utils import Message as _
00042 
00043 
00044 class EventTypeVocabulary(object):
00045 
00046     """Vocabulary factory for available event types.
00047     """
00048 
00049     implements(IVocabularyFactory)
00050 
00051     def __call__(self, context):
00052         context = getattr(context, 'context', context)
00053         mdtool = getUtility(IMetadataTool)
00054         items = [ (str(v), unicode(v), _(v))
00055                   for v in mdtool.listAllowedSubjects(context) ]
00056         return SimpleVocabulary.fromTitleItems(items)
00057 
00058 EventTypeVocabularyFactory = EventTypeVocabulary()
00059 
00060 
00061 class IEventSchema(Interface):
00062 
00063     """Schema for event views.
00064     """
00065 
00066     title = TextLine(
00067         title=_(u'Title'),
00068         required=False,
00069         missing_value=u'',
00070         max_length=100)
00071 
00072     contact_name = TextLine(
00073         title=_(u'Contact Name'),
00074         required=False,
00075         missing_value=u'',
00076         max_length=100)
00077 
00078     location = TextLine(
00079         title=_(u'Location'),
00080         required=False,
00081         missing_value=u'',
00082         max_length=100)
00083 
00084     contact_email = EmailLine(
00085         title=_(u'Contact Email'),
00086         required=False)
00087 
00088     categories = Set(
00089         title=_(u'Category'),
00090         required=False,
00091         missing_value=set(),
00092         value_type=Choice(vocabulary="cmf.calendar.AvailableEventTypes"))
00093 
00094     contact_phone = TextLine(
00095         title=_(u'Contact Phone'),
00096         required=False,
00097         missing_value=u'',
00098         max_length=100)
00099 
00100     event_url = URI(
00101         title=_(u'URL'),
00102         required=False,
00103         missing_value=u'',
00104         max_length=100)
00105 
00106     start_date = Datetime(
00107         title=_(u'From'),)
00108 
00109     stop_date = Datetime(
00110         title=_(u'To'),)
00111 
00112     description = Text(
00113         title=_(u'Description'),
00114         required=False,
00115         missing_value=u'')
00116 
00117 
00118 class EventSchemaAdapter(SchemaAdapterBase):
00119 
00120     """Adapter for IMutableEvent.
00121     """
00122 
00123     adapts(IMutableEvent)
00124     implements(IEventSchema)
00125 
00126     title = ProxyFieldProperty(IEventSchema['title'], 'Title', 'setTitle')
00127     contact_name = ProxyFieldProperty(IEventSchema['contact_name'])
00128     location = ProxyFieldProperty(IEventSchema['location'])
00129     contact_email = ProxyFieldProperty(IEventSchema['contact_email'])
00130     categories = ProxyFieldProperty(IEventSchema['categories'],
00131                                     'Subject', 'setSubject')
00132     contact_phone = ProxyFieldProperty(IEventSchema['contact_phone'])
00133     event_url = ProxyFieldProperty(IEventSchema['event_url'])
00134     start_date = ProxyFieldProperty(IEventSchema['start_date'],
00135                                     'start', 'setStartDate')
00136     stop_date = ProxyFieldProperty(IEventSchema['stop_date'],
00137                                    'end', 'setEndDate')
00138     description = ProxyFieldProperty(IEventSchema['description'],
00139                                      'Description', 'setDescription')
00140 
00141 
00142 class EventViewMixin(object):
00143 
00144     def setUpWidgets(self, ignore_request=False):
00145         super(EventViewMixin,
00146               self).setUpWidgets(ignore_request=ignore_request)
00147         self.widgets['title'].split = True
00148         self.widgets['contact_name'].split = True
00149         self.widgets['location'].split = True
00150         self.widgets['contact_email'].split = True
00151         self.widgets['categories'].split = True
00152         self.widgets['categories'].size = 4
00153         self.widgets['contact_phone'].split = True
00154         self.widgets['start_date'].split = True
00155         self.widgets['stop_date'].split = True
00156         self.widgets['description'].height = 5
00157 
00158 
00159 class EventView(EventViewMixin, DisplayFormBase):
00160 
00161     """View for IEvent.
00162     """
00163 
00164     form_fields = form.FormFields(IEventSchema)
00165 
00166 
00167 class EventEditView(EventViewMixin, ContentEditFormBase):
00168 
00169     """Edit view for IMutableEvent.
00170     """
00171 
00172     form_fields = form.FormFields(IEventSchema)
00173     form_fields['start_date'].custom_widget = DatetimeI18nWidget
00174     form_fields['stop_date'].custom_widget = DatetimeI18nWidget