Hi,

I'm having exactly the same issue.

You can setup routing to correctly set request params, eg. inside
custom AppConfig:

   def setup_routes(self):

        map = Mapper(directory=config['pylons.paths']['controllers'],
                    always_scan=config['debug'])

        # ------------ custom route goes here ---------
        map.connect('/rest/{path}/{resource}', controller='root',
action='routes_placeholder')

        # Setup a default route for the root of object dispatch
        map.connect('*url', controller='root',
action='routes_placeholder')

        config['routes.map'] = map

Then environ['pylons.routes_dict'] will be populated with the relevant
variables, eg.:

'pylons.routes_dict': {'action': u'routes_placeholder', 'path':
u'uploads', 'controller': u'root', 'resource': u'4c1f682f-cfc0-4f9b-
adc3-2ce0825a60ee'}

But, this doesn't seem to find itself in
environ['wsgiorg.routing_args']

I've only just started digging into this issue, so I don't know what
connections there are between wsgiorg.routing_args and
pylons.routes_dict, but in any case predicate.parse_variables uses
wsgiorg.routing_args so will this will still not work unless I use
pylons.routes_dict directly.

I'd likewise appreciate some insight into this issue.  Clearly, I can
now use pylons.routes_dict to get relevant params, but would like to
understand best practice approach for this since it seems I should be
using predicate.parse_variables.

Have I setup custom routes in correctly or is there something else
missing?

FYI, I'm using the RestController

Thanks

On Apr 20, 2:19 pm, NiL <[email protected]> wrote:
> thanks
> this is exactly what the predicate.parse_variables does
>
> ...snip..
>         routing_args = environ.get('wsgiorg.routing_args', ([], {}))
>         positional_args = routing_args[0] or ()
>         named_args = routing_args[1] or {}
>         variables = {
>             'post': post_vars,
>             'get': get_vars,
>             'positional_args': positional_args,
>             'named_args': named_args}
>         return variables
>
> but it sometimes return a URLGenerator object
>
> ....
>
> On Apr 20, 12:15 pm, "Diez B. Roggisch" <[email protected]> wrote:
>
> > On Wednesday, April 20, 2011 11:52:55 am NiL wrote:
>
> > > Hi list
>
> > > I have many RESTControllers, put and get method's signatures typically
> > > are something like
>
> > >  def put(self, item_id, **kwargs):
>
> > > now I want to implement a row based permission predicate decorator
>
> > >     @require(has_access('write'))
> > >     def put(self, item_id, **kwargs):
>
> > > the predicate inherits from
> > > from repoze.what.predicates import Predicate
>
> > > it's import method is evaluate
>
> > >     def evaluate(self, environ, credentials):
> > >         try:
> > >             current_user = environ['repoze.who.identity']['user']
> > >         except KeyError: # anonymous
> > >             self.unmet()
>
> > >         url = environ['pylons.routes_dict']['url']
> > > ....
>
> > > now from the environ I need to determine the item id
> > > I tried using the url like above, but then I need an overcomplex regex
> > > to find the item_id
>
> > > url might be something like :
>
> > >http://127.0.0.1/items/8.xml/?extra=452546587
>
> > > I also tried
>
> > >         vars = self.parse_variables(environ)
> > >         pos_args = vars.get('positional_args')
> > >         if pos_args:
> > >             obj_id = pos_args[0]
>
> > > but in some cases obj_id is evaluated to a URLGenerator object
>
> > > well, my question is, from the environ how can I best determine the
> > > positional arguments ?
>
> > I'm not sure, but aren't they under wsgiorg.routingargs or some such?
>
> > Diez
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to