示例#1
0
def autodiscover():
    """
    Check all apps in INSTALLED_APPS for stuff related to autocomplete_light.

    For each app, autodiscover imports ``app.autocomplete_light_registry`` if
    possing, resulting in execution of :py:func:`register()` statements in that
    module, filling up :py:data:`registry`.

    Consider a standard app called ``cities_light`` with such a structure::

        cities_light/
            __init__.py
            models.py
            urls.py
            views.py
            autocomplete_light_registry.py

    Where autocomplete_light_registry.py contains something like::

        from models import City, Country
        import autocomplete_light
        autocomplete_light.register(City)
        autocomplete_light.register(Country)

    When ``autodiscover()`` imports
    ``cities_light.autocomplete_light_registry``, both ``CityAutocomplete`` and
    ``CountryAutocomplete`` will be registered. See
    :py:meth:`AutocompleteRegistry.register()` for details on how these
    autocomplete classes are generated.
    """
    if autodiscover_modules:
        autodiscover_modules('autocomplete_light_registry')
    else:
        _autodiscover(registry)
示例#2
0
    def test_autodiscover_modules_several_found_with_registry(self):
        from .test_module import site

        autodiscover_modules("good_module",
                             "another_good_module",
                             register_to=site)
        self.assertEqual(site._registry, {"lorem": "ipsum"})
示例#3
0
def autodiscover():
    import django
    if django.VERSION >= (1, 7):
        from django.utils.module_loading import autodiscover_modules
        autodiscover_modules('sequere_registry')
    else:
        _autodiscover(registry)
示例#4
0
 def test_validate_registry_resets_after_missing_module(self):
     from .test_module import site
     autodiscover_modules('does_not_exist',
                          'another_good_module',
                          'does_not_exist2',
                          register_to=site)
     self.assertEqual(site._registry, {'lorem': 'ipsum'})
示例#5
0
 def test_validate_registry_resets_after_erroneous_module(self):
     from .test_module import site
     with self.assertRaisesMessage(Exception, "Some random exception."):
         autodiscover_modules('another_good_module',
                              'another_bad_module',
                              register_to=site)
     self.assertEqual(site._registry, {'lorem': 'ipsum'})
示例#6
0
文件: run_huey.py 项目: coleifer/huey
    def handle(self, *args, **options):
        from huey.contrib.djhuey import HUEY

        consumer_options = {}
        try:
            if isinstance(settings.HUEY, dict):
                consumer_options.update(settings.HUEY.get('consumer', {}))
        except AttributeError:
            pass

        for key, value in options.items():
            if value is not None:
                consumer_options[key] = value

        consumer_options.setdefault('verbose',
                                    consumer_options.pop('huey_verbose', None))

        if not options.get('disable_autoload'):
            autodiscover_modules("tasks")

        config = ConsumerConfig(**consumer_options)
        config.validate()
        config.setup_logger()

        consumer = Consumer(HUEY, **config.values)
        consumer.run()
示例#7
0
    def ready(self):

        from django.apps import apps
        module_to_search = 'bindings'
        autodiscover_modules(module_to_search)
        # autodiscover bindings
        for app_config in apps.get_app_configs():
            try:
                module = import_module('%s.%s' %
                                       (app_config.name, module_to_search))
                try:
                    package_name = module.__name__
                    package_path = module.__path__[0]
                    for file in glob.glob(os.path.join(package_path, '*.py')):
                        filename = os.path.basename(file)
                        try:
                            module = import_module(
                                '%s.%s.%s' %
                                (app_config.name, module_to_search, filename))
                        except Exception as e:
                            pass
                except AttributeError as e:
                    print(e)
            except ModuleNotFoundError as e:
                pass
            except Exception as e:
                print(e)
