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


Python color.no_style方法代碼示例

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


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

示例1: drop_models_tables

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def drop_models_tables(
    database_name: str,
    style: Optional[Style] = None,
) -> None:
    """Drop all installed Django's models tables."""
    style = style or no_style()
    connection = connections[database_name]
    tables = connection.introspection.django_table_names(
        only_existing=True,
        include_views=False,
    )
    sql_drop_tables = [
        connection.SchemaEditorClass.sql_delete_table % {
            'table': style.SQL_FIELD(connection.ops.quote_name(table)),
        }
        for table in tables
    ]
    if sql_drop_tables:
        get_execute_sql_flush_for(connection)(database_name, sql_drop_tables) 
開發者ID:wemake-services,項目名稱:django-test-migrations,代碼行數:21,代碼來源:sql.py

示例2: apply_initial_migration

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def apply_initial_migration(self, targets: MigrationSpec) -> ProjectState:
        """Reverse back to the original migration."""
        targets = normalize(targets)

        style = no_style()
        # start from clean database state
        sql.drop_models_tables(self._database, style)
        sql.flush_django_migrations_table(self._database, style)

        # prepare as broad plan as possible based on full plan
        self._executor.loader.build_graph()  # reload
        full_plan = self._executor.migration_plan(
            self._executor.loader.graph.leaf_nodes(),
            clean_start=True,
        )
        plan = truncate_plan(targets, full_plan)

        # apply all migrations from generated plan on clean database
        # (only forward, so any unexpected migration won't be applied)
        # to restore database state before tested migration
        return self._migrate(targets, plan=plan) 
開發者ID:wemake-services,項目名稱:django-test-migrations,代碼行數:23,代碼來源:migrator.py

示例3: test_sequence_name_length_limits_flush

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def test_sequence_name_length_limits_flush(self):
        """
        Sequence resetting as part of a flush with model with long name and
        long pk name doesn't error (#8901).
        """
        # A full flush is expensive to the full test, so we dig into the
        # internals to generate the likely offending SQL and run it manually

        # Some convenience aliases
        VLM = VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
        VLM_m2m = VLM.m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.through
        tables = [
            VLM._meta.db_table,
            VLM_m2m._meta.db_table,
        ]
        sequences = [
            {
                'column': VLM._meta.pk.column,
                'table': VLM._meta.db_table
            },
        ]
        cursor = connection.cursor()
        for statement in connection.ops.sql_flush(no_style(), tables, sequences):
            cursor.execute(statement) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:26,代碼來源:tests.py

示例4: test_generic_relation

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def test_generic_relation(self):
        "Sequence names are correct when resetting generic relations (Ref #13941)"
        # Create an object with a manually specified PK
        Post.objects.create(id=10, name='1st post', text='hello world')

        # Reset the sequences for the database
        cursor = connection.cursor()
        commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [Post])
        for sql in commands:
            cursor.execute(sql)

        # If we create a new object now, it should have a PK greater
        # than the PK we specified manually.
        obj = Post.objects.create(name='New post', text='goodbye world')
        self.assertGreater(obj.pk, 10)


# This test needs to run outside of a transaction, otherwise closing the
# connection would implicitly rollback and cause problems during teardown. 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:21,代碼來源:tests.py

示例5: test_sequence_name_length_limits_flush

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def test_sequence_name_length_limits_flush(self):
        """
        Sequence resetting as part of a flush with model with long name and
        long pk name doesn't error (#8901).
        """
        # A full flush is expensive to the full test, so we dig into the
        # internals to generate the likely offending SQL and run it manually

        # Some convenience aliases
        VLM = VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
        VLM_m2m = VLM.m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.through
        tables = [
            VLM._meta.db_table,
            VLM_m2m._meta.db_table,
        ]
        sequences = [
            {
                'column': VLM._meta.pk.column,
                'table': VLM._meta.db_table
            },
        ]
        sql_list = connection.ops.sql_flush(no_style(), tables, sequences)
        with connection.cursor() as cursor:
            for statement in sql_list:
                cursor.execute(statement) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:27,代碼來源:tests.py

示例6: test_generic_relation

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def test_generic_relation(self):
        "Sequence names are correct when resetting generic relations (Ref #13941)"
        # Create an object with a manually specified PK
        Post.objects.create(id=10, name='1st post', text='hello world')

        # Reset the sequences for the database
        commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [Post])
        with connection.cursor() as cursor:
            for sql in commands:
                cursor.execute(sql)

        # If we create a new object now, it should have a PK greater
        # than the PK we specified manually.
        obj = Post.objects.create(name='New post', text='goodbye world')
        self.assertGreater(obj.pk, 10)


# This test needs to run outside of a transaction, otherwise closing the
# connection would implicitly rollback and cause problems during teardown. 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:tests.py

示例7: reset_sequences

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def reset_sequences(*models):
    """
    After loading data the sequences must be reset in the database if
    the primary keys are manually specified. This is handled
    automatically by django for fixtures.

    Much of this is modeled after django.core.management.commands.loaddata.
    """
    # connection = connections[DEFAULT_DB_ALIAS]
    # cursor = connection.cursor()
    # sequence_sql = connection.ops.sequence_reset_sql(no_style(), models)
    # if sequence_sql:
    #     for line in sequence_sql:
    #         cursor.execute(line)
    # # transaction.commit_unless_managed()
    # cursor.close()
    pass 
