Re: [Zope3-Users] Custom Image Widget

2006-12-15 Thread Tom Dossis
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 = super(ImageWidget, 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=_(uSupporting Docs List), 
 value_type=Object(IImage, __name__='ImgItem', title=_(uImage)))
 
   img = Object(IImage, title=_(uSingle 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.

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] better selection widget

2006-12-15 Thread Dennis Schulz
also if this is just to select a supplier from the table, i'd 
recommend having a look at the vocabulary framework... i put together 
a really simple one for the states vocabulary in orgpeople, but you 
can do more complex examples, see zope.schema/sources.txt it allows 
you to bind a vocabulary to context before fetching values.


thanks i will have a closer look to it. I also have phillip's new book 
now and there is a section about voabularies and sources.


so in your opinion, what would be the most sane way to have a supplier 
selection (being part of a purchase requisition edit form) on a 
different screen?
(I would like to have a more sophisticated supplier selection where you 
have a table view with search filter and possibility to create a new one)


I thought of many possibilities, probably half of it is nonsense:

- right now I have it like this (not very good solved at all): I use an 
objectwidget in the purchase requisition edit, that only serves as 
display and contains a button to the supplier container that is 
acquisitioned from the mapped instance.
here I link every entry in the table with a link like 
purchaserequisitions/3/suppliers/4/@@selectthissupplier.
Here I would like to assign prinstance.supplier = thissupplier, but of 
course thissupplier not provides IObject (Objectwidget) which leads to 
an error. direct db update here is nonsense because I want the update 
only when the complete transaction of the predit form is 
savedso its a one way.


- I can see clearly that this is nonsence, because  I am not 
correctly using the schema, the supplier relation has to be a IChoice 
and not an IObject. Maybe it is also nonsence to have the business logic 
in the __call__ method of @@selectthissupplier view, I would like to 
have an action here but I think if you render the table with zc.table it 
is not possible to have an action for every single row, is it?


- so it would be possible to take the ItemsWidgetBase (already contains 
a vocabulary) and build a custom view upon that shows the details of the 
currently selected supplier and offers a button supplier select to the 
table view. However,
I think it is difficult to have the table view updating the parent edit 
form. Actually when the table view is an independent view it is not a 
parent form at all, I have to do the updates manually, in addition to 
that the previously entered request data will probably be lost when I 
dont pass it manually.


- probably the best option is, I recently thought, is to pack the table 
selection view into a somehow modified sequence selection widget, that 
has a source / vocabulary having all action happening same form but only 
show this widget and hide everything else.
so we would achieve to have all previously entered data on the edit form 
still in the request easily and have a true parent form - child form 
relation.



Dennis

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users