Well looks like overriding the traverser is a way to do it..... not too thrilled about copying source from pyramid to tweak but I think I can live with this.
class BatteriiTraverser(ResourceTreeTraverser): HELP_TOKEN = "@@help@@" def __call__(self, request): needs_help = request.path_info.endswith(self.HELP_TOKEN) if needs_help: request.path_info = request.path_info.replace(self.HELP_TOKEN, "") result = ResourceTreeTraverser.__call__(self, request) view = self._get_view_for_context(result["context"], request, result["view_name"]) if view: result["context"] = model.help.HelpRequest(result["context"], request, view) result["view_name"] = "" else: result["context"] = HTTPNotFound() result["view_name"] = "" else: result = ResourceTreeTraverser.__call__(self, request) return result def _get_view_for_context(self, context, request, name=""): """ taken from pyramid because there's no way to hook into pre/post view selection """ provides = [IViewClassifier] + map_(providedBy, (request, context)) try: reg = request.registry except AttributeError: reg = get_current_registry() return reg.adapters.lookup(provides, IView, name=name) On Tuesday, January 1, 2013 4:48:31 PM UTC-5, Thomas G. Willis wrote: > > I'm maintaining a json api with pyramid. And one of the request I > get on occasion is some way to provide help docs on demand for a > given endpoint. Something like..... > > > /user/login?email=...&password=... > > which maps to a UserModel context with view name = "login" > would normally call the view but ideally it would be nice to provide > something like.... > > /user/login/__help__ or /user/login?__help__ > > > if it could return the docstring from the function, the permission > required, whether the user has the permission or not, and any > paramaters expected on the request that would be a good start. > > So a response like > > {view:"login",permitted:true, "permission_required":"anonymous", > parameters:["email","password"]} > > So it seems I need a way to hook into pyramid at the point that the > context and view are selected, but because the view may be secured i > need a way to look determine whether it's a call to the view or a > call to get documentation about the view. > > Since there is no IViewSelected event to subscribe to, my first > thought was to subscribe to the IContextFound event and take a bit > of the code from pyramid.views to go through the view selection but > not call it. This way, I can handle the case where a view > documentation request comes in. > > The problem is, that this event occurs in a very delicate place > inside pyramid. I can't raise a new Context and expect the view > selection machinery to pick it up and do what I'm expecting. > > So, due to copy/pasting code out of pyramid and seeing solutions > that monkey patch pyramid to get what I want, I'm assuming I'm doing > it wrong. So, I'm asking if there's a pyramid way to provide what I > want. I've got the view paramater stuff figured out, I just would > like to know if there's a pattern I can use to customize what > happens between after the context is found, and after a view is > found but before it is ran. > > -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To view this discussion on the web visit https://groups.google.com/d/msg/pylons-devel/-/LoKivGEiKsAJ. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.