開發者ID:wise-team,項目名稱:steemprojects.com,代碼行數:19,代碼來源:datautil.py

示例8: __init__

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.copied_files = []
        self.symlinked_files = []
        self.unmodified_files = []
        self.post_processed_files = []
        self.storage = staticfiles_storage
        self.style = no_style()
        try:
            self.storage.path('')
        except NotImplementedError:
            self.local = False
        else:
            self.local = True 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:16,代碼來源:collectstatic.py

示例9: create_default_site

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
    try:
        Site = apps.get_model('sites', 'Site')
    except LookupError:
        return

    if not router.allow_migrate_model(using, Site):
        return

    if not Site.objects.using(using).exists():
        # The default settings set SITE_ID = 1, and some tests in Django's test
        # suite rely on this value. However, if database sequences are reused
        # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
        # the next id will be 1, so we coerce it. See #15573 and #16353. This
        # can also crop up outside of tests - see #15346.
        if verbosity >= 2:
            print("Creating example.com Site object")
        Site(pk=getattr(settings, 'SITE_ID', 1), domain="example.com", name="example.com").save(using=using)

        # We set an explicit pk instead of relying on auto-incrementation,
        # so we need to reset the database sequence. See #17415.
        sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site])
        if sequence_sql:
            if verbosity >= 2:
                print("Resetting sequence")
            with connections[using].cursor() as cursor:
                for command in sequence_sql:
                    cursor.execute(command) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:30,代碼來源:management.py

示例10: __init__

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def __init__(self, stdout=None, stderr=None, no_color=False):
        self.stdout = OutputWrapper(stdout or sys.stdout)
        self.stderr = OutputWrapper(stderr or sys.stderr)
        if no_color:
            self.style = no_style()
        else:
            self.style = color_style()
            self.stderr.style_func = self.style.ERROR

        # `requires_model_validation` is deprecated in favor of
        # `requires_system_checks`. If both options are present, an error is
        # raised. Otherwise the present option is used. If none of them is
        # defined, the default value (True) is used.
        has_old_option = hasattr(self, 'requires_model_validation')
        has_new_option = hasattr(self, 'requires_system_checks')

        if has_old_option:
            warnings.warn(
                '"requires_model_validation" is deprecated '
                'in favor of "requires_system_checks".',
                RemovedInDjango19Warning)
        if has_old_option and has_new_option:
            raise ImproperlyConfigured(
                'Command %s defines both "requires_model_validation" '
                'and "requires_system_checks", which is illegal. Use only '
                '"requires_system_checks".' % self.__class__.__name__)

        self.requires_system_checks = (
            self.requires_system_checks if has_new_option else
            self.requires_model_validation if has_old_option else
            True) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:33,代碼來源:base.py

示例11: flush_django_migrations_table

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def flush_django_migrations_table(
    database_name: str,
    style: Optional[Style] = None,
) -> None:
    """Flush `django_migrations` table.

    Ensures compability with all supported Django versions.
    `django_migrations` is not "regular" Django model, so its not returned
    by ``ConnectionRouter.get_migratable_models`` which is used e.g. to
    implement sequences reset in ``Django==1.11``.

    """
    style = style or no_style()
    connection = connections[database_name]
    django_migrations_sequences = get_django_migrations_table_sequences(
        connection,
    )
    execute_sql_flush = get_execute_sql_flush_for(connection)
    execute_sql_flush(
        database_name,
        connection.ops.sql_flush(
            style,
            [DJANGO_MIGRATIONS_TABLE_NAME],
            django_migrations_sequences,
            allow_cascade=False,
        ),
    ) 
開發者ID:wemake-services,項目名稱:django-test-migrations,代碼行數:29,代碼來源:sql.py

示例12: __init__

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.copied_files = []
        self.symlinked_files = []
        self.unmodified_files = []
        self.post_processed_files = []
        self.storage = staticfiles_storage
        self.style = no_style() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:10,代碼來源:collectstatic.py

示例13: _reset_sequences

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def _reset_sequences(self, db_name):
        conn = connections[db_name]
        if conn.features.supports_sequence_reset:
            sql_list = \
                conn.ops.sequence_reset_by_name_sql(no_style(),
                                                    conn.introspection.sequence_list())
            if sql_list:
                try:
                    cursor = conn.cursor()
                    for sql in sql_list:
                        cursor.execute(sql)
                except Exception:
                    transaction.rollback_unless_managed(using=db_name)
                    raise
                transaction.commit_unless_managed(using=db_name) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:17,代碼來源:testcases.py

示例14: __init__

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def __init__(self, stdout=None, stderr=None, no_color=False):
        if self.binary_output is True:
            self.stdout = BinaryOutputWrapper(stdout or sys.stdout.buffer)
            self.stderr = BinaryOutputWrapper(stderr or sys.stderr.buffer)
            self.style = no_style()
        else:
            super(BaseCommand, self).__init__(stdout, stderr, no_color=no_color) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:9,代碼來源:base.py

示例15: __init__

# 需要導入模塊: from django.core.management import color [as 別名]
# 或者: from django.core.management.color import no_style [as 別名]
def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.copied_files = []
        self.symlinked_files = []
        self.unmodified_files = []
        self.post_processed_files = []
        self.storage = staticfiles_storage
        self.style = no_style() 
開發者ID:bpgc-cte,項目名稱:python2017,代碼行數:10,代碼來源:collectstatic.py


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