All pastes #969820 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-03 19:11 UTC
rendered paste body
If I register a local utility in the site manager and this utility extends Persistent, does this guarantees that any data I set in this object will be persisted??


The class for this utility is pretty simple:


class UsersItems(PersistentDict):
    implements( IUsersItemsUtility )

    def getAllItemsForUser(self,uid):
  
       
        #Recuperamos uma referência para a tool portal_catalog
        objid_list = self[uid]
        objlist = []
       
        catalog = getToolByName(self.context, 'portal_catalog')
       
        for objid in objid_list:
            obj = getToolByName( self.context, 'reference_catalog').lookupObject( objid )
            objlist.push(obj)
           
         
        return objlist  
       

       
    def pushItemForUser(self,uid,item_id):
       
        #Checa se a entrada no dic. existe.
        if not self.has_key(uid): self[uid] = PersistentList()
       
        self[uid].append(item_id)
       
       
 I registered it using a Extension/install.py method, the code was:


def setup_usersitems_utility(self):
    portal = getToolByName(self, 'portal_url').getPortalObject()
    sm= portal.getSiteManager()
    is_already_registered = [u for u in sm.getUtilitiesFor(IUsersItemsUtility)]
    if not len(is_already_registered):
        useritems = UsersItems()
        try:
            sm.registerUtility(component=useritems,provided=IUsersItemsUtility)
        except:
            raise

The registration is succesful. I then get a reference to it and feed it some data:

myutil = zope.component.queryUtility(IUsersItemsUtility)
myutil.pushtemForUser('marcelo',333)

However, this data does not get persisted. This code was entered in a debug session of Closeau. If I come back in another session, I can't see this data I just entered.

What am I doing wrong?

Thanks.