Module Expr Str ImportFrom alias ImportFrom alias ImportFrom alias alias ImportFrom alias ImportFrom alias FunctionDef arguments args NameParam defaults vararg kwarg body Expr Str Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Str body Expr Str FunctionDef arguments args defaults vararg kwarg body If CompareEq Call NameLoad NameLoad NameLoad body Assign NameStore SubscriptLoad NameLoad Index NameLoad orelse Assign NameStore SubscriptLoad NameLoad Index NameLoad Return Call AttributeLoad AttributeLoad NameLoad attr attr Dict NameLoad NameLoad decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Str body Expr Str FunctionDef arguments args defaults vararg kwarg body If CompareEq Call NameLoad NameLoad NameLoad body Assign NameStore SubscriptLoad NameLoad Index NameLoad orelse Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Dict NameLoad NameLoad Assign NameStore Call NameLoad NameLoad If NameLoad body Assign NameStore ListComp AttributeLoad NameLoad attr comprehension NameStore NameLoad Return Call AttributeLoad AttributeLoad AttributeLoad Call AttributeLoad SubscriptLoad NameLoad Index Num attr attr attr attr keyword NameLoad Return NameLoad decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str FunctionDef arguments args defaults vararg kwarg body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return Call AttributeLoad AttributeLoad NameLoad attr attr keyword AttributeLoad NameLoad attr decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str FunctionDef arguments args defaults vararg kwarg body Return Call AttributeLoad AttributeLoad NameLoad attr attr keyword NameLoad decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str TryExcept body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr body Raise Call NameLoad TryExcept body Return Call AttributeLoad NameLoad attr keyword NameLoad handlers ExceptHandler type AttributeLoad Call AttributeLoad NameLoad attr attr body Raise Call NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam defaults vararg kwarg body Expr Str Assign NameStore Call NameLoad NameLoad Str NameLoad If UnaryOpNot NameLoad body Expr Call NameLoad NameLoad Call NameLoad NameLoad orelse Expr Call NameLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad Call NameLoad Call NameLoad NameLoad attr NameLoad NameLoad If UnaryOpNot NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Expr Call NameLoad NameLoad NameLoad SubscriptLoad NameLoad Index NameLoad keyword NameLoad Expr Call NameLoad NameLoad NameLoad SubscriptLoad NameLoad Index NameLoad keyword NameLoad decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam defaults vararg kwarg body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr Expr Call AttributeLoad Call NameLoad Call NameLoad NameLoad attr NameLoad NameLoad decorator_list Return NameLoad decorator_list
N/A N/A 
Created on Jun 1, 2010

