#2430: Widgets should use lazy params initialization to prevent from 
inconsistence
------------------------+---------------------------------------------------
 Reporter:  xaka        |        Owner:  chrisz      
     Type:  defect      |       Status:  new         
 Priority:  normal      |    Milestone:  1.1.x bugfix
Component:  TG Widgets  |      Version:  1.0.9       
 Severity:  normal      |   Resolution:              
 Keywords:              |  
------------------------+---------------------------------------------------
Comment (by xaka):

 '''Case 1'''
 {{{
 class MyWidget(turbogears.widgets.Widget):
     params = ['call_me']
 widget = MyWidget()
 print widget.call_me # output "None", ok

 def call_me():
     return 'hello world'
 widget.call_me = call_me # we can set it here or in constructor before
 display

 print widget.call_me # output "<function call_me ...>", wrong, we expect
 "hello world"
 }}}

 '''Case 2'''
 {{{
 class MyWidget(turbogears.widgets.Widget):
     params = ['call_me']

     @property  # also could be just a method
     def call_me(self):
         # trying to receive some remote resource (from DB?)
         # but its possible only when application started,
         # and inpossible at __init__ call time
         # if not application_started:
         #     raise RuntimeError('just for test')
         pass
 widget = MyWidget() # upss, RuntimError here, not good
 }}}

 '''Case 3'''
 {{{
 class MyWidget(turbogears.widgets.Widget):
     params = ['call_me']

     @property # also could be just a method
     def call_me(self):
         # load massive data here and doing some
         # highload calculations.
         # We expect that this will called/accesed only at
         # render time or when its really needed, not when __init__
         # calls
         pass
 widget = MyWidget() # upss, waiting for much time, but nobody requested
 "call_me"
 }}}

 My patch resolve all this cases with backward compatible and just few
 lines changes.

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2430#comment:4>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

-- 
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en

Reply via email to