Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #22 (rule lookup does not count inheritance) #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions flask_classy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,39 @@ def register(cls, app, route_base=None, subdomain=None):
proxy = cls.make_proxy_method(name)
route_name = cls.build_route_name(name)
try:
if hasattr(cls, "_rule_cache") and name in cls._rule_cache:
for idx, cached_rule in enumerate(cls._rule_cache[name]):
rule, options = cached_rule
rule = cls.build_rule(rule)
sub, ep, options = cls.parse_options(options)

if not subdomain and sub:
subdomain = sub

if ep:
endpoint = ep
elif len(cls._rule_cache[name]) == 1:
endpoint = route_name
for _cls in cls.mro()[:-1]:
if hasattr(_cls, "_rule_cache") and name in _cls._rule_cache:
for idx, cached_rule in enumerate(_cls._rule_cache[name]):
rule, options = cached_rule
rule = _cls.build_rule(rule)
sub, ep, options = _cls.parse_options(options)

if not subdomain and sub:
subdomain = sub

if ep:
endpoint = ep
elif len(_cls._rule_cache[name]) == 1:
endpoint = route_name
else:
endpoint = "%s_%d" % (route_name, idx,)

app.add_url_rule(rule, endpoint, proxy, subdomain=subdomain, **options)
break
else:
if name in special_methods:
if name in ["get", "index"]:
methods = ["GET"]
else:
endpoint = "%s_%d" % (route_name, idx,)

app.add_url_rule(rule, endpoint, proxy, subdomain=subdomain, **options)

elif name in special_methods:
if name in ["get", "index"]:
methods = ["GET"]
else:
methods = [name.upper()]
methods = [name.upper()]

rule = cls.build_rule("/", value)
rule = cls.build_rule("/", value)

app.add_url_rule(rule, route_name, proxy, methods=methods, subdomain=subdomain)
app.add_url_rule(rule, route_name, proxy, methods=methods, subdomain=subdomain)

else:
rule = cls.build_rule('/%s/' % name, value,)
app.add_url_rule(rule, route_name, proxy, subdomain=subdomain)
else:
rule = cls.build_rule('/%s/' % name, value,)
app.add_url_rule(rule, route_name, proxy, subdomain=subdomain)
except DecoratorCompatibilityError:
raise DecoratorCompatibilityError("Incompatible decorator detected on %s in class %s" % (name, cls.__name__))

Expand Down