#NEWLINE# def permissions_save_override( permittee_kw , model_func , create_perm , edit_perm , delete_perm ) : #NEWLINE# #INDENT# 'Get a save function that can be used to enforce create, edit, and\n    delete permissions.\n    \n    For example::\n    \n        class ModelX(models.Model):\n            ...\n            save = permissions_save_override(\n                "user", lambda: ModelX, "can_create", "can_edit", "can_delete")\n            \n    @param permittee_kw: the keyword used to store the permittee in\n        threadlocals\n    @type permittee_kw: C{str}.\n    @param model_func: A callable that returns the the class.\n    @type model_func: C{Model} subclass\n    @param create_perm: The name of the creation permission for the class.\n    @type create_perm: C{str}\n    @param edit_perm: The name of the edit permission for the instance.\n    @type edit_perm: C{str}\n    @param delete_perm: the name of the delete permission for the instance.\n    @type delete_perm: C{str}\n    @return: a save function that can be used to enforce permissions.\n    @rtype: a callable.\n    ' #NEWLINE# def save( self , * args , **kwargs ) : #NEWLINE# #INDENT# '\n        Override the default save method to enforce permissions.\n        ' #NEWLINE# pk = getattr ( self , 'pk' , None ) #NEWLINE# if ( not pk ) : #NEWLINE# #INDENT# must_have_permission ( permittee_kw , model_func ( ) , create_perm ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# must_have_permission ( permittee_kw , self , edit_perm ) #NEWLINE# #UNINDENT# super ( model_func ( ) , self ) . save ( * args , ** kwargs ) #NEWLINE# if ( not pk ) : #NEWLINE# #INDENT# d = threadlocals . get_thread_locals ( ) #NEWLINE# give_permission_to ( edit_perm , self , d [ permittee_kw ] , can_delegate = True ) #NEWLINE# give_permission_to ( delete_perm , self , d [ permittee_kw ] , can_delegate = True ) #NEWLINE# #UNINDENT# #UNINDENT# return save