示例#8
0
    def ready(self):
        super().ready()

        from django.conf import settings  # noqa

        # Autodiscover various modules defined by AlekSIS
        autodiscover_modules("form_extensions", "model_extensions", "checks")

        sitepreferencemodel = self.get_model("SitePreferenceModel")
        personpreferencemodel = self.get_model("PersonPreferenceModel")
        grouppreferencemodel = self.get_model("GroupPreferenceModel")

        preference_models.register(sitepreferencemodel,
                                   site_preferences_registry)
        preference_models.register(personpreferencemodel,
                                   person_preferences_registry)
        preference_models.register(grouppreferencemodel,
                                   group_preferences_registry)

        self._load_data_checks()

        from .health_checks import (
            BackupJobHealthCheck,
            DataChecksHealthCheckBackend,
            DbBackupAgeHealthCheck,
            MediaBackupAgeHealthCheck,
        )

        plugin_dir.register(DataChecksHealthCheckBackend)
        plugin_dir.register(DbBackupAgeHealthCheck)
        plugin_dir.register(MediaBackupAgeHealthCheck)
        plugin_dir.register(BackupJobHealthCheck)
示例#9
0
def autodiscover():
    """Auto-discovers files that should be found by fobi."""
    # For Python 3 we need to increase the recursion limit, otherwise things
    # break. What we want is to set the recursion limit back to its' initial
    # value after all plugins have been discovered.
    recursion_limit = 1500
    default_recursion_limit = sys.getrecursionlimit()

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(recursion_limit)

    FORM_ELEMENT_PLUGINS_MODULE_NAME = get_setting(
        'FORM_ELEMENT_PLUGINS_MODULE_NAME')
    FORM_HANDLER_PLUGINS_MODULE_NAME = get_setting(
        'FORM_HANDLER_PLUGINS_MODULE_NAME')
    THEMES_MODULE_NAME = get_setting('THEMES_MODULE_NAME')
    FORM_CALLBACKS_MODULE_NAME = get_setting('FORM_CALLBACKS_MODULE_NAME')

    FORM_IMPORTER_PLUGINS_MODULE_NAME = get_setting(
        'FORM_IMPORTER_PLUGINS_MODULE_NAME')

    # Discover modules
    autodiscover_modules(FORM_ELEMENT_PLUGINS_MODULE_NAME)
    autodiscover_modules(FORM_HANDLER_PLUGINS_MODULE_NAME)
    autodiscover_modules(THEMES_MODULE_NAME)
    autodiscover_modules(FORM_CALLBACKS_MODULE_NAME)

    # Do not yet discover form importers
    autodiscover_modules(FORM_IMPORTER_PLUGINS_MODULE_NAME)

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(default_recursion_limit)
示例#10
0
 def discover_menus(self):
     if self.discovered:
         return
     autodiscover_modules('cms_menus')
     from menus.modifiers import register
     register()
     self.discovered = True
示例#11
0
文件: apps.py 项目: xiaoqiangjoe/CRM
 def ready(self):
     '''
     有ready方法,django会执行ready方法
     目的:django在启动的时候就加载stark
     :return:
     '''
     autodiscover_modules('stark')
def autodiscover():
    """
    Check all apps in INSTALLED_APPS for stuff related to rules_light.

    For each app, autodiscover imports ``app.rules_light_registry`` if
    available, resulting in execution of ``rules_light.registry[...] = ...``
    statements in that module, filling registry.

    Consider a standard app called 'cities_light' with such a structure::

        cities_light/
            __init__.py
            models.py
            urls.py
            views.py
            rules_light_registry.py

    With such a rules_light_registry.py::

        import rules_light

        rules_light.register('cities_light.city.read', True)
        rules_light.register('cities_light.city.update',
            lambda user, rulename, country: user.is_staff)

    When autodiscover() imports cities_light.rules_light_registry, both
    `'cities_light.city.read'` and `'cities_light.city.update'` will be
    registered.
    """
    if autodiscover_modules:
        autodiscover_modules('rules_light_registry')
    else:
        _autodiscover(registry)
