Python源码示例:django.apps.apps.get_containing_app_config()

示例1
def app(self):
        return apps.get_containing_app_config(type(self).__module__).name 
示例2
def type_def(self, type_def):
        if isinstance(type_def, str):
            type_def = import_string(type_def)

        if not issubclass(type_def, self.type_def_subclass):
            raise TypeError('type_def must be a subclass of {}'.format(self.type_def_subclass))

        # Import meta options from type_def
        with suppress(AttributeError):
            self.type_name = type_def.Meta.db_type
        with suppress(AttributeError):
            self.type_app_label = type_def.Meta.app_label

        if not self.type_app_label:
            # Determine app_label of enum being used
            app_config = apps.get_containing_app_config(type_def.__module__)
            if app_config is None:
                raise RuntimeError(
                    "type_def class doesn't declare an explicit app_label, and isn't"
                    " in an application in INSTALLED_APPS")
            self.type_app_label = app_config.label

        # Generate type_name if not already set
        if not self.type_name:
            self.type_name = '{app_label}_{type_subclass}_{type_name}'.format(
                app_label=self.type_app_label,
                type_subclass=self.type_def_subclass.__name__.lower(),
                type_name=type_def.__qualname__.lower())

        self._type_def = type_def 
示例3
def app(self):
        return apps.get_containing_app_config(type(self).__module__).name 
示例4
def app(self) -> str:
        return apps.get_containing_app_config(type(self).__module__).name 
示例5
def app(self):
        return apps.get_containing_app_config(type(self).__module__).name 
示例6
def app(self):
        return apps.get_containing_app_config(type(self).__module__).name 
示例7
def __init__(self, report):
        self._report = report
        module = self._report.__class__.__module__
        app_config = apps.get_containing_app_config(module)
        self._app_label = app_config.label
        self._object_name = self._report.__class__.__name__ 
示例8
def get_urls(self):
        urlpatterns = []

        for report in self._registry:
            app_name = apps.get_containing_app_config(report.__module__).name
            urlpatterns.append(
                url(r"^{0}/{1}/$".format(app_name.replace(".", "_"), report.__name__.lower()),
                    admin_site.admin_view(ReportView.as_view(report_class=report)),
                    name=camel_re.sub(r'\1_\2', report.__name__).lower()
                ))
        return urlpatterns 
示例9
def test_get_containing_app_config_apps_not_ready(self):
        """
        apps.get_containing_app_config() should raise an exception if
        apps.apps_ready isn't True.
        """
        apps.apps_ready = False
        try:
            with self.assertRaisesMessage(AppRegistryNotReady, "Apps aren't loaded yet"):
                apps.get_containing_app_config('foo')
        finally:
            apps.apps_ready = True 
示例10
def _add_django_meta_and_register_model(cls, klass, attrs, name):
        # Create the class.
        module = attrs.get('__module__')
        if not module:
            return klass

        new_class = klass
        attr_meta = attrs.pop('Meta', None)
        abstract = getattr(attr_meta, 'abstract', False)
        if not attr_meta:
            meta = getattr(new_class, 'Meta', None)
        else:
            meta = attr_meta

        if meta:
            meta.managed = False

        app_label = None

        # Look for an application configuration to attach the model to.
        app_config = apps.get_containing_app_config(module)

        if getattr(meta, 'app_label', None) is None:
            if app_config is None:
                if not abstract:
                    raise RuntimeError(
                        "Model class %s.%s doesn't declare an explicit "
                        "app_label and isn't in an application in "
                        "INSTALLED_APPS." % (module, name)
                    )

            else:
                app_label = app_config.label

        # Add _meta/Options attribute to the model
        new_class.add_to_class(
            '_meta', DjangoCassandraOptions(meta, app_label, cls=new_class))
        # Add manager to the model
        for manager_attr in _django_manager_attr_names:
            new_class.add_to_class(manager_attr, new_class.objects)
        # Register the model
        new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
        return new_class