On Nov 6, 2007, at 11:35 AM, Humberto Diógenes wrote:

  I'm trying to port an existing mod_python app to Pylons, but had
some trouble with Routes. I'd like to keep using URLs the same
"classic" URL style:
  http://localhost/location/edit?location_id=123

  And then have Pylons receive it as arguments for the controller
method:

<code>
class LocationController(BaseController):
    def edit(self, location_id):
        return 'Editing %s' % location_id
</code>

  But I'm getting this exception:
  TypeError: edit() takes exactly 2 arguments (1 given)

  Do you have any directions on what do I need to do to make it work?

Routes can handle this, though you'll need to 'post-process' the query arguments as a function condition:
http://routes.groovie.org/manual.html#conditions

In an app I'm working on right now, I have to handle some weird legacy URL's that work entirely based on query parameters, with the path portion being identical. No problem!

Try this in your routes...

from paste.wsgiwrappers import WSGIRequest

def fix_location(environ, result):
    req = WSGIRequest(environ)
    result['location'] = req.GET.get('location_id', '')
    return True

map.connect(':controller/:action', conditions=dict (function=fix_location))

Your function can now ask for 'location' as a function argument.

Note that since the same dict used for Routes that is passed into your controller, is also passed into your condition that verifies the route is valid (returning False causes it to not match), you can inject whatever you like from anything environ can see (remote ip, referer, etc.).

I'd highly recommend using this approach with Pylons 0.9.6.1, as pylons-dev is undergoing active development.

Cheers,
Ben

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to