def permissioned_model(cls, perm_type=None, path_fields=None, actions=None):
if not issubclass(cls, models.Model):<EOL><INDENT>raise DecoratorException(<EOL>'<STR_LIT>',<EOL>"<STR_LIT>" + cls.__name__ + "<STR_LIT>"<EOL>)<EOL><DEDENT>added = False<EOL>try:<EOL><INDENT>if not hasattr(cls, '<STR_LIT>'):<EOL><INDENT>if perm_type is None or path_fields is None or actions is None:<EOL><INDENT>raise DecoratorException(<EOL>'<STR_LIT>',<EOL>("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL>)<EOL><DEDENT>added = True<EOL>cls.TutelaryMeta = type('<STR_LIT>', (object,),<EOL>dict(perm_type=perm_type,<EOL>path_fields=path_fields,<EOL>actions=actions))<EOL><DEDENT>cls.TutelaryMeta.pfs = ([cls.TutelaryMeta.perm_type] +<EOL>get_path_fields(cls))<EOL>perms_objs = {}<EOL>for a in cls.TutelaryMeta.actions:<EOL><INDENT>an = a<EOL>ap = {}<EOL>if isinstance(a, tuple):<EOL><INDENT>an = a[<NUM_LIT:0>]<EOL>ap = a[<NUM_LIT:1>]<EOL><DEDENT>Action.register(an)<EOL>if isinstance(ap, dict) and '<STR_LIT>' in ap:<EOL><INDENT>po = ap['<STR_LIT>']<EOL>if po is not None:<EOL><INDENT>try:<EOL><INDENT>t = cls._meta.get_field(po).__class__<EOL>if t not in [models.ForeignKey,<EOL>models.OneToOneField]:<EOL><INDENT>raise PermissionObjectException(po)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>raise PermissionObjectException(po)<EOL><DEDENT><DEDENT>perms_objs[an] = po<EOL><DEDENT><DEDENT>if len(perms_objs) == <NUM_LIT:0>:<EOL><INDENT>cls.get_permissions_object = get_perms_object<EOL><DEDENT>else:<EOL><INDENT>cls.get_permissions_object = make_get_perms_object(perms_objs)<EOL><DEDENT>return cls<EOL><DEDENT>except:<EOL><INDENT>if added:<EOL><INDENT>del cls.TutelaryMeta<EOL><DEDENT>raise<EOL><DEDENT>
Function to set up a model for permissioning.  Can either be called
    directly, passing a class and suitable values for ``perm_type``,
    ``path_fields`` and ``actions``, or can be used as a class
    decorator, taking values for ``perm_type``, ``path_fields`` and
    ``actions`` from the ``TutelaryMeta`` subclass of the decorated
    class.