

def assign(self, permission, user_or_group, obj=None):
    '\n        Assigns the given permission to the given user or group, and returns\n        the AssignedPermission instance.\n        \n        If an object is given, assigns the permission for that object.\n        '
    (perm, ct) = self.get_permission_and_content_type(permission, obj)
    assigned_dict = {
        'permission': perm,
        'content_type': ct,
        'object_id': None,
    }
    if obj:
        assigned_dict['object_id'] = obj.id
    if isinstance(user_or_group, User):
        assigned_dict['user'] = user_or_group
    elif isinstance(user_or_group, Group):
        assigned_dict['group'] = user_or_group
    else:
        raise TypeError('Permissions must be assigned to a User or Group instance.')
    return AssignedPermission.objects.get_or_create(**assigned_dict)

dataset/ETHPy150Open jlecker/django-rubberstamp/rubberstamp/models.py AppPermissionManager.assign/original