Re: [Zope3-Users] ComponentLookupError

2006-12-14 Thread FB
Hi,

On Wed, Dec 13, 2006 at 09:40:51PM +0100, David Johnson wrote:
 I'm very confused by the following error. Whenever I add certain content 
 components I get the 
 following error when add form is generated (I'm using standard addform).
 
 ComponentLookupError: ((decimalwidget.widget.Decimal object at 0x4203972c, 
 zope.publisher.browser.BrowserRequest instance 
 URL=http://192.168.81.89:8090/CRM/Vanderbilt/@@+/action.html), 
 InterfaceClass 
 zope.app.form.interfaces.IInputWidget, u'')
 
 I am not sure where to go with this.  I have three different instances of 
 Zope and two 
 generate this error and one does not.  The object listed in the error is not 
 the same between 
 content types, although it is consistent within a content type.

AFAIK the data type Decimal was included into zope some months ago. Maybe
two of your zope instances are outdated.

Regards,

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


Re: [Zope3-Users] Registered utility is never found

2006-12-14 Thread FB
Hi,

On Mon, Dec 11, 2006 at 12:58:21PM +0100, FB wrote:
 Hi,
 
 is there any reason why a registered utility which is persistently stored 
 inside the site
 manager is never found via zapi.getUtility(IMyInterface) ?

It's strange - I installed the package on a different computer and wasn't
able to reproduce the problem in any way. After I re-checked-out zope, my
packages, some other stuff, recompiled, ... the problem was gone on the
first computer, too.

Thank you for all your help. I'll keep the list informed, if the problem
re-occurs.

Regards,

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


Re: [Zope3-Users] Custom Image Widget

2006-12-14 Thread Adam Summers




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
Again, any help is much appreciated.
Regards,
Adam

Tom Dossis wrote:

  Adam Summers wrote:
  
  
Hi,

I have the following widgets.


class MyImageDisplayWidget(DisplayWidget):

   class_ = Image

   def __call__(self):
   mycontent = u"oops! no img"
   if self._renderedValueSet():
   mycontent = "img src="" class="moz-txt-link-rfc2396E" href="data:image/gif;base64,">"data:image/gif;base64, " +
b64encode(self._data.data) + " \" /"
   return mycontent

MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget,
subwidget = MyImageDisplayWidget)

class MyImageWidget(FileWidget):

   class_ = Image

   def _toFieldValue(self, input):
   value = super(MyImageWidget, self)._toFieldValue(input)
   return self.class_(value)

MyImageListWidget = CustomWidgetFactory(ListSequenceWidget, subwidget =
MyImageWidget)

I want to build a better input widget (MyImageWidget), so that we can do
the following:
   * If the field has no data, display a file input.
   * If the field has data, display the image.

I know that there are design shortcomings in this, but I need a simple
example (and I only use the files in lists anyway, so I can delete images).

Any pointers on how to go about this would be much appreciated; as always

  
  

Hi Adam,

I'm not exactly sure of your use case, but I've included a widget
implementation (see below) which you may find useful.  I've used this
widget for an attribute which is an IImage, e.g.

  


snip

  
class ImageInputWidget(FileWidget):

def _toFieldValue(self, input):
data = "" self)._toFieldValue(input)
if data is not None:
img = Image(data)
notify(ObjectCreatedEvent(img))
return img

def __call__(self):
input_widget = super(ImageWidget, self).__call__()
try:
image = ImageDisplayWidget(self.context, self.request)()
info = self.info()
return u'br /'.join([image, info, input_widget])
except AttributeError:
# This happens because the context is IAdding
return input_widge

/snippet


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


Re[2]: [Zope3-Users] Custom Image Widget

2006-12-14 Thread Adam Groszer
Hi Adam,

I would try to figure out how the data gets extracted when it gets
displayed. Something like _getCurrentValue.

