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

added automatic url_rule generation in route()-decorator #92

Open
wants to merge 1 commit into
base: develop
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
14 changes: 12 additions & 2 deletions xbmcswift2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:copyright: (c) 2012 by Jonathan Beluch
:license: GPLv3, see LICENSE for more details.
'''
from inspect import getargspec
import os
import sys
import pickle
Expand Down Expand Up @@ -237,13 +238,22 @@ def new_decorator(func):
return route_decorator(cache_decorator(func))
return new_decorator

def route(self, url_rule, name=None, options=None):
def route(self, url_rule=None, name=None, is_root=False, options=None):
'''A decorator to add a route to a view. name is used to
differentiate when there are multiple routes for a given view.'''
# TODO: change options kwarg to defaults
def decorator(f):
view_name = name or f.__name__
self.add_url_rule(url_rule, f, name=view_name, options=options)
if is_root:
_url_rule = '/'
elif not url_rule:
_url_rule = '/%s/' % view_name
args = getargspec(f)[0]
if args:
_url_rule += '/'.join('%s/<%s>' % (p, p) for p in args)
else:
_url_rule = url_rule
self.add_url_rule(_url_rule, f, name=view_name, options=options)
return f
return decorator

Expand Down