本文整理汇总了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)
示例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)
示例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)
示例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.
示例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)
示例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.
示例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
示例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
示例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)
示例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)
示例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,
),
)
示例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()
示例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)
示例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)
示例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()