Search code examples
pythonploneploneformgen

how to display image uploaded in a submitted form with ploneformgen?


I'm using ploneformgen. [edited] I'm using a custom script adapter from ploneformgen to create a page using the information from submitted forms. The problem is: the page generated when i submit, doesn't show the image. I would like to create a page/document with text AND one image. How can I do this?

I've tried this code:

#Creating the folder in zope instance. I gave the name 'conteudo' to it.
targetdir = context.conteudo

#Here asking for the form,  so we can access its contents
form = request.form

#Creating an unique ID
from DateTime import DateTime
uid= str(DateTime().millis())

# Creating a new Page (Document)
targetdir.invokeFactory('Document',id=uid, title= 'Minha Página', image= form['foto-de-perfil_file'],text='<b>Nome Completo:</b><br>'+form
['nome-completo']+'<br><br>'+'<b>Formação:</b><br>'+form
['formacao']+'<br><br>'+'<b>Áreas de Atuação:</b><br>'+form['areas-de-    atuacao']+'<br><br>'+'<b>Links:</b><br>'+form['links'])

# Set the reference for our new Page
doc = targetdir.get('uid',targetdir)

# Reindexed the Page in the site
doc.reindexObject()

It only shows the text, but the picture isn't there.

I tried using "setImage", but it shows an attribute error. I tried making another invokefactory but instead of 'Document', I put 'Image' then it only shows the image.

What should I modify on my code to display both the text and the picture?

Thanks in advance.


Solution

  • The only thing that worked well for me was instead of creating 'pages', I switched it for 'news items'.