示例#13
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS autocompleters.py modules and fail silently when
    not present.
    NOTE: autodiscover was copied from django.contrib.admin autodiscover
    """
    autodiscover_modules('autocompleters')
示例#14
0
def autodiscover():
    """Auto-discovers files that should be found by fobi."""
    # For Python 3 we need to increase the recursion limit, otherwise things
    # break. What we want is to set the recursion limit back to its' initial
    # value after all plugins have been discovered.
    recursion_limit = 1500
    default_recursion_limit = sys.getrecursionlimit()

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(recursion_limit)

    importer_plugin_module_name = get_setting(
        'IMPORTER_PLUGIN_MODULE_NAME'
    )

    exporter_plugin_module_name = get_setting(
        'EXPORTER_PLUGIN_MODULE_NAME'
    )

    # Discover modules
    autodiscover_modules(importer_plugin_module_name)
    autodiscover_modules(exporter_plugin_module_name)

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(default_recursion_limit)
示例#15
0
    def handle(self, *args, **options):

        consumer_options = {}
        try:
            if isinstance(settings.HUEY, dict):
                consumer_options.update(settings.HUEY.get('consumer', {}))
        except AttributeError:
            pass

        for key, value in options.items():
            if value is not None:
                consumer_options[key] = value

        consumer_options.setdefault('verbose',
                                    consumer_options.pop('huey_verbose', None))

        autodiscover_modules("tasks")

        huey_queue = settings.HUEY_QUEUES[options["queue"]]
        #del options["queue"]

        config = ConsumerConfig(**consumer_options)
        config.validate()
        config.setup_logger()

        consumer = Consumer(huey_queue, **config.values)
        logger.info("The following tasks are available for this queue:")
        for command in consumer.huey.registry._registry:
            logger.info(command.replace('queue_task_', ''))
        consumer.run()
示例#16
0
文件: run_huey.py 项目: yijxiang/huey
    def handle(self, *args, **options):
        from huey.contrib.djhuey import HUEY

        consumer_options = {}
        try:
            if isinstance(settings.HUEY, dict):
                consumer_options.update(settings.HUEY.get('consumer', {}))
        except AttributeError:
            pass

        for key, value in options.items():
            if value is not None:
                consumer_options[key] = value

        consumer_options.setdefault('verbose',
                                    consumer_options.pop('huey_verbose', None))

        if not options.get('disable_autoload'):
            autodiscover_modules("tasks")

        logger = logging.getLogger('huey')

        config = ConsumerConfig(**consumer_options)
        config.validate()

        # Only configure the "huey" logger if it has no handlers. For example,
        # some users may configure the huey logger via the Django global
        # logging config. This prevents duplicating log messages:
        if not logger.handlers:
            config.setup_logger(logger)

        consumer = Consumer(HUEY, **config.values)
        consumer.run()
示例#17
0
    def get_indexers(self, **options):
        autodiscover_modules('indexers')
        indexers = []
        if options['daily']:
            return DAILY_INDEXERS
        elif len(options['app']):
            indexer_names = self._get_indexer_names_from_args(options['app'])
        elif options['from_file']:
            indexer_names = self._get_indexer_names_from_json(
                options['from_file'])
        else:
            return indexer_klasses

        for indexer_name, doc_types in indexer_names.items():
            list_indexer = indexer_klasses_map[indexer_name]
            if '*' in doc_types:
                indexers += list(list_indexer)
                continue
            for doc_type in doc_types:
                indexers += [
                    idx for idx in list_indexer
                    if idx.doc_type_klass._doc_type.name == doc_type
                ]

        # Always ensure parent indexers to be index first
        return sorted(indexers,
                      key=lambda x:
                      (getattr(x, 'parent_doc_type_property', ''),
                       getattr(x, 'op_type', '')))
示例#18
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS autocompleters.py modules and fail silently when
    not present.
    NOTE: autodiscover was copied from django.contrib.admin autodiscover
    """
    autodiscover_modules('autocompleters')
示例#19
0
    def handle(self, *args, **options):
        queue_name = options['queue_name'][0]
        self.consumer_options = settings_reader.configurations[
            queue_name].consumer_options

        autodiscover_modules("tasks")
        self.run_consumer(queue_name)
 def register_achievements(*args, **kwargs):
     try:
         from django.utils.module_loading import autodiscover_modules
         autodiscover_modules('achievements')
     except Exception as e:
         print e
         print "Maybe, you need to run migrations first"
