[Zope-CMF] Problem adding CMF Topics with quickinstaller

matt.bartolome at uniontrib.com matt.bartolome at uniontrib.com
Mon Sep 29 14:13:52 EDT 2003


Still stuggling with this one...I used the code you directed me too. I still
get the same behavior. The CMF Topic doesn't recognize the friendly date
criteria (on the expires attribute of my objects) until I click "save" under
the topic's "criteria" in the Plone Interface. I'm adding an "Integer
Criterion" in the same place in the code and it works fine. So I guess I
need to figure out what happens when you click "save"?

def install(self):
    out = StringIO()
    portalroot = getattr(self, 'classifieds')
    
    for topicid in TOPIC_MAPPINGS.keys():
        id = str(topicid[0]) + '-' + str(topicid[1])
        
        portalroot.invokeFactory('Topic',id,title=TOPIC_MAPPINGS[topicid])
        
        topic_o = getattr(portalroot,id)
        
        field = 'Section'
        field2 = 'expires'
        
        criterion_type = 'Integer Criterion'
        criterion_type2 = 'Friendly Date Criterion'
        
        topic_o.addCriterion(field=field, criterion_type=criterion_type)
        topic_o.addCriterion(field=field2, criterion_type=criterion_type2)
                 
        criteria_o = getattr(topic_o,'crit__Section')
        range = str(topicid[0] - 1) + ' ' + str(topicid[1] + 1)
        criteria_o.edit(range,direction='min:max')
        
        datecriteria_o = getattr(topic_o,'crit__expires')
        datecriteria_o.edit(operation='min',daterange='ahead')        
    installTypes(self, out,
                 listTypes(PROJECTNAME),
                 PROJECTNAME)

    install_subskin(self, out, GLOBALS)
    get_transaction().commit()
    print >> out, "Successfully installed %s." % PROJECTNAME
    return out.getvalue()


-----Original Message-----
From: Raphael Ritz [mailto:ritz at itb.biologie.hu-berlin.de]
Sent: Monday, September 29, 2003 4:02 AM
To: matt.bartolome at uniontrib.com
Cc: zope-cmf at zope.org
Subject: Re: [Zope-CMF] Problem adding CMF Topics with quickinstaller


Did you solve this in the meantime?

If not, you might want to look at
http://www.neuroinf.de/LabTools/ScriptingCMF-0_1.tgz/view
and there in particular at the source of 'ScriptSite.py'.
It generates and configures (among other things) a topic
from the script which works right away. Maybe you can
find out where it differs from your approach?

Raphael

matt.bartolome at uniontrib.com wrote:

>I have an Install.py script in an archetypes product that adds CMF Topics
>(using portal_quickinstaller). Everything appears to install correctly
>except that the criteria is not being recognized in the topics when viewing
>them through the web. The criteria are shown in the topic interface, they
>just don't work. When I click "save" in the criteria tab in plone the
>criteria are suddenly recognized. Weird.
>
>from Products.Archetypes.public import listTypes
>from Products.Archetypes.Extensions.utils import installTypes,
>install_subskin
>from Products.CMFCore.utils import getToolByName 
>from Products.Classifieds.config import *
>
>from StringIO import StringIO
>
>def install(self):
>    out = StringIO()
>    portalroot = getToolByName(self, 'portal_url').getPortalObject()
>
>    for topicid in TOPIC_MAPPINGS.keys():
>        id = str(topicid[0]) + '-' + str(topicid[1])
>        try:
>            portalroot.invokeFactory(id=id,type_name='Topic')
>        except:
>            pass
>        topic_o = portalroot._getOb(id)
>
>        topic_o.edit(acquireCriteria=None
>                , title=TOPIC_MAPPINGS[topicid]
>                , description=None )
>        
>        field = 'Section'
>        criterion_type = 'Integer Criterion'
>        
>        topic_o.addCriterion(field=field, criterion_type=criterion_type)
>        criteria_o = topic_o.getCriterion(field)
>        range = str(topicid[0] - 1) + ' ' + str(topicid[1] + 1)
>        criteria_o.edit(range,direction='min:max')
>                       
>        for rec in topic_o.listCriteria():
>            crit = topic_o.getCriterion(rec.id)
>            command = {}
>            for attr in crit.editableAttributes():
>                tmp = getattr(rec, attr, None)
>        
>                if tmp is None:
>                    tmp = getattr(rec, '%s__%s' % (attr, rec.id), None)
>                command[attr] = tmp
>            crit.apply(command)
>
>    installTypes(self, out,
>                 listTypes(PROJECTNAME),
>                 PROJECTNAME)
>
>    install_subskin(self, out, GLOBALS)
>
>    print >> out, "Successfully installed %s." % PROJECTNAME
>    return out.getvalue()
>
>_______________________________________________
>Zope-CMF maillist  -  Zope-CMF at zope.org
>http://mail.zope.org/mailman/listinfo/zope-cmf
>
>See http://collector.zope.org/CMF for bug reports and feature requests
>  
>




More information about the Zope-CMF mailing list