def collect_indexes(self):
        indexes = []

        for app_mod in haystack_get_app_modules():
            try:
                search_index_module = importlib.import_module(
                    "%s.search_indexes" % app_mod.__name__)
            except ImportError:
                if module_has_submodule(app_mod, "search_indexes"):
                    raise

                continue

            for item_name, item in inspect.getmembers(search_index_module,
                                                      inspect.isclass):
                if getattr(item, "haystack_use_for_indexing",
                           False) and getattr(item, "get_model", None):
                    # We've got an index. Check if we should be ignoring it.
                    class_path = "%s.search_indexes.%s" % (app_mod.__name__,
                                                           item_name)

                    if class_path in self.excluded_indexes or self.excluded_indexes_ids.get(
                            item_name) == id(item):
                        self.excluded_indexes_ids[str(item_name)] = id(item)
                        continue

                    indexes.append(item())

        return indexes
Beispiel #2
0
    def collect_indexes(self):
        indexes = []

        for app_mod in haystack_get_app_modules():
            try:
                search_index_module = importlib.import_module(
                    "%s.search_indexes" % app_mod.__name__
                )
            except ImportError:
                if module_has_submodule(app_mod, "search_indexes"):
                    raise

                continue

            for item_name, item in inspect.getmembers(
                search_index_module, inspect.isclass
            ):
                if getattr(item, "haystack_use_for_indexing", False) and getattr(
                    item, "get_model", None
                ):
                    # We've got an index. Check if we should be ignoring it.
                    class_path = "%s.search_indexes.%s" % (app_mod.__name__, item_name)

                    if class_path in self.excluded_indexes or self.excluded_indexes_ids.get(
                        item_name
                    ) == id(
                        item
                    ):
                        self.excluded_indexes_ids[str(item_name)] = id(item)
                        continue

                    indexes.append(item())

        return indexes
Beispiel #3
0
    def _collect_indexes(self):
        """
        Partial duplicates UnifiedIndex.collect_indexes()
        """
        from haystack.utils.app_loading import haystack_get_app_modules
        all_indexes = []
        for app_mod in haystack_get_app_modules():
            try:
                search_index_module = importlib.import_module("%s.search_indexes" % app_mod.__name__)
            except ImportError:
                if module_has_submodule(app_mod, 'search_indexes'):
                    raise
                continue

            for item_name, item in inspect.getmembers(search_index_module, inspect.isclass):
                if getattr(item, 'haystack_use_for_indexing', False) and getattr(item, 'get_model', None):
                    # We've got an index. Check if we should be ignoring it.
                    class_path = "%s.search_indexes.%s" % (app_mod.__name__, item_name)
                    all_indexes.append(class_path)
        return all_indexes
Beispiel #4
0
    def test_get_app_modules(self):
        app_modules = app_loading.haystack_get_app_modules()
        self.assertIsInstance(app_modules, (list, GeneratorType))

        for i in app_modules:
            self.assertIsInstance(i, ModuleType)
    def test_get_app_modules(self):
        app_modules = app_loading.haystack_get_app_modules()
        self.assertIsInstance(app_modules, (list, GeneratorType))

        for i in app_modules:
            self.assertIsInstance(i, ModuleType)