示例#21
0
    def handle(self, *args, **options):
        from huey.contrib.djhuey import HUEY

        consumer_options = {}
        try:
            if isinstance(settings.HUEY, dict):
                consumer_options.update(settings.HUEY.get('consumer', {}))
        except AttributeError:
            pass

        for key, value in options.items():
            if value is not None:
                consumer_options[key] = value

        consumer_options.setdefault('verbose',
                                    consumer_options.pop('huey_verbose', None))

        autodiscover_modules("tasks")

        config = ConsumerConfig(**consumer_options)
        config.validate()
        config.setup_logger()

        consumer = Consumer(HUEY, **config.values)
        consumer.run()
def autodiscover():
    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        from .module_loading import autodiscover_modules

    autodiscover_modules('adapters', register_to=registry)
示例#23
0
def autodiscover(register_to, include_defaults=True):
    # Look through INSTALLED_APPS and import the admin module for
    # each one (if present).
    autodiscover_modules('admin', register_to=register_to)
    # Copy models registered to the default admin site.
    if include_defaults:
        register_to._registry.update(default_admin_site._registry)
示例#24
0
def autodiscover():
    """
    Auto discover notification registrations in any file called "notifications" in any app.
    """
    from django.utils.module_loading import autodiscover_modules

    autodiscover_modules('notifications', register_to=registry)
def autodiscover():
    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        from .module_loading import autodiscover_modules

    autodiscover_modules('upload', register_to=upload_handlers)
示例#26
0
def autodiscover():
    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        from .module_loading import autodiscover_modules

    autodiscover_modules('upload', register_to=upload_handlers)
示例#27
0
    def ready(self):
        from django.utils import module_loading

        for module_name in [
                'assets', 'fragments', 'markdown', 'rest_api', 'signals'
        ]:
            module_loading.autodiscover_modules(module_name)
示例#28
0
文件: apps.py 项目: new-789/git
 def ready(self):
     """
     定义此方法后表示会每次先加载 url 前执行每个应用中的
     stark 模块中的内容
     :return:
     """
     autodiscover_modules('stark')
示例#29
0
def autodiscover():
    """
    Auto discover notification registrations in any file called "notifications" in any app.
    """
    from django.utils.module_loading import autodiscover_modules

    autodiscover_modules('notifications', register_to=registry)
示例#30
0
def autodiscover():
    # look for "components" module/pkg in each app
    from . import app_settings

    if app_settings.AUTODISCOVER:
        autodiscover_modules("components")
    for path in app_settings.LIBRARIES:
        import_module(path)
示例#31
0
    def test_validate_registry_resets_after_missing_module(self):
        from .test_module import site

        autodiscover_modules("does_not_exist",
                             "another_good_module",
                             "does_not_exist2",
                             register_to=site)
        self.assertEqual(site._registry, {"lorem": "ipsum"})
示例#32
0
def discover(app):
    autodiscover_modules('resources', register_to=app)

    if settings.AUTH_RESOURCES:
        from shanghai.contrib.auth.resources import GroupResource, UserResource

        app.register(GroupResource)
        app.register(UserResource)
示例#33
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS admin.py modules and fail silently when
    not present. This forces an import on them to register any admin bits they
    may want.
    """

    autodiscover_modules('importers', register_to=importer_site)
示例#34
0
 def ready(self):
     from djcelery.models import PeriodicTask, TaskState, WorkerState
     administration.register(TaskState, icon='Edit-check-sheet.png')
     administration.register(PeriodicTask,
                             parent=TaskState,
                             icon='Appointment.png')
     administration.register(WorkerState, parent=TaskState, dashboard=False)
     autodiscover_modules('tasks')
示例#35
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS' gargoyle modules and fail silently when
    not present. This forces an import on them to register any gargoyle bits they
    may want.
    """
    import gargoyle.builtins  # noqa
    autodiscover_modules('gargoyle')
