[Zope3-Users] Varying Default Value for Subschema (Object in Tuple)
I have a schema (the Tuple of Objects is the important part): class ISyndications(Interface): """Annotation that indicates the object can provide IFeed and that stores the current syndication configuration. """ enabled = Bool(title=_(u'Enable syndication'), description=_(u'...'), default=False, ) syndications = Tuple(title=_(u'Feeds'), description=_(u'...'), required=False, default=(), value_type=Object(title=_(u'Feed'), description=_(u'...'), schema=ISyndication, ), ) def findSyndicationByLocalURL(url): """Find an ISyndication in syndications by the local URL it contains. """ The subschema is (the UUID field is the important part): class ISyndication(Interface): """Configuration for an individual feed. """ name = TextLine(title=_(u'Name'), description=_(u'...'), ) format = Choice(title=_(u'Format'), description=_(u'Data format for this feed'), values=[u'atom', u'rss 1.0', u'rss 2.0'], ) recurse = Bool(title=_(u'Recurse'), description=_(u'...'), default=False, ) enabled = Bool(title=_(u'Enabled'), description=_(u'...'), default=True, ) referring_URL = URI(title=_(u'URL'), description=_(u'...'), ) local_URL = URI(title=_(u'Local URL'), description=_(u'...'), ) UUID = TextLine(title=_(u'UUID'), description=_(u'UUID for this feed.'), required=False, readonly=True, ) I want to populate the UUID upon creation from a function. So I tried this (the __init__ is the important part): class Syndication(persistent.Persistent): """See ISyndication """ implements(ISyndication, IItemUUIDable) self.name = u'' self.format = u'' self.recurse = False self.enabled = False self.referring_URL = None self.local_URL = None def __init__(self): self.UUID = uuid1() However, the UUID field does not show up in the interface as initialized when I do: class SyndicationsEditForm(EditForm): """Edit form for syndications. """ form_fields = Fields(ISyndications) ow = CustomWidgetFactory(ObjectWidget, Syndication) sw = CustomWidgetFactory(SequenceWidget, subwidget=ow) form_fields['syndications'].custom_widget = sw label = u'Configure syndications' This seems like it should be an easy thing to do. Who can tell me what I'm doing wrong? Thanks, Derek ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Re: Varying Default Value for Subschema (Object in Tuple)
Derek Richardson wrote: I have a schema (the Tuple of Objects is the important part): class ISyndications(Interface): """Annotation that indicates the object can provide IFeed and that stores the current syndication configuration. """ enabled = Bool(title=_(u'Enable syndication'), description=_(u'...'), default=False, ) syndications = Tuple(title=_(u'Feeds'), description=_(u'...'), required=False, default=(), value_type=Object(title=_(u'Feed'), description=_(u'...'), schema=ISyndication, ), ) def findSyndicationByLocalURL(url): """Find an ISyndication in syndications by the local URL it contains. """ The subschema is (the UUID field is the important part): class ISyndication(Interface): """Configuration for an individual feed. """ name = TextLine(title=_(u'Name'), description=_(u'...'), ) format = Choice(title=_(u'Format'), description=_(u'Data format for this feed'), values=[u'atom', u'rss 1.0', u'rss 2.0'], ) recurse = Bool(title=_(u'Recurse'), description=_(u'...'), default=False, ) enabled = Bool(title=_(u'Enabled'), description=_(u'...'), default=True, ) referring_URL = URI(title=_(u'URL'), description=_(u'...'), ) local_URL = URI(title=_(u'Local URL'), description=_(u'...'), ) UUID = TextLine(title=_(u'UUID'), description=_(u'UUID for this feed.'), required=False, readonly=True, ) I want to populate the UUID upon creation from a function. So I tried this (the __init__ is the important part): class Syndication(persistent.Persistent): """See ISyndication """ implements(ISyndication, IItemUUIDable) self.name = u'' self.format = u'' self.recurse = False self.enabled = False self.referring_URL = None self.local_URL = None def __init__(self): self.UUID = uuid1() However, the UUID field does not show up in the interface as initialized when I do: class SyndicationsEditForm(EditForm): """Edit form for syndications. """ form_fields = Fields(ISyndications) ow = CustomWidgetFactory(ObjectWidget, Syndication) sw = CustomWidgetFactory(SequenceWidget, subwidget=ow) form_fields['syndications'].custom_widget = sw label = u'Configure syndications' This seems like it should be an easy thing to do. Who can tell me what I'm doing wrong? Thanks, Derek The problem *may* stem from sequencewidget.py (lines 235-239 in Zope 3.3.1): # add an entry to the list if the add button has been pressed if self.name + ".add" in self.request.form: # Should this be using self.context.value_type.missing_value # instead of None? sequence.append(None) When I hack it just to prove a point, like so: # add an entry to the list if the add button has been pressed if self.name + ".add" in self.request.form: # Should this be using self.context.value_type.missing_value # instead of None? from plone.syndication.syndication import Syndication sequence.append(Syndication()) #sequence.append(None) The UUID field gets populated. But I'm not sure where to go with this. I don't see any bugs for SequenceWidget on launchpad, so I'm still figuring I'm doing something wrong... Derek ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Problem with @@absolute_url
I have no idea how to get the absolute url of an adapted object, or even if its possible. If you can, please bear with me and I'll try to explain myself clearly. Consider this example (simple object and adapter): class IStudent: """Simple student object""" studentNumber = StudentNumber( title = _("Student Number"), description = _("""The student's ID number."""), required = True) class IStudentPhoto: """Adapts Student to IImage""" The unit tests for my class and adapter passes fine, so I know that doing something like the following works... photo = StudentPhoto(Student("123456789")) My problem is that I want to display the photo in a browser but can't figure out how. I created a browser view helper in python, and it seems to work for the most part: class StudentDetails: """Helper to return a student photo.""" def getPhoto(self): student = self.context return StudentPhoto(student) In my page template, I can see that the IImage object is being created correctly.. # gives me . But to turn this object into a URL so that I can put it in an tag is beyond me. When I try to do an @@absolute_url on the photo object I get the error saying there's not enough context. Am I going about this the wrong way? Is there some other thing I need to be doing in order for there to be enough context? Thanks for any help, Greg ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Problem with @@absolute_url
You should probably try to set the __parent__ of the adapter to the __parent__ of the adapted object (or to the object itself) Christophe Greg Baker a écrit : I have no idea how to get the absolute url of an adapted object, or even if its possible. If you can, please bear with me and I'll try to explain myself clearly. Consider this example (simple object and adapter): class IStudent: """Simple student object""" studentNumber = StudentNumber( title = _("Student Number"), description = _("""The student's ID number."""), required = True) class IStudentPhoto: """Adapts Student to IImage""" The unit tests for my class and adapter passes fine, so I know that doing something like the following works... photo = StudentPhoto(Student("123456789")) My problem is that I want to display the photo in a browser but can't figure out how. I created a browser view helper in python, and it seems to work for the most part: class StudentDetails: """Helper to return a student photo.""" def getPhoto(self): student = self.context return StudentPhoto(student) In my page template, I can see that the IImage object is being created correctly.. # gives me . But to turn this object into a URL so that I can put it in an tag is beyond me. When I try to do an @@absolute_url on the photo object I get the error saying there's not enough context. Am I going about this the wrong way? Is there some other thing I need to be doing in order for there to be enough context? Thanks for any help, Greg ___ 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] Problem with @@absolute_url
> class StudentDetails: > """Helper to return a student photo.""" > def getPhoto(self): > student = self.context > return StudentPhoto(student) > > In my page template, I can see that the IImage object is being created > correctly.. > > > # > > > gives me . But to turn this > object into a URL so that I can put it in an tag is beyond me. When I > try to do an @@absolute_url on the photo object I get the error saying > there's not enough context. > > Am I going about this the wrong way? Is there some other thing I need to be > doing in order for there to be enough context? Hm... not sure if it is good solution but it is just a quick though so possibly somebody may give you something better. Maybe there are ready solutions for this. In general if you want to return image then you have to return it's data to the browser (not Image object) and you also have to set proper headers like content-type and content-length. I don't remember exactly how it should go but you should find examples with google or see how z3c.image does this etc. This should be something like: class StudentDetails: """Helper to return a student photo.""" def __call__(self): student = self.context self.request.setHeader('content-type', 'image/png') # determine and set content-length here return StudentPhoto(student).data # not sure if it was 'data' # check image.py If you declare this in zcml as: http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Problem with @@absolute_url
On Monday 30 April 2007 17:46, Christophe Combelles wrote: > You should probably try to set the __parent__ of the adapter to the > __parent__ of the adapted object (or to the object itself) Thanks for the advice, Christophe. I tried both ways but neither worked for me. Still getting the 'not enough context' error. Guess I will try using Maciej's way. Hopefully that will work for me. Greg > > Christophe > > Greg Baker a écrit : > > I have no idea how to get the absolute url of an adapted object, or even > > if its possible. If you can, please bear with me and I'll try to explain > > myself clearly. > > > > Consider this example (simple object and adapter): > > > > class IStudent: > > """Simple student object""" > > studentNumber = StudentNumber( > > title = _("Student Number"), > > description = _("""The student's ID number."""), > > required = True) > > > > class IStudentPhoto: > > """Adapts Student to IImage""" > > > > > > The unit tests for my class and adapter passes fine, so I know that doing > > something like the following works... > > > > photo = StudentPhoto(Student("123456789")) > > > > > > My problem is that I want to display the photo in a browser but can't > > figure out how. I created a browser view helper in python, and it seems > > to work for the most part: > > > > class StudentDetails: > > """Helper to return a student photo.""" > > def getPhoto(self): > > student = self.context > > return StudentPhoto(student) > > > > In my page template, I can see that the IImage object is being created > > correctly.. > > > > > > # > > > > > > gives me . But to turn > > this object into a URL so that I can put it in an tag is beyond me. > > When I try to do an @@absolute_url on the photo object I get the error > > saying there's not enough context. > > > > Am I going about this the wrong way? Is there some other thing I need to > > be doing in order for there to be enough context? > > > > Thanks for any help, > > Greg > > ___ > > 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 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Problem with @@absolute_url
Hi, On Mon, 2007-04-30 at 22:23 +0200, Maciej Wisniowski wrote: > > class StudentDetails: > > """Helper to return a student photo.""" > > def getPhoto(self): > > student = self.context > > return StudentPhoto(student) > > > > In my page template, I can see that the IImage object is being created > > correctly.. > > > > > > # > > > > > > gives me . But to turn > > this > > object into a URL so that I can put it in an tag is beyond me. When > > I > > try to do an @@absolute_url on the photo object I get the error saying > > there's not enough context. > > > > Am I going about this the wrong way? Is there some other thing I need to > > be > > doing in order for there to be enough context? > Hm... not sure if it is good solution but it is just a quick though so > possibly somebody may give you something better. Maybe there are ready > solutions for this. In general if you want > to return image then you have to return it's data to the browser (not > Image object) and you also have to set proper headers like content-type > and content-length. I don't remember exactly how it should go but you > should find examples with google or see how z3c.image does this etc. > This should be something like: > > > class StudentDetails: > """Helper to return a student photo.""" > def __call__(self): > student = self.context > self.request.setHeader('content-type', 'image/png') > # determine and set content-length here > return StudentPhoto(student).data # not sure if it was 'data' ># check image.py > > If you declare this in zcml as: > > name='myphoto' >class=StudentDetails' >permission='zope.Public' >for=. > > then you may use url just like: > > student_object/myphoto > > and this will execute __call__ method of the view class. > Maciej's code should do it for you but will need to be a browser view: class StudentPhotoView(BrowserView): etc Also take a look at zope.app.file.browser.image.py for ImageData which takes the trouble to set the correct headers (which Maciej also implies). Hope this helps. Darryl ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users