If something comes often, base of computer science is Dont Repeat Yourself :
have in your User model a method like : common_templating_info that
build part of this dict, and update it in the contoller before return.
btw GetCodeLeft, PhoneInfo and GetPhoneList are functions that takes
the user as an argument, it seems to me it would make more sense if
they were @property of the User class.
And regarding PEP8 CamelCase is mostly suited for class while
under_score notation is pretty much for the rest (attributes, method
and function names).
I spot you have some strong coupling in your code between PhoneInfo
and User that might makes it difficult to apply the aforementioned
solution, maintenance will be nightmarish, but this has nothing to do
with turbogears.
Have Fun and good day
2011/10/31 Lingfeng Xiong <xiongl...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>
>
Why don't you make a method in your controller, like:
def common_info(self, page, **kw):
user = sefl.user
info = dict(page=page,
username = user.user_name,
phoneinfo = self.phoneInfo,
phonelist = PhoneInfo.GetPhoneList(user),
codeleft = GetCodeLeft(user),
phonename = PhoneInfo.GetPhoneName(
user=useruser, imei=self.phoneInfo.IMEI))
info.update(kw)
return info
And then in your exposed controller method, you can write:
...
return self.common_info('rename')
or
...
return self.common_info('otherpage', moreinfo='etc')
Also, you can use the add_global_tmpl_vars function in lib.helpers to
provide info that will be available in *all* templates globally.
-- Christoph
def common_info(self, page, **kw):
user = sefl.user
info = dict(page=page,
username = user.user_name,
phoneinfo = self.phoneInfo,
phonelist = PhoneInfo.GetPhoneList(user),
codeleft = GetCodeLeft(user),
phonename = PhoneInfo.GetPhoneName(
user=useruser, imei=self.phoneInfo.IMEI))
info.update(kw)
return info
And then in your exposed controller method, you can write:
...
return self.common_info('rename')
or
...
return self.common_info('otherpage', moreinfo='etc')
[/quote]
is the most suitable way for me.
Thanks again for all your kindly help!
----------
Regards,
Lingfeng Xiong
“六岁至十二岁之学龄儿童,一律受基本教育,免纳学费。其贫苦者,由政府供给
书籍。已逾学龄未受基本教育之国民,一律受补习教育,免纳学费,其书籍亦由政
府供给。”
-- 《中华民国宪法》