@author: jnaous
 django.contrib.contenttypes.models ContentType django.http Http404 expedient.common.permissions.shortcuts must_have_permission give_permission_to expedient.common.middleware threadlocals expedient.common.permissions.models ObjectPermission get_user_from_req N/A N/A request N/A args kwargs N/A N/A 
    Get the user from the request. This function is helpful when
    using the require_*_permission_for_view decorators.

    For example::
    
        @require_objs_permissions_for_view(
            ["can_view_obj_detail"],
            get_user_from_req,
            get_objects_from_filter_func(Obj, 1),
            ["GET"],
        )
        def view_obj_detail(request, obj_id):
            ...
            
    @param request: the request object
    @type request: C{HttpRequest}
     N/A N/A request user N/A get_queryset N/A N/A klass index filter N/A pk N/A N/A 
    Returns a function that can be used for the require_*_permission_for_view
    decorators to get a queryset from some argument.
    
    The returned function has a signature (*args, **kwargs) and mainly does
    the following::
    
        klass.objects.filter(**{filter: arg})
        
    where C{arg} is obtained from the arguments. If C{index} is an
    C{int}, C{arg} is assumed to be positional. Otherwise, it is assumed to be
    a keyword.
    
    For example::
    
        @require_obj_permission_for_view(
            ["can_view_obj_detail"],
            get_user_from_req,
            get_queryset(Obj, 1),
            ["GET"],
        )
        def view_obj_detail(request, obj_id):
            ...
    
    @param klass: The class of the object to be returned.
    @type klass: class
    @param index: location of the id in the arguments when the arguments are
        given as (*args, **kwargs).
    @type index: C{int} for positional, hashable for keyword.
    @keyword filter: a filter to be used for obtaining the object.
    @type filter: C{str}
    
    @return: A callable that returns an object from (*args, **kwargs)
     wrapper N/A N/A N/A args kwargs N/A N/A N/A N/A type index int N/A N/A arg N/A args N/A index N/A N/A arg N/A kwargs N/A index N/A N/A N/A N/A klass objects filter N/A filter arg N/A N/A wrapper N/A get_leaf_queryset N/A N/A parent_klass index filter N/A pk N/A N/A 
    Same as L{get_queryset} but also calls the C{as_leaf_class} function
    on the first element in the queryset and returns a queryset with the
    returned object's class.
     wrapper N/A N/A N/A args kwargs N/A N/A N/A N/A type index int N/A N/A arg N/A args N/A index N/A N/A arg N/A kwargs N/A index N/A parent_qs N/A N/A N/A parent_klass objects filter N/A filter arg N/A parents N/A list parent_qs N/A parents N/A N/A ids N/A N/A p id N/A p parents N/A N/A N/A N/A N/A N/A N/A N/A parents N/A 0 as_leaf_class __class__ objects filter id__in ids N/A parent_qs N/A N/A wrapper N/A get_queryset_from_class N/A N/A klass N/A N/A N/A 
    Returns a function usable as the C{target_func} of the
    L{require_objs_permissions_for_view} decorator. The returned function
    returns the C{ContentType} queryset for a class. This can be used to
    enforce class level permissions on views.
     
    @param klass: the model class for which we want the queryset. 
     target_func N/A N/A N/A args kwargs N/A N/A ct N/A N/A N/A ContentType objects get_for_model klass N/A N/A N/A N/A ContentType objects filter pk N/A ct pk N/A N/A target_func N/A get_queryset_from_id N/A N/A klass id N/A N/A N/A 
    Returns a function usable as a C{target_func} parameter. The returned
    function returns a C{QuerySet} containing one object with the given C{id}.
    
    @param klass: the class of the queryset's model.
    @param id: the object's id.
     target_func N/A N/A N/A args kwargs N/A N/A N/A N/A N/A klass objects filter id id N/A N/A target_func N/A get_object_from_ids N/A N/A ct_id id N/A N/A N/A 
    Get an object from the ContentType id and from the object's id.
    
    @param ct_id: ContentType's id for the object class.
    @param id: object's id.
     N/A N/A N/A ct N/A N/A N/A ContentType objects get_for_id ct_id N/A N/A N/A N/A ContentType DoesNotExist N/A N/A N/A Http404 N/A N/A N/A N/A N/A ct get_object_for_this_type pk id N/A N/A N/A N/A N/A N/A ct model_class DoesNotExist N/A N/A N/A Http404 N/A permissions_save_override N/A N/A permittee_kw model_func create_perm edit_perm delete_perm N/A N/A N/A Get a save function that can be used to enforce create, edit, and
    delete permissions.
    
    For example::
    
        class ModelX(models.Model):
            ...
            save = permissions_save_override(
                "user", lambda: ModelX, "can_create", "can_edit", "can_delete")
            
    @param permittee_kw: the keyword used to store the permittee in
        threadlocals
    @type permittee_kw: C{str}.
    @param model_func: A callable that returns the the class.
    @type model_func: C{Model} subclass
    @param create_perm: The name of the creation permission for the class.
    @type create_perm: C{str}
    @param edit_perm: The name of the edit permission for the instance.
    @type edit_perm: C{str}
    @param delete_perm: the name of the delete permission for the instance.
    @type delete_perm: C{str}
    @return: a save function that can be used to enforce permissions.
    @rtype: a callable.
     save N/A N/A self N/A args kwargs N/A N/A 
        Override the default save method to enforce permissions.
         N/A pk N/A getattr self pk None N/A N/A pk N/A N/A N/A must_have_permission permittee_kw N/A model_func create_perm N/A N/A N/A must_have_permission permittee_kw self edit_perm N/A N/A N/A N/A super N/A model_func self save args kwargs N/A N/A pk N/A N/A d N/A N/A threadlocals get_thread_locals N/A N/A give_permission_to edit_perm self N/A d N/A permittee_kw can_delegate True N/A N/A give_permission_to delete_perm self N/A d N/A permittee_kw can_delegate True N/A N/A save N/A permissions_delete_override N/A N/A permittee_kw model_func delete_perm N/A N/A N/A Get a delete function that can be used to enforce
    delete permissions.
    
    For example::
    
        class ModelX(models.Model):
            ...
            delete = permissions_delete_override(
                "user", lambda: ModelX, "can_delete")
            
    @param permittee_kw: the keyword used to store the permittee in
        threadlocals
    @type permittee_kw: C{str}.
    @param model_func: A callable that returns the class.
    @type model_func: C{Model} subclass
    @param delete_perm: the name of the delete permission for the instance.
    @type delete_perm: C{str}
     delete N/A N/A self N/A args kwargs N/A N/A 
        Override the default delete method to enforce permissions.
         N/A N/A must_have_permission permittee_kw self delete_perm N/A N/A N/A N/A N/A N/A ObjectPermission objects filter_from_instance self delete N/A N/A N/A N/A super N/A model_func self delete args kwargs N/A N/A delete N/A