YES thanks much,

another list to subscribe to :)

On 7/7/07, Ian Wilson <[EMAIL PROTECTED]> wrote:
>
>
> No worries but for future reference there is a sqlobject mailing list
> which I think is what you were looking for:
>
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
> On 7/7/07, Thomas G. Willis <[EMAIL PROTECTED]> wrote:
> > Geez, reading comprehension on saturdays is sucking.
> >
> > Just in case anyone else needs this I offer the solution I came up
> with.I'm
> > sure there's better ways though
> >
> >
> > class SQLBase(SQLObject):
> >     '''Hook some events for auditing(created/last updated)'''
> >     createDate = DateTimeCol(default=datetime.now,notNone=True)
> >     updateDate = DateTimeCol(default=datetime.now,notNone=True)
> >
> >     def __init__(self,*args,**kwargs):
> >         SQLObject.__init__(self,*args,**kwargs)
> >
> >         #hook events
> >
> > events.listen(self.event_CreateRow,self.__class__,events.RowCreateSignal
> )
> >
> > events.listen(self.event_UpdateRow,self.__class__,events.RowUpdateSignal
> )
> >
> >      def event_UpdateRow(self,instance,kwargs):
> >         if not kwargs.has_key("createDate") and not
> > kwargs.has_key("updateDate"):
> >             instance.updateDate = datetime.now()
> >
> >         return
> >     def event_CreateRow(self,instance,kwargs):
> >         if not kwargs.has_key("createDate") and not
> > kwargs.has_key("updateDate"):
> >             instance.createDate = datetime.now()
> >             instance.updateDate = datetime.now()
> >
> >         return
> >
> >
> >
> > On 7/7/07, Thomas G. Willis <[EMAIL PROTECTED] > wrote:
> > > Hello,
> > >
> > > I realize this may not be the best place to ask a SQLobject question
> > > but there doesn't seem to be a group for SQLobject specifically
> > > correct me if I'm wrong.
> > >
> > > Anyway, my question. I want to have columns for updateDate and
> > > createDate. I'm sure you can guess what the functionality would be.
> > >
> > > I saw this.
> > >
> > > http://www.sqlobject.org/module-sqlobject.events.html
> > >
> > >
> > > and this
> > >
> > > http://xentac.net/~jchu/blog/2005/Nov/14
> > >
> > > I thought I understood things and came up with a base class
> > >
> > > class SQLBase(SQLObject):
> > >     '''Hook some events for auditing(created/last updated)'''
> > >     createDate = DateTimeCol(default=datetime.now,notNone=True)
> > >     updateDate = DateTimeCol(default=datetime.now,notNone=True)
> > >
> > >     def __init__(self,*args,**kwargs):
> > >         SQLObject.__init__(self,*args,**kwargs)
> > >
> > >         #hook events
> > >
> > > events.listen(self.event_CreateRow,self,events.RowCreateSignal)
> > >
> > > events.listen(self.event_UpdateRow,self,events.RowUpdateSignal)
> > >
> > >     def event_UpdateRow(self,kwargs):
> > >         print "updaterow: kwargs %s" % str(kwargs)
> > >         setattr(self,'updateDate', datetime.now())
> > >         return
> > >     def event_CreateRow(self,kwargs):
> > >         print "updaterow: kwargs %s" % str(kwargs)
> > >         setattr(self,'createDate', datetime.now())
> > >         setattr(self,'updateDate', datetime.now())
> > >         return
> > >
> > > and a class to test with
> > >
> > > class TestDateCols(SQLBase):
> > >     data = UnicodeCol(notNone=True)
> > >     def __init__(self,*args,**kwargs):
> > >         SQLBase.__init__(self,*args,**kwargs)
> > >
> > >
> > >
> > > when created in tg-admin shell
> > >
> > > In [1]: import model
> > >
> > > In [2]: tobj = model.TestDateCols(data="goo")
> > >
> > > In [3]: tobj.data = "foo"
> > >
> > > In [4]: tobj.updateDate
> > > Out[4]: datetime.datetime(2007, 7, 7, 13, 57, 20)
> > >
> > > In [5]: tobj.createDate
> > > Out[5]: datetime.datetime(2007, 7, 7, 13, 57, 20)
> > >
> > > In [6]:
> > >
> > >
> > > Any  guidance is appreciated.
> > >
> > >
> >
> >
> >
> > --
> > Thomas G. Willis
> >
> >  >
> >
>
> >
>


-- 
Thomas G. Willis

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to