[Twisted-web] newbiew question
Christopher Armstrong
radix at twistedmatrix.com
Wed Jul 23 08:15:37 EDT 2008
On Tue, Jul 22, 2008 at 11:26 PM, Maarten ter Huurne
<maarten at treewalker.org> wrote:
> On Wednesday 23 July 2008, arun chhetri wrote:
>
>> class Calendar(resource.Resource):
>> def __init__(self,user,pswd,server):
>> resource.Resource.__init__(self)
>> self.user = user
>> self.pswd = pswd
>> self.server = server
>> self.putChild('month',Month(user))
>>
>> def render(self,request):
>> return"""<p> The user is %s
>> <a href=/calendar/month> The link to the month is this
>> """%self.user[0]
>>
>> def getChild(self,path,request):
>> return Month(self.user[0])
>
> The information about the user does not belong in any Resource subclass: a
> Resource is a page that can be generated for different users, so it should
> only contain information that is the same for all users. Any user specific
> data should be fetched via the request object.
This is totally inaccurate. It's perfectly reasonable to store
user-specific data in Resource objects. "a Resource is a page that
can be generated for different users" is either irrelevant or not
true, I can't tell which. You can dynamically and return Resources
based on which user is making the request.
Now, I'm not sure my favorite abstraction for a user is a string; I'd
probably pass something other than a username to a Resource. Perhaps a
rich object representing the user.
--
Christopher Armstrong
International Man of Twistery
http://radix.twistedmatrix.com/
http://twistedmatrix.com/
http://canonical.com/
More information about the Twisted-web
mailing list