示例#36
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS' gargoyle modules and fail silently when
    not present. This forces an import on them to register any gargoyle bits they
    may want.
    """
    import gargoyle.builtins  # noqa
    autodiscover_modules('gargoyle')
示例#37
0
    def load_channels(self):
        """
        Called when loading the application. Cannot be called a second time,
        (eg. for testing) as Django will not re-import and re-register anything.
        """
        autodiscover_modules('lookups')

        if hasattr(settings, 'AJAX_LOOKUP_CHANNELS'):
            self.register(settings.AJAX_LOOKUP_CHANNELS)
示例#38
0
def autodiscover():
    import django

    if django.VERSION >= (1, 7):
        from django.utils.module_loading import autodiscover_modules

        autodiscover_modules("sequere_registry")
    else:
        _autodiscover(registry)
示例#39
0
    def ready(self):
        super().ready()
        """
        Import signals to start listening for events
        """
        autodiscover_modules('feed_handlers')

        if not settings.TESTING:
            from .signals import post_save_callback, post_delete_callback  # noqa
示例#40
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS admin.py modules and fail silently when not present.

    This forces an import on them to register any admin bits they may want.
    """
    from django.utils.module_loading import autodiscover_modules
    from health_check.plugins import plugin_dir

    autodiscover_modules('plugin_health_check', register_to=plugin_dir)
def autodiscover():
    """Import all INSTALLED_APPS notifications.py modules."""
    if django.VERSION >= (1, 7):
        from django.utils.module_loading import autodiscover_modules
        autodiscover_modules('notifications')
    else:
        for app in settings.INSTALLED_APPS:
            try:
                import_module('%s.notifications' % app)
            except ImportError:
                pass
示例#42
0
    def load_channels(self):
        self._registry = {}
        try:
            from django.utils.module_loading import autodiscover_modules
        except ImportError:
            pass
        else:
            autodiscover_modules("lookups")

        if hasattr(settings, "AJAX_LOOKUP_CHANNELS"):
            self.register(settings.AJAX_LOOKUP_CHANNELS)
示例#43
0
def autodiscover_socketios():
    """
    Auto-discover INSTALLED_APPS sockets.py modules and fail silently when
    not present. NOTE: socketio_autodiscover was inspired/copied from
    django.contrib.admin autodiscover
    """
    global LOADING_SOCKETIO
    if LOADING_SOCKETIO:
        return
    LOADING_SOCKETIO = True

    autodiscover_modules('events')
    LOADING_SOCKETIO = False
示例#44
0
def autodiscover():
    autodiscover_modules('admin',register_to=site)

    for m in Page.get_content_models():
        try:
            adm = site._registry[m]
        except KeyError:
            continue

        if not isinstance(adm, PageAdmin) and isinstance(adm, mezz_PageAdmin):
            if site.safe_unregister(m):
                site.register(m, PageAdmin)

    site.lazy_registration()
示例#45
0
文件: discover.py 项目: 18dubu/MMS
def autodiscover():
    """
    Autodiscovers files that should be found by fobi.
    """
    FORM_ELEMENT_PLUGINS_MODULE_NAME = get_setting(
        'FORM_ELEMENT_PLUGINS_MODULE_NAME'
        )
    FORM_HANDLER_PLUGINS_MODULE_NAME = get_setting(
        'FORM_HANDLER_PLUGINS_MODULE_NAME'
        )
    THEMES_MODULE_NAME = get_setting(
        'THEMES_MODULE_NAME'
        )
    FORM_CALLBACKS_MODULE_NAME = get_setting(
        'FORM_CALLBACKS_MODULE_NAME'
        )

    #FORM_IMPORTER_PLUGINS_MODULE_NAME = get_setting(
    #    'FORM_IMPORTER_PLUGINS_MODULE_NAME'
    #    )

    # Discover modules
    autodiscover_modules(FORM_ELEMENT_PLUGINS_MODULE_NAME)
    autodiscover_modules(FORM_HANDLER_PLUGINS_MODULE_NAME)
    autodiscover_modules(THEMES_MODULE_NAME)
    autodiscover_modules(FORM_CALLBACKS_MODULE_NAME)
    def get_dashboards(self):
        cls = self.__class__
        if not cls.autodiscovered:
            cls.autodiscovered = True
            autodiscover_modules('dashboards', register_to=cls)

        dashboards = cls._registry
        if self.slug:
            dashboards = filter(lambda d: d.slug == self.slug, dashboards)
        dashboards = filter(lambda d: d.enabled, map(lambda d: d(view=self), dashboards))
        dashboards = sorted(dashboards, key=lambda dashboard: dashboard.priority, reverse=True)
        if not dashboards:
            raise Http404('No enabled dashboards')
        return dashboards
