Back to index

plone3  3.1.7
newsitem.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 news items.
00014 
00015 $Id: newsitem.py 72362 2007-02-04 15:31:51Z yuppie $
00016 """
00017 
00018 from zope.component import adapts
00019 from zope.formlib import form
00020 from zope.interface import implements
00021 from zope.interface import Interface
00022 from zope.schema import Choice
00023 from zope.schema import Text
00024 from zope.schema import TextLine
00025 
00026 from Products.CMFDefault.formlib.form import ContentEditFormBase
00027 from Products.CMFDefault.formlib.schema import ProxyFieldProperty
00028 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00029 from Products.CMFDefault.formlib.widgets import ChoiceRadioWidget
00030 from Products.CMFDefault.formlib.widgets import TextInputWidget
00031 from Products.CMFDefault.interfaces import IMutableNewsItem
00032 from Products.CMFDefault.utils import Message as _
00033 
00034 
00035 class INewsItemSchema(Interface):
00036 
00037     """Schema for news item views.
00038     """
00039 
00040     title = TextLine(
00041         title=_(u'Title'),
00042         readonly=True)
00043 
00044     text_format = Choice(
00045         title=_(u'Format'),
00046         vocabulary='cmf.AvailableTextFormats')
00047 
00048     description = Text(
00049         title=_(u'Lead-in'),
00050         required=False,
00051         missing_value=u'')
00052 
00053     text = Text(
00054         title=_(u'Body'),
00055         required=False,
00056         missing_value=u'')
00057 
00058 
00059 class NewsItemSchemaAdapter(SchemaAdapterBase):
00060 
00061     """Adapter for IMutableNewsItem.
00062     """
00063 
00064     adapts(IMutableNewsItem)
00065     implements(INewsItemSchema)
00066 
00067     title = ProxyFieldProperty(INewsItemSchema['title'], 'Title')
00068     text_format = ProxyFieldProperty(INewsItemSchema['text_format'])
00069     description = ProxyFieldProperty(INewsItemSchema['description'],
00070                                      'Description', 'setDescription')
00071     text = ProxyFieldProperty(INewsItemSchema['text'],
00072                               'EditableBody', '_edit')
00073 
00074 
00075 class NewsItemEditView(ContentEditFormBase):
00076 
00077     """Edit view for INewsItem.
00078     """
00079 
00080     form_fields = form.FormFields(INewsItemSchema)
00081     form_fields['text_format'].custom_widget = ChoiceRadioWidget
00082     form_fields['description'].custom_widget = TextInputWidget
00083     form_fields['text'].custom_widget = TextInputWidget
00084 
00085     def setUpWidgets(self, ignore_request=False):
00086         super(NewsItemEditView,
00087               self).setUpWidgets(ignore_request=ignore_request)
00088         self.widgets['text_format'].orientation = 'horizontal'
00089         self.widgets['description'].height = 8
00090         self.widgets['text'].height = 16