Back to index

plone3  3.1.7
file.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2007 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 files.
00014 
00015 $Id: file.py 72569 2007-02-14 12:38:28Z 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 ASCIILine
00023 from zope.schema import Bytes
00024 from zope.schema import Text
00025 from zope.schema import TextLine
00026 
00027 from Products.CMFDefault.formlib.form import ContentEditFormBase
00028 from Products.CMFDefault.formlib.schema import ProxyFieldProperty
00029 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00030 from Products.CMFDefault.interfaces import IMutableFile
00031 from Products.CMFDefault.utils import Message as _
00032 
00033 
00034 class IFileSchema(Interface):
00035 
00036     """Schema for file views.
00037     """
00038 
00039     title = TextLine(
00040         title=_(u'Title'),
00041         readonly=True)
00042 
00043     description = Text(
00044         title=_(u'Description'),
00045         readonly=True)
00046 
00047     format = ASCIILine(
00048         title=_(u'Content type'),
00049         readonly=True)
00050 
00051     upload = Bytes(
00052         title=_(u'Upload'),
00053         required=False)
00054 
00055 
00056 class FileSchemaAdapter(SchemaAdapterBase):
00057 
00058     """Adapter for IMutableFile.
00059     """
00060 
00061     adapts(IMutableFile)
00062     implements(IFileSchema)
00063 
00064     title = ProxyFieldProperty(IFileSchema['title'], 'Title')
00065     description = ProxyFieldProperty(IFileSchema['description'],
00066                                      'Description')
00067     format = ProxyFieldProperty(IFileSchema['format'], 'Format')
00068     upload = ProxyFieldProperty(IFileSchema['upload'],
00069                                 'data', 'manage_upload')
00070 
00071 
00072 class FileEditView(ContentEditFormBase):
00073 
00074     """Edit view for IMutableFile.
00075     """
00076 
00077     form_fields = form.FormFields(IFileSchema)
00078 
00079     def setUpWidgets(self, ignore_request=False):
00080         super(FileEditView,
00081               self).setUpWidgets(ignore_request=ignore_request)
00082         self.widgets['description'].height = 3
00083         self.widgets['upload'].displayWidth = 60
00084 
00085     def _handle_success(self, action, data):
00086         if not data.get('upload'):
00087             del data['upload']
00088         return super(FileEditView, self)._handle_success(action, data)