Example #1
0
def filter_db_entity_interests(**options):
    """
        Filter db_entities by config_entity_keys and db_entity_keys options
    :param options:
    :return:
    """
    return DbEntityInterest.objects.filter(**compact_kwargs(
        config_entity__key__in=options.get('config_entity_keys'),
        db_entity__key__in=options.get('db_entity_keys')
    ))
Example #2
0
def filter_layers(**options):
    """
        Filter layers by config_entity_keys and db_entity_keys options
    :param options:
    :return:
    """
    return Layer.objects.filter(**compact_kwargs(
        presentation__config_entity__key__in=options.get('config_entity_keys'),
        db_entity_interest__db_entity__key__in=options.get('db_entity_keys')
    ))
Example #3
0
def filter_config_entities(**options):
    """
        Filter by 'limit_to_classes' ConfigEntity subclasses and by config_etnity_keys options
    :param options:
    :return:
    """

    global _CACHED_CONFIG_ENTITIES
    if not _CACHED_CONFIG_ENTITIES:
        old_debug = settings.DEBUG
        settings.DEBUG = True
        reset_queries()

        _cached_config_entities = ConfigEntity.objects.filter(deleted=False)

        # This assertion makes sure we aren't overly aggressive in
        # loading the initial ConfigEntity list. In a pinch, comment
        # this out.
        # TODO: Move this to a test.
        total_entities = len(_cached_config_entities)
        assert len(connection.queries) < total_entities*13, (
            "Got %d queries for %d config_entities " % (len(connection.queries), len(_cached_config_entities)))
        settings.DEBUG = old_debug

    # Make sure we only select ConfigEntities related to the current client
    client_region = Region.objects.get(key=settings.CLIENT)
    eligible_ids = map(lambda config_entity: config_entity.id,
                       [global_config_singleton(), client_region] + list(client_region.descendants()))
    config_entities = _cached_config_entities.filter(
        id__in=eligible_ids,
        **compact_kwargs(key__in=options.get('config_entity_keys'))
    )
    # config_entities = ConfigEntity.objects.filter(deleted=False).filter(
    #     **compact_kwargs(key__in=options.get('config_entity_keys')))
    result = sort_config_entities(
        filter(
            lambda config_entity: not options.get('limit_to_classes') or isinstance(config_entity, tuple(options.get('limit_to_classes'))),
            map(lambda config_entity: config_entity.subclassed, config_entities)
        )
    )

    return result