On Fri, Oct 23, 2009 at 2:25 PM, Matt Feifarek <[email protected]> wrote:
> On Fri, Oct 23, 2009 at 2:48 PM, d2ncal <[email protected]> wrote:
>
>> However, to get the above working, I will have to change the
>> declaration of view() action in profile controller to accept username
>> as an argument. It already check for username in 'GET'. I want to keep
>> the old method working along with the new method.
>>
>> Is there any way I can get routes to convert the request to a GET
>> based URL, rather than explicitly passing the argument to view
>> function?
>
> Not sure if routes can do that for you, but what you can do is add another
> action to your controller class that does NOT return a response, but merely
> calls the right action:
>
> def view(self, username):
> # whatever you do normally
>
> and:
>
> def legacy_view(self):
> # put some checking here, send 404 if bad...
> un = params.get('username')
> return self.view(un)
>
> Then you can map
>
> http://mysite.com/profile/view?user=username
>
> to the legacy_view in routes.
Routes does not know anything about query parameters. Action
arguments can only be routing variables, not query parameters. Matt's
suggestion with legacy_view is a good one. You could also do this:
def view(self, username=None):
username = username or request.params.get("username")
Or if you wanted to get fancy you could pass a condition function to
the route definition:
def my_function(environ, match_dict):
match_dict["username"] = request.params.get("username")
return True
map.connect(..., conditions={"function": my_function})
But this is arguably too complex for the situation.
--
Mike Orr <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---