CompoundField.ArrayField with more than 1 Field

3 messages Options
Embed this post
Permalink
Nico Grubert-2 () CompoundField.ArrayField with more than 1 Field
Reply Threaded More More options
Print post
Permalink
Hi there

is it possible to use the CompoundField.ArrayField for more than 1 field
at the same time?

I'd like to have an array of <image+imagetitle> pairs and tried this:

ArrayField(
   atapi.ImageField('image',
     searchable = 0,
     required = 0,
     max_size = (380, 220),
     allowable_content_types = ('image/gif','image/jpeg','image/png'),
     widget = atapi.ImageWidget(label = u'Image'),
     ),
  atapi.StringField('image_title',
     widget = atapi.StringWidget(label = u'Image title', size = 150),
     ),
),


Unfortunately, this doesn't seem to work, see the traceback below.

  Exception type: TypeError
Exception value: range() integer end argument expected, got StringField.

Traceback (most recent call last):
   File "/zope/plone/Products/teaserpage/teaserpage.py", line 29, in ?
     widget = atapi.StringWidget(label = u'Image title', size = 150),
   File "/zope/plone/Products/CompoundField/ArrayField.py", line 145, in
__init__
     self.resize(size)
   File "/zope/plone/Products/CompoundField/ArrayField.py", line 180, in
resize
     for i in range(max(size,1)):
TypeError: range() integer end argument expected, got StringField.


Any idea how I can use the ArrayField class for my use case?

Thanks in advance,
Nico

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Jens W. klein-2 () Re: CompoundField.ArrayField with more than 1 Field
Reply Threaded More More options
Print post
Permalink
Am Fri, 24 Apr 2009 14:13:03 +0200 schrieb Nico Grubert:

> Hi there
>
> is it possible to use the CompoundField.ArrayField for more than 1 field
> at the same time?
[...]

yes, just put a CompoundField into the ArrayField

This can be done using ArchGenXML by creating a CompoundField and use it
in a content type (attribute on a class) with multiplicity more than 1.

hth
--
Jens W. Klein - Klein & Partner KEG - BlueDynamics Alliance


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Nico Grubert-2 () Re: CompoundField.ArrayField with more than 1 Field
Reply Threaded More More options
Print post
Permalink
In reply to this post by Nico Grubert-2
Hi Jens

thanks a lot for pointing me in the proper direction. It works fine.

My code reads like this now:

ArrayField(
   CompoundField(name='images',

                 schema=atapi.Schema((
                   atapi.ImageField(name='image',
                         widget = atapi.ImageWidget(label = u'Image'),),
                   atapi.StringField(name='image_title',),
                  ),),
   ),
   size=2,
),

However, I am wondering how to access the image/image_title pairs in an
elegant way.

Here is what I tried with a content type where I stored 2
image/image_title pairs. It works but I am not sure, if that's the
proper way:

# 'self' is an instance of my content object
f = self.Schema().getField('images')
# f.getFields()
#  -> [[<Field images|size(integer:rw)>,
#       <Field images|images:000(compoundfield:rw)>,
#       <Field images|images:001(compoundfield:rw)>]]
for k in f.getFields()[1:]:
   fields = ff.Schema().fields()
   image = fields[0]  # image.tag(self) to get the <img src""> tag
   image_title = fields[1]

Again, thanks for the help, Jens.

Regards,
Nico

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users