[Zope3-Users] Fields for file and images

Johan Carlsson johanc at easypublisher.com
Thu Oct 20 13:30:16 EDT 2005


Johan Carlsson wrote:

For anyone that might be interested in the update to my code (still only
parsely working):

> Here is my code (which uses the Poll as base, that stuff has been 
> removed though):
> 
> interfaces.py:
> 
>   from zope.interface import Interface
>   from zope.schema import Object
>   from zope.app.file.interfaces import IFile

from zope.security.proxy import removeSecurityProxy

>   from zope.i18n import MessageIDFactory
>   _ = MessageIDFactory('poll')
> 
>   class IPoll(Interface):
> 
>       file=Object(IFile, title=_('File'))
> 
> poll.py:
> 
>   from persistent import Persistent
>   from interfaces import IPoll
>   from zope.interface import implements, classImplements
>   from zope.app.file.file import File
> 
>   class Poll(Persistent, object):
>       implements(IPoll)
> 

         def get_file(self):
             return self._file

         def set_file(self, file):
             self._file = removeSecurityProxy(file)

         file = property(get_file, set_file, None, 'fiddle file')


> 
> browser.py:
> 
>   from zope.interface import implements
>   from zope.app.form.browser.editview import EditView
>   from zope.app.form.browser.add import AddView
>   from zope.app.form import CustomWidgetFactory
>   from zope.app.form.browser import ObjectWidget
> 
>   from interfaces import IPoll
> 
> 
>   from zope.app.file.file import File
> 
>   fw = CustomWidgetFactory(ObjectWidget, File)
> 
>   class PollEditView(EditView):
>       __used_for__ = IPoll
> 
>       file_widget = fw
> 
>   class PollAddView(AddView):
>       __used_for__ = IPoll
> 
>       file_widget = fw
> 
> configure.zcml:
> 
> <configure xmlns="http://namespaces.zope.org/zope"
>     xmlns:browser="http://namespaces.zope.org/browser"
>     i18n_domain="poll">
> 
>   <content class=".poll.Poll">
>   <factory id="zope.app.demo.poll2" />
> 
>   <implements
>     interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
>     />
> 
>   <require
>     permission="zope.View"
>     interface=".interfaces.IPoll"
>     />
> 
>   <require
>     permission="zope.ManageContent"
>     set_schema=".interfaces.IPoll"
>     />
>   </content>
> 
>   <browser:addform
>     schema=".interfaces.IPoll"
>     label="Add a Poll"
>     content_factory=".poll.Poll"
>     name="AddPoll2.html"
>     class=".browser.PollAddView"
>     permission="zope.ManageContent" />
> 
>   <browser:addMenuItem
>     title="Poll 2 Demo"
>     description="Poll 2 Demo"
>     class=".poll.Poll"
>     view="AddPoll2.html"
>     permission="zope.ManageContent"
>     />
> 
>   <browser:editform
>     schema=".interfaces.IPoll"
>     class=".browser.PollEditView"
>     label="Change a Poll"
>     name="edit.html"
>     menu="zmi_views" title="Edit"
>     permission="zope.ManageContent" />
> </configure>
> 
> 
> 
> 


-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM


-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM



More information about the Zope3-users mailing list