how to mounting application under url /user/<login_user>/

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to mounting application under url /user/<login_user>/

GvaderTh

Hi all.
Can anyone tell mi please how mount my aplication under url like
www.myaps.com/user/<user_login>/

For now my apps are mounted like that:
cherrypy.root = PublicContainer()
cherrypy.root.user = PersonalContainer()
cherrypy.server.start()
but I must change url for logged user, so it can't be
www.myaps.com/user/method
but it must be like this
 www.myaps.com/user/<user_login>/method
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 read something about virtual filter, and tryed to use it, but I
didn't get any results.
I'm using cherrypy 2.2.1
Thanks for any help
Gregor


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to mounting application under url /user/<login_user>/

Christian Wyglendowski-2

On 12/12/06, gregor <[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---