示例#47
0
    def load_channels(self):
        """
        Called when loading the application. Cannot be called a second time,
        (eg. for testing) as Django will not re-import and re-register anything.
        """
        self._registry = {}
        try:
            from django.utils.module_loading import autodiscover_modules
        except ImportError:
            pass
        else:
            autodiscover_modules('lookups')

        if hasattr(settings, 'AJAX_LOOKUP_CHANNELS'):
            self.register(settings.AJAX_LOOKUP_CHANNELS)
    def handle(self, *args, **options):
        force = options['force']

        _prepare_metadir()

        autodiscover_modules('restapi')

        from application.restapi import RestApi
        for name, cls in RestApi._registry.items():
            rname = cls.__class__.__name__.replace('Resource', '')
            endpoint = RestApi._build_reverse_url("api_dispatch_list", kwargs={
                'api_name': RestApi.api_name,
                'resource_name': name,
                })
            _gen_meta(rname, cls, endpoint)
            _gen_model(rname, force)
示例#49
0
def load():
    """
    Load ``cron`` modules for applications listed in ``INSTALLED_APPS``.
    """
    autodiscover_modules('cron')

    if '.' in PROJECT_MODULE.__name__:
        try:
            import_module('%s.cron' % '.'.join(
	            PROJECT_MODULE.__name__.split('.')[0:-1]))
        except ImportError as e:
            if 'No module named' not in str(e):
                print(e)

    # load django tasks
    for cmd, app in get_commands().items():
        try:
            load_command_class(app, cmd)
        except django.core.exceptions.ImproperlyConfigured:
            pass
示例#50
0
def autodiscover():
    from django.conf import settings

    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        from django.utils.importlib import import_module
        from django.utils.module_loading import module_has_submodule
        autodiscover_modules = None

    if autodiscover_modules:
        autodiscover_modules('restapi')
    else:
        for app in settings.INSTALLED_APPS:
            mod = import_module(app)
            try:
                import_module('%s.restapi' % app)
            except:
                if module_has_submodule(mod, 'restapi'):
                    raise
示例#51
0
def autodiscover():
    """
    Auto-discovers files that should be found by fobi.
    """
    # For Python 3 we need to increase the recursion limit, otherwise things
    # break. What we want is to set the recursion limit back to its' initial
    # value after all plugins have been discovered.
    recursion_limit = 1500
    default_recursion_limit = sys.getrecursionlimit()

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(recursion_limit)

    FORM_ELEMENT_PLUGINS_MODULE_NAME = get_setting(
        'FORM_ELEMENT_PLUGINS_MODULE_NAME'
        )
    FORM_HANDLER_PLUGINS_MODULE_NAME = get_setting(
        'FORM_HANDLER_PLUGINS_MODULE_NAME'
        )
    THEMES_MODULE_NAME = get_setting(
        'THEMES_MODULE_NAME'
        )
    FORM_CALLBACKS_MODULE_NAME = get_setting(
        'FORM_CALLBACKS_MODULE_NAME'
        )

    FORM_IMPORTER_PLUGINS_MODULE_NAME = get_setting(
        'FORM_IMPORTER_PLUGINS_MODULE_NAME'
        )

    # Discover modules
    autodiscover_modules(FORM_ELEMENT_PLUGINS_MODULE_NAME)
    autodiscover_modules(FORM_HANDLER_PLUGINS_MODULE_NAME)
    autodiscover_modules(THEMES_MODULE_NAME)
    autodiscover_modules(FORM_CALLBACKS_MODULE_NAME)

    # Do not yet discover form importers
    autodiscover_modules(FORM_IMPORTER_PLUGINS_MODULE_NAME)

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(default_recursion_limit)
示例#52
0
def steal_registrations_from_stock_admin_site():
    """Steals all the registrations from the admin site and reregisters them here

    Lots of things register with the standard admin page automatically when the
    autodiscovery is called. This is great ... except when using a custom
    AdminSite. There doesn't seem to be a clean way to do this The Right Way,
    so this hack is in place. This lets them all do their registration thing,
    then unregisters them from the stock admin and re-registers them here.

    """
    autodiscover_modules('admin')

    for k,v in admin.site._registry.copy().items():
        try:
            admin.site.unregister(k)
        except admin.sites.NotRegistered:
            pass # Alright. We were stealing them anyhow
        try:
            admin_site.register(k,type(v))
        except admin.sites.AlreadyRegistered:
            pass # Also alright. No honor amongst thieves
