apiguy/flask-classy — pull request #20 by uniphil (2013-03-26 04:13:16+00:00)
Title: Support rule arguments in route_base

This pull request maybe should have been two. First, it fixes the behaviour of the arguments passed to the proxied views:

1. As far as I can tell, Flask always calls views with only a `**`, so we can drop `*args` altogether there unless I'm missing something. Maybe strange use cases of people calling view functions manually? I'll put them back if you think it's an issue. The place where Flask calls view functions seems to be centralized to always go through [this line in flask.app](https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L1466).

The dict that is passed is the one from the global request object. From my own testing with flask's built-in `@before_request` method, it seems you can change the `request.view_args` dict in a `@before_request`, and expect the arguments passed to views to be changed accordingly.

The flask-classy proxy, however, was getting passed `**request.view_args` by flask, and then passing _that_ into the class's `before_request`, `before_`, and finally the actual `view` method, which means it could not be modified.

I'm going on a lot here, and it might seem like a pretty weird use-case, but I wanted to be able to have the modified `request.view_args` passed to my view methods so that I could pull out arguments from `cls.route_base` first. Which leads me to....

2. Support for arguments in `cls.route_base`! I wanted to do class-level pre-processing of arguments in `route_base`, which lead to all kinds of problems before. The main issue was that adding the `route_base` argument to my view's method declaration caused the variable to be added to the rule twice, and making werkzeug throw a -fit- `ValueError`.

So I pulled in `werkzeug.routing.parse_rule` to find any rules in the `route_base` which should not be re-added because of a method declaration, and had them be ignored along with `self` in `build_rules`.

I added some tests which I think cover my changes. Seems to be working fine for me so far. Let me know what you think!