def handle(self, *args, **options):
        from djangosphinx.utils.config import generate_config_for_model, generate_sphinx_config

        model_classes = []
        if options['find_all']:
            model_classes = itertools.chain(*(models.get_models(app) for app in models.get_apps()))
        elif len(args):
            app_list = [models.get_app(app_label) for app_label in args]
            for app in app_list:
                model_classes.extend([ getattr(app, n) for n in dir(app) if hasattr(getattr(app, n), '_meta')])
        else:
            raise CommandError("You must specify an app name or use --all")

        found = 0
        for model in model_classes:
            if getattr(model._meta, 'proxy', False) or getattr(model._meta, 'abstract', False):
                continue
            indexes = getattr(model, '__sphinx_indexes__', [])
            for index in indexes:
                found += 1
                print generate_config_for_model(model, index)
        if not found:
            raise CommandError("Unable to find any models in application which use standard SphinxSearch configuration.")

        print generate_sphinx_config()
 def handle_app(self, app, **options):
     from djangosphinx.utils.config import generate_config_for_model
     model_classes = [getattr(app, n) for n in dir(app) if hasattr(getattr(app, n), '_meta')]
     found = 0
     for model in model_classes:
         indexes = getattr(model, '__sphinx_indexes__', [])
         for index in indexes:
             found += 1
             print generate_config_for_model(model, index)
     if found == 0:
         print "Unable to find any models in application which use standard SphinxSearch configuration."
Exemplo n.º 3
0
 def handle_app(self, app, **options):
     from djangosphinx.utils.config import generate_config_for_model
     model_classes = [
         getattr(app, n) for n in dir(app)
         if hasattr(getattr(app, n), '_meta')
     ]
     found = 0
     for model in model_classes:
         indexes = getattr(model, '__sphinx_indexes__', [])
         for index in indexes:
             found += 1
             print generate_config_for_model(model, index)
     if found == 0:
         print "Unable to find any models in application which use standard SphinxSearch configuration."
    def handle(self, *args, **options):
        from djangosphinx.utils.config import generate_config_for_model, generate_sphinx_config

        output = []

        # warn the user to remove SPHINX_API_VERSION, because we no longer pull from bundled apis
        if getattr(settings, 'SPHINX_API_VERSION', None) is not None:
            raise CommandError("SPHINX_API_VERSION is deprecated, please use pip for installing the appropriate Sphinx API.")

        model_classes = []
        if options['find_all']:
            model_classes = itertools.chain(*(models.get_models(app) for app in models.get_apps()))
        elif len(args):
            app_list = [models.get_app(app_label) for app_label in args]
            for app in app_list:
                model_classes.extend([getattr(app, n) for n in dir(app) if hasattr(getattr(app, n), '_meta')])
        else:
            raise CommandError("You must specify an app name or use --all")

        found = 0
        for model in model_classes:
            if getattr(model._meta, 'proxy', False) or getattr(model._meta, 'abstract', False):
                continue
            indexes = getattr(model, '__sphinx_indexes__', [])

            for index in indexes:
                found += 1
                output.append(generate_config_for_model(model, index))

        if found == 0:
            raise CommandError("Unable to find any models in application which use standard SphinxSearch configuration.")

        output.append(generate_sphinx_config())

        print ('\n'.join(output))
    def handle(self, *args, **options):
        from djangosphinx.utils.config import generate_config_for_model, generate_sphinx_config

        model_classes = []
        if options['find_all']:
            model_classes = itertools.chain(*(models.get_models(app) for app in models.get_apps()))
        elif len(args):
            app_list = [models.get_app(app_label) for app_label in args]
            for app in app_list:
                model_classes.extend([ getattr(app, n) for n in dir(app) if hasattr(getattr(app, n), '_meta')])
        else:
            raise CommandError("You must specify an app name or use --all")

        unsafe_options = []
        def _optionsAreSafe(options):
            try:
                options['excluded_fields'] and options['included_fields']
                unsafe_options.append(['excluded_fields', 'included_fields'])
                return False
            except:
                return True

        found = 0
        for model in model_classes:
            if getattr(model._meta, 'proxy', False) or getattr(model._meta, 'abstract', False):
                continue
            indexes = getattr(model, '__sphinx_indexes__', [])
            if _optionsAreSafe(getattr(model, '__sphinx_options__', None)):
                for index in indexes:
                    found += 1
                    print generate_config_for_model(model, index)
            else:
                raise CommandError("Unsafe options for model '%s': %s" % (model.__name__, [u for u in unsafe_options[0]]))
        if found == 0:
            raise CommandError("Unable to find any models in application which use standard SphinxSearch configuration.")

        print generate_sphinx_config()
    def handle(self, *args, **options):
        from djangosphinx.utils.config import generate_config_for_model, generate_sphinx_config

        output = []

        # warn the user to remove SPHINX_API_VERSION, because we no longer pull from bundled apis
        if getattr(settings, 'SPHINX_API_VERSION', None) is not None:
            raise CommandError(
                "SPHINX_API_VERSION is deprecated, please use pip for installing the appropriate Sphinx API."
            )

        model_classes = []
        if options['find_all']:
            model_classes = itertools.chain(*(models.get_models(app)
                                              for app in models.get_apps()))
        elif len(args):
            app_list = [models.get_app(app_label) for app_label in args]
            for app in app_list:
                model_classes.extend([
                    getattr(app, n) for n in dir(app)
                    if hasattr(getattr(app, n), '_meta')
                ])
        else:
            raise CommandError("You must specify an app name or use --all")

        found = 0
        for model in model_classes:
            if getattr(model._meta, 'proxy', False) or getattr(
                    model._meta, 'abstract', False):
                continue
            indexes = getattr(model, '__sphinx_indexes__', [])

            for index in indexes:
                found += 1
                output.append(generate_config_for_model(model, index))

        if found == 0:
            raise CommandError(
                "Unable to find any models in application which use standard SphinxSearch configuration."
            )

        output.append(generate_sphinx_config())

        print('\n'.join(output))