Plone Content Typ programmatisch erstellen (ArrayField)

6 messages Options
Embed this post
Permalink
Nico Grubert-2

Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
Hallo zusammen

Angenommen, ich habe folgenden Content-Typen für Plone 3 definiert:

mycontenttypeSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
   atapi.StringField('images',
       widget=atapi.StringWidget(label=u"Images",),
       ),

Eine Instanz dieses Content-Typen in Plone kann man programmatisch dann
ja wie folgt anlegen:

   obj.invokeFactory("MyContentType",
                      id=id,
                      title=title,
                      images=images,
                     )


Wie müsste der Aufruf zum Anlegen aussehen, wenn 'images' nun nicht ein
StringField wäre, sondern ein ArrayField der folgenden Form:

mycontenttypeSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
ArrayField(CompoundField(name='images', Schema=atapi.Schema((
    atapi.ImageField(name='image',
        label=u'Image',

        searchable = False,
        required = False,
        max_size = (125, 125),
        allowable_content_types = ('image/gif',
                                   'image/jpeg',
                                   'image/png'),
        widget = atapi.ImageWidget(label = u'Image'),
        ),
    atapi.StringField(name='imagetitle', maxlength = 30,
                      label = u'Imagetitle'),
    atapi.TextField(name='imagetext',
                    label = u'Textblock',
                    default_output_type = 'text/x-html-safe',
                    widget = atapi.RichWidget(rows = 3),

                    ),
  ),),
),


Hat jemand so etwas schon mal gemacht und einen Tip für mich?

Gruss & Danke im voraus
Nico


_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope
robert rottermann

Re: Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
ich würe nicht invokeFactory nutzen, sondern
portal_types.constructContent (oder so).
das sähe dann in etwa so aus:
new_id = portal_types.constructContent ("MyContentType", container, id ..)
new_obj = container[new_id]
for feld in alle meine felder:
  new_obj.setzeFeld(wert ..)

robert
Nico Grubert schrieb:

> Hallo zusammen
>
> Angenommen, ich habe folgenden Content-Typen für Plone 3 definiert:
>
> mycontenttypeSchema = schemata.ATContentTypeSchema.copy() +
> atapi.Schema((
>   atapi.StringField('images',
>       widget=atapi.StringWidget(label=u"Images",),
>       ),
>
> Eine Instanz dieses Content-Typen in Plone kann man programmatisch
> dann ja wie folgt anlegen:
>
>   obj.invokeFactory("MyContentType",
>                      id=id,
>                      title=title,
>                      images=images,
>                     )
>
>
> Wie müsste der Aufruf zum Anlegen aussehen, wenn 'images' nun nicht
> ein StringField wäre, sondern ein ArrayField der folgenden Form:
>
> mycontenttypeSchema = schemata.ATContentTypeSchema.copy() +
> atapi.Schema((
> ArrayField(CompoundField(name='images', Schema=atapi.Schema((
>    atapi.ImageField(name='image',
>        label=u'Image',
>        searchable = False,
>        required = False,
>        max_size = (125, 125),
>        allowable_content_types = ('image/gif',
>                                   'image/jpeg',
>                                   'image/png'),
>        widget = atapi.ImageWidget(label = u'Image'),
>        ),
>    atapi.StringField(name='imagetitle', maxlength = 30,
>                      label = u'Imagetitle'),
>    atapi.TextField(name='imagetext',
>                    label = u'Textblock',
>                    default_output_type = 'text/x-html-safe',
>                    widget = atapi.RichWidget(rows = 3),
>                    ),
>  ),),
> ),
>
>
> Hat jemand so etwas schon mal gemacht und einen Tip für mich?
>
> Gruss & Danke im voraus
> Nico
>
>
> _______________________________________________
> zope mailing list
> [hidden email]
> https://mail.dzug.org/mailman/listinfo/zope
>
>



_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope
Nico Grubert-2

Re: Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
robert rottermann wrote:
> ich würe nicht invokeFactory nutzen, sondern
> portal_types.constructContent (oder so).
> das sähe dann in etwa so aus:
> new_id = portal_types.constructContent ("MyContentType", container, id ..)
> new_obj = container[new_id]
> for feld in alle meine felder:
>   new_obj.setzeFeld(wert ..)

Das ist wirklich leichter als ich dachte:

images = [{'image':'',
            'imagetitle':'bu',
            'imagetext':'mytext'}
           ]

obj.invokeFactory("MyContentType",
                    id=id,
                    title=title,
                    images=images,
                    )

Warum sollte ich invokeFactory nicht mehr nutzen? Wird das demnächst
nicht mehr unterstützt?


_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope
robert rottermann

Re: Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
Nico Grubert schrieb:
>
>
> Warum sollte ich invokeFactory nicht mehr nutzen? Wird das demnächst
> nicht mehr unterstützt?
>
weil constructContent in die plone event-maschinerie eingebaut ist und
invokeFactory glaube ich nicht.

robert


_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope
Jens Vagelpohl-2

Re: Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jul 30, 2009, at 15:38 , robert rottermann wrote:

> Nico Grubert schrieb:
>>
>>
>> Warum sollte ich invokeFactory nicht mehr nutzen? Wird das demnächst
>> nicht mehr unterstützt?
>>
> weil constructContent in die plone event-maschinerie eingebaut ist und
> invokeFactory glaube ich nicht.

invokeFactory ruft auch constructContent auf.

jens

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkpxtToACgkQRAx5nvEhZLIhfQCbB+CmWAtLi+nPw2lA8mJ3SQHL
yt4AmQEh61WOv3DkQq289lCKZzn7SUf+
=+L9q
-----END PGP SIGNATURE-----


_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope
robert rottermann

Re: Plone Content Typ programmatisch erstellen (ArrayField)

Reply Threaded More More options
Print post
Permalink
Jens Vagelpohl schrieb:

> On Jul 30, 2009, at 15:38 , robert rottermann wrote:
>
> > Nico Grubert schrieb:
> >>
> >>
> >> Warum sollte ich invokeFactory nicht mehr nutzen? Wird das demnächst
> >> nicht mehr unterstützt?
> >>
> > weil constructContent in die plone event-maschinerie eingebaut ist und
> > invokeFactory glaube ich nicht.
>
> invokeFactory ruft auch constructContent auf.
>
> jens
>
ah, hab gedacht es sei umgekehrt ..
robert
_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope






_______________________________________________
zope mailing list
[hidden email]
https://mail.dzug.org/mailman/listinfo/zope