Permalink
Browse files

allow variable rules in route_base

  • Loading branch information...
1 parent 01b7a50 commit 6aa02481bc9176de951a5b07573043a4d8e6616f @uniphil uniphil committed Mar 26, 2013
Showing with 10 additions and 4 deletions.
  1. +7 −1 flask_classy.py
  2. +1 −1 test_classy/test_endpoints.py
  3. +2 −2 test_classy/view_classes.py
View
@@ -12,6 +12,7 @@
import functools
import inspect
+from werkzeug.routing import parse_rule
from flask import request, Response, make_response
import re
@@ -210,11 +211,14 @@ def build_rule(cls, rule, method=None):
route_base = cls.get_route_base()
rule_parts = [route_base, rule]
+ ignored_rule_args = ['self']
+ if hasattr(cls, 'base_args'):
+ ignored_rule_args += cls.base_args
if method:
args = inspect.getargspec(method)[0]
for arg in args:
- if arg != "self":
+ if arg not in ignored_rule_args:
rule_parts.append("<%s>" % arg)
result = "/%s" % "/".join(rule_parts)
@@ -226,6 +230,8 @@ def get_route_base(cls):
if hasattr(cls, "route_base"):
route_base = cls.route_base
+ base_rule = parse_rule(route_base)
+ cls.base_args = [r[2] for r in base_rule]
else:
if cls.__name__.endswith("View"):
route_base = cls.__name__[:-4].lower()
@@ -38,4 +38,4 @@ def test_variable_route_popped_base():
def test_variable_route_base():
with app.test_request_context():
url = url_for('VarBaseView:with_base_arg', route='bar')
- eq_('/var-base-route/bar/', url)
+ eq_('/var-base-route/bar/with_base_arg/', url)
@@ -82,8 +82,8 @@ def before_index(self):
def index(self):
return "Custom routed."
- # def with_base_arg(self, route):
- # return "Base route arg: " + route
+ def with_base_arg(self, route):
+ return "Base route arg: " + route
class BeforeRequestView(FlaskView):

0 comments on commit 6aa0248

Please sign in to comment.