[Zope-CMF] Problem adding Portal Images programatically
Josef Albert Meile
jmeile@hotmail.com
Fri, 05 Oct 2001 10:44:12 -0000
Hello group,
I saw Gr=E9goire Weber's HowTo about "adding objects at member
creation"
(http://www.zope.org/Members/gregweb/cmf_add_objects_at_member_creatio
n), took some code from it, and addapted it to my necessities.
I need to add an image (on this case a logo) before I create an
instance of my product. I can add the image and I can see it from my
product and from the manage interface, but I can't see it from the
portal. Whenever I click on the link that appears on the
folder_contents form, I get the following error:
BEGIN ERROR MESSAGE --->
Error Type: Not Found
Error Value: Cannot find default view for
/NewPortal/Members/jmeile/GRYTXTR5.JPG"
Troubleshooting Suggestions
The URL may be incorrect.
The parameters passed to this resource may be incorrect.
A resource that this resource relies on may be encountering an error.
Traceback (innermost last):
File /usr/local/Zope-2.3.0/lib/python/ZPublisher/Publish.py, line
223, in publish_module
File /usr/local/Zope-2.3.0/lib/python/ZPublisher/Publish.py, line
187, in publish
File /usr/local/Zope-2.3.0/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook (Object: GRYTXTR5.JPG)
File /usr/local/Zope-2.3.0/lib/python/ZPublisher/Publish.py, line
171, in publish
File /usr/local/Zope-2.3.0/lib/python/ZPublisher/mapply.py, line
160, in mapply (Object: view)
File /usr/local/Zope-2.3.0/lib/python/ZPublisher/Publish.py, line
112, in call_object (Object: view)
File
/usr/local/Zope-2.3.0/lib/python/Products/CMFCore/PortalContent.py,
line 247, in view (Object: GRYTXTR5.JPG)
File
/usr/local/Zope-2.3.0/lib/python/Products/CMFCore/PortalContent.py,
line 234, in __call__ (Object: GRYTXTR5.JPG)
File
/usr/local/Zope-2.3.0/lib/python/Products/CMFCore/PortalContent.py,
line 227, in _getDefaultView (Object: GRYTXTR5.JPG)
Not Found: (see above)
END ERROR MESSAGE --->
My editDone form looks like this:
BEGIN EDITDONE --->
<dtml-call "REQUEST.set('fileContent',
REQUEST.form['attachedImage'].read())">
<dtml-call "REQUEST.set('fileName',
REQUEST.form['attachedImage'].filename)">
<dtml-call "REQUEST.set('objectName',getShortName(fileName))">
<dtml-let user=3D"portal_membership.getAuthenticatedMember().getUserName
()" folderLocation=3D"portal_membership.getHomeFolder(user).absolute_url
()">
<dtml-call "REQUEST.set('myContext',REQUEST)">
<dtml-call "createImage(portal_membership.getHomeFolder(user),
fileName,fileContent)">
<dtml-call "REQUEST.set('jobCompanyLogo',
folderLocation+'/'+objectName)">
</dtml-let>
<dtml-call
"propertysheets.JobOfferPropertySheet.manage_changeProperties
(REQUEST)">
<dtml-call "manage_changeProperties(REQUEST)">
<dtml-call indexObject>
<dtml-call "RESPONSE.redirect(URL2+'/folder_contents')">
END EDITDONE --->
note1: The function getShortName returns only the filename without
its path
note2: attachedImage comes from this input:
<input type=3D"file" name=3D"attachedImage">
and my method createImage, which is external, looks like this:
BEGIN CREATEIMAGE --->
from Products.CMFDefault import Image
from string import rfind
def createImage(location, fileName, fileContent):
#gets only the file name without its path
pos=3Drfind(fileName,'\\')
shortName=3DfileName[pos+1:len(fileName)]
#adds the image in the specified location
Image.addImage
(self=3Dlocation,id=3DshortName,file=3DfileContent,title=3DfileName,co
ntent_type=3D'Image')
END CREATEIMAGE --->
I guess the problem could be the part where Gregory say:
if hasattr(ob, '_setPortalTypeName'):
ob._setPortalTypeName('Image')
I didn't put this line because then I get another error which says
that
names beginning with "_" are forbidden.
What could be wrong?
Thanks in advanced,
Josef.