Or better, have a look at hurry.file. It uses a session variable or
hidden input to solve your problem.
And well, thinking further, hurry.file might be _the_ solution for you.

cheers,

Thursday, December 14, 2006, 4:47:51 PM, you wrote:

AS
AS  Hi Tom  Widget Afficionados.
AS  
AS  Thanks for the help so far.
AS  
AS  My problem is now this:
AS  
AS      From this code (which Tom supplied), how do I code the logic (in bold) 
     
AS  
AS def _toFieldValue(self, input):
AS data = super(ImageWidget, self)._toFieldValue(input)
AS if data is not None:
AS img = Image(data)
AS notify(ObjectCreatedEvent(img))
AS return imgelse: #data is None, ie. the File input
AS field was left blank and we don't want to
AS #replace the current value of the Image Widget with an empty 
value.
AS currentImg = the Image object which the field is being rendered 
for
AS return currentImg
AS  I can't rely on 
AS  
AS  
AS   
AS field = self.context
AS   
AS  image = field.get(field.context)
AS  
AS  
AS  logic to find the data, because my schema can contain:
AS  
AS  
AS class Iclaim(IContained):
AS  
AS Claim
AS  
AS supDoc = List(title=_(uSupporting Docs List),
AS value_type=Object(IImage, __name__='ImgItem', title=_(uImage)))
AS  
AS img = Object(IImage, title=_(uSingle img), required=False)
AS  
AS      And hence, the self.context.context points to the claim
AS object, not the list inside when rendering supDoc
AS  Again, any help is much appreciated.
AS  Regards,
AS  Adam
AS   
AS  Tom Dossis wrote: 
AS   
AS Adam Summers wrote: 
AS   
AS   
AS Hi,

AS I have the following widgets.


AS class MyImageDisplayWidget(DisplayWidget):

ASclass_ = Image

ASdef __call__(self):
ASmycontent = uoops! no img
ASif self._renderedValueSet():
ASmycontent = img src=\data:image/gif;base64,  +
AS b64encode(self._data.data) +  \ /
ASreturn mycontent

AS MyImageListDisplayWidget = CustomWidgetFactory(SequenceDisplayWidget,
AS subwidget = MyImageDisplayWidget)

AS class MyImageWidget(FileWidget):

ASclass_ = Image

ASdef _toFieldValue(self, input):
ASvalue = super(MyImageWidget, self)._toFieldValue(input)
ASreturn self.class_(value)

AS MyImageListWidget = CustomWidgetFactory(ListSequenceWidget, subwidget =
AS MyImageWidget)

AS I want to build a better input widget (MyImageWidget), so that we can do
AS the following:
AS* If the field has no data, display a file input.
AS* If the field has data, display the image.

AS I know that there are design shortcomings in this, but I need a simple
AS example (and I only use the files in lists anyway, so I can delete images).

AS Any pointers on how to go about this would be much appreciated; as always
AS   
AS   
AS Hi Adam,

AS I'm not exactly sure of your use case, but I've included a widget
AS implementation (see below) which you may find useful.  I've used this
AS widget for an attribute which is an IImage, e.g. 
AS  
AS  
AS  snip
AS  
AS   
AS class ImageInputWidget(FileWidget):

AS def _toFieldValue(self, input):
AS data = super(ImageWidget, self)._toFieldValue(input)
AS if data is not None:
AS img = Image(data)
AS notify(ObjectCreatedEvent(img))
AS return img

AS def __call__(self):
AS input_widget = super(ImageWidget, self).__call__()
AS try:
AS image = ImageDisplayWidget(self.context, self.request)()
AS info = self.info()
AS return u'br /'.join([image, info, input_widget])
AS except AttributeError:
AS # This happens because the context is IAdding
AS return input_widge
AS  
AS  /snippet
AS  
AS


-- 
Best regards,
 Adam
--
Quote of the day:
Education helps earning capacity.  Ask any college professor.

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