On 12/12/06, gregor <GSlusarek gmail.com> wrote:
>
> Hi all.
> Can anyone tell mi please how mount my aplication under
url like
> www.myaps.com/user/<user_login>/
[snip]
> Methods are common for every user (exacly class
PersonalContainer is
> common for every user), I just only want to called that
method from
> different url's for each user
> e.g. www.myaps.com/user/smith/method,
> www.myaps.com/user/gregor/method
> What is the best way to do this?
I would suggest using a callable "default" class.
class UrlActionDispatcher(object):
exposed = True
def __call__(self, user, action, **params):
meth = getattr(self, action, None)
if meth and getattr(meth, 'exposed', False):
return meth(user, **params)
else:
raise cherrypy.NotFound
def preferences(self, user):
return preferences_for(user).html()
preferences.exposed = True
Something along those lines. Then...
cherrypy.root.user.default = UrlActionDispatcher()
Then, a request to www.yourapps.com/user/guido/preferences
would call
the preferences method of UrlActionDispatcher with
"guido" as the
parameter.
You could even make the UrlActionDispatcher class a bit more
generic
and only provide a __call__ method and then inherit from it
anywhere
you wanted this sort of dispatching...
class ArticleActions(UrlActionDispatcher):
def view(...):
Does that make sense?
Christian
http://www.dowski.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|