Re: [Zope3-Users] Custom Image Widget - Solution
Hi Tom all, First of all, thanks for the help. Its much appreciated :) I understand what you're suggesting, but I needed a way to do it without traversal. For what I'm trying to do, the interface and implementation of the zope objects need to be as simple as possible - anything fancy needs to be (if possible) outside the interface/implementation (like in a widget) I attached what I ended up doing for the widget and the form. Its nothing radical, and very crude, but it works. (The supdoc attribute in the form is defined as supDoc = List(title=_(u"Supporting Docs List"), value_type=Object(IImage, __name__='ImgItem', title=_(u"Image"))) anyway, hope this helps anyone who gets stuck on this sort of thing. Again, thanks. Adam Tom Dossis wrote: Adam Summers wrote: Hi Tom Widget Afficionados. Thanks for the help so far. My problem is now this: From this code (which Tom supplied), how do I code the logic (in bold) def _toFieldValue(self, input): data = "" self)._toFieldValue(input) if data is not None: img = Image(data) notify(ObjectCreatedEvent(img)) return img *else: #data is None, ie. the File input field was left blank and we don't want to #replace the current value of the Image Widget with an empty value. currentImg = the Image object which the field is being rendered for return currentImg * I can't rely on field = self.context image = field.get(field.context) logic to find the data, because my schema can contain: class Iclaim(IContained): """Claim""" supDoc = List(title=_(u"Supporting Docs List"), value_type=Object(IImage, __name__='ImgItem', title=_(u"Image"))) img = Object(IImage, title=_(u"Single img"), required=False) And hence, the self.context.context points to the claim object, not the list inside when rendering supDoc Hi Adam, You can rely on: field = self.context image = field.get(field.context) because the widget is for an attribute object of type IImage. Your supDoc attribute object is a List Type - not an IImage. In this case you'd need another widget - for a list of IImage. I wouldn't been too keen to tackle the html work effort and would probably look at an alternative along the lines of... class IImageList(IContainer): contains(zope.app.image.interfaces.IImage) class IClaim(IContained): supDoc=Object(schema=IImageList) Make supDoc traversable, then you wouldn't need the custom widget here because you can store Images directly in supDoc view with the browser:containerView's. from zope.app.form import CustomWidgetFactory from zope.app.form.browser.widget import DisplayWidget, SimpleInputWidget, renderElement from zope.app.form.browser.sequencewidget import ListSequenceWidget, SequenceDisplayWidget from zope.app.file.image import Image from zope.app.form.interfaces import ConversionError from base64 import b64encode, b64decode class MyImageDisplayWidget(DisplayWidget): def __call__(self): mycontent = u(No Image) if self._renderedValueSet() and self._data is not None: mycontent = buildHTMLImg(self._data.data) return mycontent MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget, subwidget = MyImageDisplayWidget) class MyImageInputWidget(SimpleInputWidget): File Widget type = 'file' def _toFieldValue(self, input): if (input is None or input == ''): try: imgData = b64decode(self.request.form[self.name + '.data']) return Image(imgData) except AttributeError, e: return self.context.missing_value else: try: seek = input.seek read = input.read except AttributeError, e: raise ConversionError(_('Form input is not a file object'), e) else: seek(0) data = read() if data or getattr(input, 'filename', ''): return Image(data) else: return self.context.missing_value def __call__(self): elem = renderElement(self.tag, type=self.type, name=self.name, id=self.name, extra=self.extra) input_widget = elem try: img_widget = buildHTMLImg(self._data.data) elem = renderElement(self.tag, type='hidden', name=self.name+'.data', id=self.name, extra='value=' + b64encode(self._data.data) + '') input_widget = img_widget + input_widget +elem
[Zope3-Users] Re: proxied list object in a schema
Hi Tim, Chat must implement IChat Jürgen Tim Terlegård wrote: Would someone like to explain how to use a list in a schema object without getting ForbiddenAttribute? This is my use case. class IChat(Interface): messages = Attribute('Chat messages') class Chat(Persistent): def __init__(self): self.messages = persistent.list.PersistentList() class class=.chat.Chat require permission=zope.View interface=.interfaces.IChat / require permission=zope.View set_schema=.interfaces.IChat / /class I have a Chat class that implements IChat and that is declared in configure.zcml. Both the chat object and the 'messages' attribute are proxied automatically, right? The require / tags in configure.zcml adds security declarations to the chat object, but not to the 'messages' attribute. Am I correct this far? When I call self.context.messages.append(...) (in a browser page for IChat) I get ForbiddenAttribute on append. I should get this, so this is ok. But list or PersistentList has no interface I can use in IChat instead of Attribute. So I tried using zope.schema.List instead, but the interface of that was a small subset of what list provides and doesn't have append either. So I don't know how to add these security declarations to the 'messages' attribute. How can I use a list without getting security proxy problems? Do I have to make my own list implementation and interface? Tim ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: proxied list object in a schema
Hi Jürgen, Actually Chat implements IChat, I forgot that line. Are all attributes of an object proxied or are for instance attributes starting with _ not proxied? Tim Hi Tim, Chat must implement IChat Jürgen Tim Terlegård wrote: Would someone like to explain how to use a list in a schema object without getting ForbiddenAttribute? This is my use case. class IChat(Interface): messages = Attribute('Chat messages') class Chat(Persistent): def __init__(self): self.messages = persistent.list.PersistentList() class class=.chat.Chat require permission=zope.View interface=.interfaces.IChat / require permission=zope.View set_schema=.interfaces.IChat / /class I have a Chat class that implements IChat and that is declared in configure.zcml. Both the chat object and the 'messages' attribute are proxied automatically, right? The require / tags in configure.zcml adds security declarations to the chat object, but not to the 'messages' attribute. Am I correct this far? When I call self.context.messages.append(...) (in a browser page for IChat) I get ForbiddenAttribute on append. I should get this, so this is ok. But list or PersistentList has no interface I can use in IChat instead of Attribute. So I tried using zope.schema.List instead, but the interface of that was a small subset of what list provides and doesn't have append either. So I don't know how to add these security declarations to the 'messages' attribute. How can I use a list without getting security proxy problems? Do I have to make my own list implementation and interface? Tim ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] proxied list object in a schema
Hi, On Sun, Dec 17, 2006 at 02:21:03PM +0100, Tim Terlegård wrote: Would someone like to explain how to use a list in a schema object without getting ForbiddenAttribute? This is my use case. class IChat(Interface): messages = Attribute('Chat messages') class Chat(Persistent): def __init__(self): self.messages = persistent.list.PersistentList() class class=.chat.Chat require permission=zope.View interface=.interfaces.IChat / require permission=zope.View set_schema=.interfaces.IChat / /class try that: class MyList(persistent.list.PersistentList): pass class class=.MyList ... /class You should find the necessary interfaces for your requires in zope.interface.common.mapping. Regards, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] ZODB explorer?
On Dec 4, 2006, at 7:23 PM, Robert Hicks wrote: I have search a bit on GOOGLE and didn't find anything. I was wondering if there was a GUI for ZODB (like TOAD for Oracle or similar)? Robert ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users since in the zope format there is rarely plain text in the ZODB (just objects), reading the file hierarchy would require you to know which objects were containers and which weren't. To examine the contents you'd have to instantiate the object, which would probably require classes the view doesn't have. Although the ZODB has file- system type properties when using PersistentDictionary, the inclusion of scads of different object types renders it unusable except in the target system. This statement forms a theory of mine at the least, if anyone wants to add/correct it, that's fine by me (thanks even). james ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users