當前位置: 首頁>>代碼示例>>Python>>正文


Python serializers.sort_dependencies方法代碼示例

本文整理匯總了Python中django.core.serializers.sort_dependencies方法的典型用法代碼示例。如果您正苦於以下問題:Python serializers.sort_dependencies方法的具體用法?Python serializers.sort_dependencies怎麽用?Python serializers.sort_dependencies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.serializers的用法示例。


在下文中一共展示了serializers.sort_dependencies方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: serialize_db_to_string

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def serialize_db_to_string(self):
        """
        Serializes all data in the database into a JSON string.
        Designed only for test runner usage; will not handle large
        amounts of data.
        """
        # Build list of all apps to serialize
        from django.db.migrations.loader import MigrationLoader
        loader = MigrationLoader(self.connection)
        app_list = []
        for app_config in apps.get_app_configs():
            if (
                app_config.models_module is not None and
                app_config.label in loader.migrated_apps and
                app_config.name not in settings.TEST_NON_SERIALIZED_APPS
            ):
                app_list.append((app_config, None))

        # Make a function to iteratively return every object
        def get_objects():
            for model in serializers.sort_dependencies(app_list):
                if (not model._meta.proxy and model._meta.managed and
                        router.allow_migrate_model(self.connection.alias, model)):
                    queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
                    for obj in queryset.iterator():
                        yield obj
        # Serialize to a string
        out = StringIO()
        serializers.serialize("json", get_objects(), indent=None, stream=out)
        return out.getvalue() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:32,代碼來源:creation.py

示例2: serialize_db_to_string

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def serialize_db_to_string(self):
        """
        Serialize all data in the database into a JSON string.
        Designed only for test runner usage; will not handle large
        amounts of data.
        """
        # Build list of all apps to serialize
        from django.db.migrations.loader import MigrationLoader
        loader = MigrationLoader(self.connection)
        app_list = []
        for app_config in apps.get_app_configs():
            if (
                app_config.models_module is not None and
                app_config.label in loader.migrated_apps and
                app_config.name not in settings.TEST_NON_SERIALIZED_APPS
            ):
                app_list.append((app_config, None))

        # Make a function to iteratively return every object
        def get_objects():
            for model in serializers.sort_dependencies(app_list):
                if (model._meta.can_migrate(self.connection) and
                        router.allow_migrate_model(self.connection.alias, model)):
                    queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
                    yield from queryset.iterator()
        # Serialize to a string
        out = StringIO()
        serializers.serialize("json", get_objects(), indent=None, stream=out)
        return out.getvalue() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:31,代碼來源:creation.py

示例3: serialize_db_to_string

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def serialize_db_to_string(self):
        """
        Serializes all data in the database into a JSON string.
        Designed only for test runner usage; will not handle large
        amounts of data.
        """
        # Build list of all apps to serialize
        from django.db.migrations.loader import MigrationLoader
        loader = MigrationLoader(self.connection)
        app_list = []
        for app_config in apps.get_app_configs():
            if (
                app_config.models_module is not None and
                app_config.label in loader.migrated_apps and
                app_config.name not in settings.TEST_NON_SERIALIZED_APPS
            ):
                app_list.append((app_config, None))

        # Make a function to iteratively return every object
        def get_objects():
            for model in serializers.sort_dependencies(app_list):
                if (model._meta.can_migrate(self.connection) and
                        router.allow_migrate_model(self.connection.alias, model)):
                    queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
                    for obj in queryset.iterator():
                        yield obj
        # Serialize to a string
        out = StringIO()
        serializers.serialize("json", get_objects(), indent=None, stream=out)
        return out.getvalue() 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:32,代碼來源:creation.py

示例4: test_dependency_sorting

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting(self):
        """
        It doesn't matter what order you mention the models,  Store *must* be
        serialized before then Person, and both must be serialized before Book.
        """
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Book, Person, Store])]
        )
        self.assertEqual(
            sorted_deps,
            [Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:tests.py

示例5: test_dependency_sorting_2

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_2(self):
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Book, Store, Person])]
        )
        self.assertEqual(
            sorted_deps,
            [Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例6: test_dependency_sorting_3

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_3(self):
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Store, Book, Person])]
        )
        self.assertEqual(
            sorted_deps,
            [Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例7: test_dependency_sorting_4

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_4(self):
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Store, Person, Book])]
        )
        self.assertEqual(
            sorted_deps,
            [Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例8: test_dependency_sorting_5

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_5(self):
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Person, Book, Store])]
        )
        self.assertEqual(
            sorted_deps,
            [Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例9: test_dependency_sorting_dangling

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_dangling(self):
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [Person, Circle1, Store, Book])]
        )
        self.assertEqual(
            sorted_deps,
            [Circle1, Store, Person, Book]
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例10: test_dependency_sorting_tight_circular

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_tight_circular(self):
        with self.assertRaisesMessage(
            RuntimeError,
            "Can't resolve dependencies for fixtures_regress.Circle1, "
            "fixtures_regress.Circle2 in serialized app list."
        ):
            serializers.sort_dependencies([('fixtures_regress', [Person, Circle2, Circle1, Store, Book])]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:tests.py

示例11: test_dependency_sorting_tight_circular_2

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_tight_circular_2(self):
        with self.assertRaisesMessage(
            RuntimeError,
            "Can't resolve dependencies for fixtures_regress.Circle1, "
            "fixtures_regress.Circle2 in serialized app list."
        ):
            serializers.sort_dependencies([('fixtures_regress', [Circle1, Book, Circle2])]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:tests.py

示例12: test_dependency_self_referential

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_self_referential(self):
        with self.assertRaisesMessage(
            RuntimeError,
            "Can't resolve dependencies for fixtures_regress.Circle3 in "
            "serialized app list."
        ):
            serializers.sort_dependencies([('fixtures_regress', [Book, Circle3])]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:tests.py

示例13: test_dependency_sorting_long

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_long(self):
        with self.assertRaisesMessage(
            RuntimeError,
            "Can't resolve dependencies for fixtures_regress.Circle1, "
            "fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized "
            "app list."
        ):
            serializers.sort_dependencies([('fixtures_regress', [Person, Circle2, Circle1, Circle3, Store, Book])]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例14: test_dependency_sorting_m2m_simple

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_m2m_simple(self):
        """
        M2M relations without explicit through models SHOULD count as dependencies

        Regression test for bugs that could be caused by flawed fixes to
        #14226, namely if M2M checks are removed from sort_dependencies
        altogether.
        """
        sorted_deps = serializers.sort_dependencies(
            [('fixtures_regress', [M2MSimpleA, M2MSimpleB])]
        )
        self.assertEqual(sorted_deps, [M2MSimpleB, M2MSimpleA]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:tests.py

示例15: test_dependency_sorting_m2m_simple_circular

# 需要導入模塊: from django.core import serializers [as 別名]
# 或者: from django.core.serializers import sort_dependencies [as 別名]
def test_dependency_sorting_m2m_simple_circular(self):
        """
        Resolving circular M2M relations without explicit through models should
        fail loudly
        """
        with self.assertRaisesMessage(
            RuntimeError,
            "Can't resolve dependencies for fixtures_regress.M2MSimpleCircularA, "
            "fixtures_regress.M2MSimpleCircularB in serialized app list."
        ):
            serializers.sort_dependencies([('fixtures_regress', [M2MSimpleCircularA, M2MSimpleCircularB])]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:tests.py


注:本文中的django.core.serializers.sort_dependencies方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。