示例#53
0
def autodiscover():
    """
    Auto-discover INSTALLED_APPS imagegenerators.py modules and fail silently
    when not present. This forces an import on them to register any admin bits
    they may want.

    Copied from django.contrib.admin
    """
    global _autodiscovered

    if _autodiscovered:
        return

    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        # Django<1.7
        _autodiscover_modules_fallback()
    else:
        autodiscover_modules('imagegenerators')
    _autodiscovered = True
示例#54
0
def autodiscover():
    """Auto-discovers files that should be found by dash."""
    # For Python 3 we need to increase the recursion limit, otherwise things
    # break. What we want is to set the recursion limit back to its' initial
    # value after all plugins have been discovered.
    recursion_limit = 1500
    default_recursion_limit = sys.getrecursionlimit()

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(recursion_limit)

    PLUGINS_MODULE_NAME = get_setting('PLUGINS_MODULE_NAME')
    LAYOUTS_MODULE_NAME = get_setting('LAYOUTS_MODULE_NAME')

    # Discover plugins
    autodiscover_modules(PLUGINS_MODULE_NAME)

    # Discover layouts
    autodiscover_modules(LAYOUTS_MODULE_NAME)

    if six.PY3 and recursion_limit > default_recursion_limit:
        sys.setrecursionlimit(default_recursion_limit)
示例#55
0
def autodiscover():

    import copy
    from django.conf import settings
    
    try:
        from django.utils.module_loading import autodiscover_modules
    except ImportError:
        from django.utils.importlib import import_module
        from django.utils.module_loading import module_has_submodule

        def autodiscover_modules(submod, **kwargs):
            for app_name in settings.INSTALLED_APPS:
                mod = import_module(app_name)
                try:
                    before_import_registry = copy.copy(registry._registry)
                    import_module('%s.lookups' % app_name)
                except:
                    registry._registry = before_import_registry
                    if module_has_submodule(mod, 'lookups'):
                        raise

    # Attempt to import the app's lookups module.
    autodiscover_modules('lookups', register_to=registry)
from pdc.apps.utils.SortedRouter import router
from django.utils.module_loading import autodiscover_modules

from pdc.apps.release.views import ReleaseListView, ReleaseDetailView
from pdc.apps.release.views import BaseProductListView, BaseProductDetailView
from pdc.apps.release.views import ProductListView, ProductDetailView
from pdc.apps.release.views import ProductVersionListView, ProductVersionDetailView
from pdc.apps.compose.views import ComposeListView, ComposeDetailView
from pdc.apps.compose.views import ComposeRPMListView, RPMOverrideFormView, ComposeImageListView
from pdc.apps.changeset.views import ChangesetListView, ChangesetDetailView
from pdc.apps.common import views as common_views
from pdc.apps.auth import views as auth_views
from pdc.apps.release import views as release_views


autodiscover_modules('routers')

urlpatterns = [
    url(r'^$', common_views.home, name='home'),

    # see details about configuring kerberos authentication in utils/auth.py
    url(r'^auth/krb5login$', auth_views.remoteuserlogin, name='auth/krb5login'),
    url(r'^auth/saml2login$', auth_views.remoteuserlogin, name='auth/saml2login'),
    url(r'^auth/logout$', auth_views.logout, name='auth/logout'),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^auth/profile/$', auth_views.user_profile, name='auth/profile'),
    url(r'^auth/refresh-ldap/$', auth_views.refresh_ldap_groups,
        name='auth/refresh_ldap'),

    url(r"^compose/$", ComposeListView.as_view(), name="compose/index"),
示例#57
0
def autodiscover():
    if django.VERSION < (1, 7):
        old_autodiscover()
    else:
        from django.utils.module_loading import autodiscover_modules
        autodiscover_modules('tools', register_to=tools)