

def get_roles(user, obj):
    '\n    Get a list of roles assigned to a user for a specific instance from the\n    cache, or builds such a list if it is not found.\n    '
    roles = cache.get(roles_key(user, obj))
    if isinstance(roles, list):
        return roles
    else:
        user_roles = []
        if (not hasattr(obj, 'relevant_roles')):
            raise RulesException(('Cannot build roles cache for %s instance. Did you forget to                 define a "relevant_roles()" method on %s?' % (obj.__class__, obj.__class__)))
        relevant = obj.relevant_roles()
        for role in relevant:
            if role.is_member(user, obj):
                user_roles.append(role)
        cache.set(roles_key(user, obj), user_roles, (1 * HOUR))
        return user_roles

dataset/ETHPy150Open chrisglass/django-rulez/rulez/rolez/cache_helper.py get_roles/original