[Tutor] automatically add it to all the classes
Kent Johnson
kent37 at tds.net
Mon Oct 30 12:02:02 CET 2006
anil maran wrote:
> All the classes in my webpy application have the following lines
> is there anyway to automatically add it to all the classes in code.py,
> user.py
> If it is too basic, please pardon my naivette.
> thanks
> John
> These are the lines shared by all classes,
> @checkaccess(auth=True)
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
> in a class
> class index:
> @checkaccess(auth=True)
> def GET(self):
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
If this is an entire method that is shared by all your classes, then you
can make a base class that contains the method. If the method doesn't
need access to member attributes (doesn't use self) then it doesn't have
to be part of the class definition, it can be a standalone function in a
utility module.
If just part of a method is shared by all the classes, see if you can
put the shared code into a separate method and then use one of the
approaches described above.
If neither of those will work then please give a little more context.
Kent
More information about the Tutor
mailing list