def __init__(self, cls, action='read', args='id', args_map=None): """ @type cls: subclass of django.models.Model @param cls: class to instanciate / check permissions for @type action: basestring @param action: check for specific action. @type args: basestring, iterable @param args: arguments to pass to cls.objects.get. If this is None, check will not instanciate cls. @type args_map: dict, tuple with 2-length tuples @param args_map: map of arg --> model-property (see docs above) """ self.cls = cls self.action = action self.args = toolkit.totuple(args) self.args_map = dict() if not args_map else dict(args_map)
def tab_url(view, arg=None): """ Filter specifically written (but no limited to) reversing tab- urls. This function overcomes the limitations of the normal url tag, as it can process variables. @type view: string, unicode @param view: view which needs to be reverted to an url. @type arg: whatever your view requires @param arg: args passed to reverse() """ if arg is None: return reverse(view) elif isinstance(arg, dict): append = arg.pop("APPEND") url = reverse(view, kwargs=arg) if append: url += append return url else: return reverse(view, args=toolkit.totuple(arg))