[Grok-dev] Persistence issue with grok.Model

Andreas Jung lists at zopyx.com
Mon Dec 29 14:43:19 EST 2008

Hi there,

I am current encountering a persistence issue with the following:
A Grok app "Server" contains a container "Accounting" holding instances 
of "Job":

class Server(grok.Application, grok.Container):
     """ This is the base of all evil """


     title = u''
     spool_directory = default_tempdir

     def addJob(self, *args, **kw):
         if not 'accounting' in self:
             self['accounting'] = Accounting()
         self['accounting'].addJob(*args, **kw)
         self._p_changed = 1

class Accounting(grok.Container):
     """ A folder for Job objects """

     num_items = 0

     def addJob(self, *args, **kw):
         self.num_items += 1
         self[str(self.num_items)] = Job(*args, **kw)
         self._p_changed = 1

class Job(grok.Model):
     """ Holds informations about each conversion job """

     def __init__(self, *args, **kw):
         super(Job, self).__init__()
         for k,v in kw.items():
             setattr(self, k, v)

So Server.addJob(**kw) create a new Job instance within the Accouting
container where the **kw parameters are added as instances attributes
(I need this very generic approach).

The mess starts after having created a view for displaying the jobs:

class ShowJobs(grok.View):

     def getJobs(self):
         lst = list()
         for id, job in self.context['accounting'].items():
             print id, job.__dict__
         return lst

The instance dict of a Job instance holds the **kw dict until I restart
my Grok instance. After the restart the instance dict is empty. Is there 
something I am missing or some further magic involved (do I need a 
schema for a Grok Model in order for having the instance dict properly


-------------- next part --------------
A non-text attachment was scrubbed...
Name: lists.vcf
Type: text/x-vcard
Size: 316 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20081229/86e6dbc8/attachment.vcf 

More information about the Grok-dev mailing list