I need to do initialize some properties of new instances of a DataSkin subclass - ASPAccount. However, I can't put this in __init__ since the object hasn't been stored at that point. Doing self.__dict__['name'] = 'Rincewind' seems kinda ugly. Maybe newItem should by default call a function on newly created objects, say __init? I don't want to have to subclass Specialist (or in my case, LoginManager) each time I want to this, since it's a *very* common action. For example, *** Specialists.py.orig Wed Jul 19 12:37:32 2000 --- Specialists.py Wed Jul 19 12:38:18 2000 *************** *** 37,43 **** def newItem(self, key=None): """Create a new item""" # Default use first rack ! return self.rackList[0].__of__(self).newItem(key) def manage_refreshPlugIns(self, REQUEST=None): """Update plugin registries""" --- 37,46 ---- def newItem(self, key=None): """Create a new item""" # Default use first rack ! obj = self.rackList[0].__of__(self).newItem(key) ! if hasattr(obj, '__init'): ! obj.__init() ! return obj def manage_refreshPlugIns(self, REQUEST=None): """Update plugin registries"""
At 12:42 PM 7/19/00 +0300, Itamar Shtull-Trauring wrote:
I need to do initialize some properties of new instances of a DataSkin subclass - ASPAccount. However, I can't put this in __init__ since the object hasn't been stored at that point.
Doing self.__dict__['name'] = 'Rincewind' seems kinda ugly. Maybe newItem should by default call a function on newly created objects, say __init? I don't want to have to subclass Specialist (or in my case, LoginManager) each time I want to this, since it's a *very* common action. For example,
Could you give a more specific example? My assumption is that if you need to have things happen upon adding, that one uses a trigger to do it. Or, if the data is specific to that instance, then the appropriate thing would be to manipulate properties or attributes in the code that calls newItem(). Also, it isn't necessary to subclass the specialist -- you don't have to call your routine newItem(), after all. newUser() would be a better choice of name for the method, it sounds like.
"Phillip J. Eby" wrote:
Doing self.__dict__['name'] = 'Rincewind' seems kinda ugly. Maybe newItem should by default call a function on newly created objects, say __init? I don't want to have to subclass Specialist (or in my case, LoginManager) each time I want to this, since it's a *very* common action. For example,
Could you give a more specific example? My assumption is that if you need to have things happen upon adding, that one uses a trigger to do it. Or, if the data is specific to that instance, then the appropriate thing would be to manipulate properties or attributes in the code that calls newItem().
I like the OO idea that changes to an object should be done by the object, not by someone else. It seems silly to have to write a trigger to do this, or a factory. Why do classes have __init__ anyway? So that all the internal object creation logic is in the same place. Okay - this is the ASP Account class. These are user objects that I'd like to store in a regular LoginManager. I could subclass LoginManager of course, but I don't want to spread my code all over the place, when there's no real need. class ASPAccount(LoginUser, MemberMixin): def __init__(self, id, title=''): LoginUser.__init__(self, id) self.__dict__['_currentPayment'] = None self.__dict__['debt'] = Payment.Debt(0.0) self.__dict__['debtInPayment'] = Payment.Debt(0.0) self.__dict__['services'] = ServicesManager.ServicesManager() self.__dict__['lastMonthlyPayDay'] = None # day in month on which we pay self.__dict__['payday'] = 15 self.__dict__['log'] = ""
Also, it isn't necessary to subclass the specialist -- you don't have to call your routine newItem(), after all. newUser() would be a better choice of name for the method, it sounds like.
Again, why should I fagment my class into multiple parts? I want it all to be in once place - it's more readable, easier to debug, easier to understand, and more portable. -- Itamar S.T. itamar@maxnm.com Fingerprint = D365 7BE8 B81E 2B18 6534 025E D0E7 92DB E441 411C
At 05:41 PM 7/19/00 +0300, Itamar Shtull-Trauring wrote:
class ASPAccount(LoginUser, MemberMixin):
def __init__(self, id, title=''): LoginUser.__init__(self, id) self.__dict__['_currentPayment'] = None self.__dict__['debt'] = Payment.Debt(0.0) self.__dict__['debtInPayment'] = Payment.Debt(0.0) self.__dict__['services'] = ServicesManager.ServicesManager() self.__dict__['lastMonthlyPayDay'] = None # day in month on which we pay self.__dict__['payday'] = 15 self.__dict__['log'] = ""
Also, it isn't necessary to subclass the specialist -- you don't have to call your routine newItem(), after all. newUser() would be a better choice of name for the method, it sounds like.
Again, why should I fagment my class into multiple parts? I want it all to be in once place - it's more readable, easier to debug, easier to understand, and more portable.
If what you want is default values, then just put them in a DataSkin property sheet in the ZClass. Or, if using a Python class, implement them as class attributes named "class_default_for_X". E.g.: class ASPAccount(LoginUser, MemberMixin): class_default_for__currentPayment = None class_default_for_payday = 15 class_default_for_log = "" Of course, this is only useful for immutables.
participants (2)
-
Itamar Shtull-Trauring -
Phillip J. Eby