本文整理汇总了Python中django.core.management.color.color_style方法的典型用法代码示例。如果您正苦于以下问题:Python color.color_style方法的具体用法?Python color.color_style怎么用?Python color.color_style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.color
的用法示例。
在下文中一共展示了color.color_style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_empty_source_table
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def create_empty_source_table(self, clazz, source_table_name, source_db_connection, extra_fields={}):
project = Project(key='sutter_county', id=0)
db_entity = DbEntity(key=Keys.DB_ABSTRACT_BASE_AGRICULTURE_FEATURE, feature_class_configuration=dict(
abstract_class=full_module_path(clazz)
))
SourceClass = FeatureClassCreator(project, db_entity, no_ensure=True).dynamic_model_class(base_only=True, schema='public', table=source_table_name)
# class SourceClass(clazz):
# class Meta(clazz.Meta):
# db_table = source_table_name
create_tables_for_dynamic_classes(SourceClass)
for field in SourceClass._meta.fields[1:]:
setattr(field, 'null', True)
drop_table = "DROP TABLE IF EXISTS {final_table} CASCADE;".format(final_table=source_table_name)
sql, refs = source_db_connection.creation.sql_create_model(SourceClass, color_style())
add_geometry_fields = '''
ALTER TABLE {final_table} ADD COLUMN geography_id VARCHAR;
ALTER TABLE {final_table} ADD COLUMN wkb_geometry GEOMETRY;'''.format(final_table=source_table_name)
sql = drop_table + sql[0] + add_geometry_fields
for dbfield, fieldtype in extra_fields.items():
sql += 'ALTER TABLE {final_table} ADD COLUMN {field} {type}'.format(
final_table=source_table_name, field=dbfield, type=fieldtype)
source_db_connection.cursor().execute(sql)
示例2: livereload_request
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def livereload_request(self, **options):
"""
Performs the LiveReload request.
"""
style = color_style()
verbosity = int(options['verbosity'])
host = '%s:%d' % (
options['livereload_host'],
options['livereload_port'],
)
try:
urlopen('http://%s/forcereload' % host)
self.message('LiveReload request emitted.\n',
verbosity, style.HTTP_INFO)
except IOError:
pass
示例3: populate_exam_run_fk
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def populate_exam_run_fk(apps, schema_editor):
ProctoredExamGrade = apps.get_model('grades', 'ProctoredExamGrade')
ExamAuthorization = apps.get_model('exams', 'ExamAuthorization')
style = color_style()
fake_exam_grades = []
exam_grades = ProctoredExamGrade.objects.filter(exam_run__isnull=True)
for exam_grade in exam_grades.iterator():
try:
exam_grade.exam_run = ExamAuthorization.objects.get(
id=exam_grade.client_authorization_id
).exam_run
exam_grade.save()
except ValueError:
fake_exam_grades.append(exam_grade)
continue
for fake_exam_grade in fake_exam_grades:
sys.stdout.write(
style.ERROR(
'\nInvalid client_authorization_id {0} for ProctoredExamGrade {1}'.format(
fake_exam_grade.client_authorization_id, fake_exam_grade.id
)
)
)
示例4: main_help_text
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def main_help_text(self, commands_only=False):
"""
Returns the script's main help text, as a string.
"""
if commands_only:
usage = sorted(get_commands().keys())
else:
usage = [
"",
"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
"",
"Available subcommands:",
]
commands_dict = collections.defaultdict(lambda: [])
for name, app in six.iteritems(get_commands()):
if app == 'django.core':
app = 'django'
else:
app = app.rpartition('.')[-1]
commands_dict[app].append(name)
style = color_style()
for app in sorted(commands_dict.keys()):
usage.append("")
usage.append(style.NOTICE("[%s]" % app))
for name in sorted(commands_dict[app]):
usage.append(" %s" % name)
# Output an extra note if settings are not properly configured
if self.settings_exception is not None:
usage.append(style.NOTICE(
"Note that only Django core commands are listed "
"as settings are not properly configured (error: %s)."
% self.settings_exception))
return '\n'.join(usage)
示例5: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_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)
示例6: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, *args, **kwargs):
self.style = color_style()
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
示例7: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, *args, **kwargs):
self.style = color_style()
super().__init__(*args, **kwargs)
示例8: main_help_text
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def main_help_text(self, commands_only=False):
"""Return the script's main help text, as a string."""
if commands_only:
usage = sorted(get_commands())
else:
usage = [
"",
"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
"",
"Available subcommands:",
]
commands_dict = defaultdict(lambda: [])
for name, app in get_commands().items():
if app == 'django.core':
app = 'django'
else:
app = app.rpartition('.')[-1]
commands_dict[app].append(name)
style = color_style()
for app in sorted(commands_dict):
usage.append("")
usage.append(style.NOTICE("[%s]" % app))
for name in sorted(commands_dict[app]):
usage.append(" %s" % name)
# Output an extra note if settings are not properly configured
if self.settings_exception is not None:
usage.append(style.NOTICE(
"Note that only Django core commands are listed "
"as settings are not properly configured (error: %s)."
% self.settings_exception))
return '\n'.join(usage)
示例9: run_migrations
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def run_migrations(args, options, executor_codename, schema_name, allow_atomic=True, idx=None, count=None):
from django.core.management import color
from django.core.management.base import OutputWrapper
from django.db import connections
style = color.color_style()
def style_func(msg):
percent_str = ''
if idx is not None and count is not None and count > 0:
percent_str = '%d/%d (%s%%) ' % (idx + 1, count, int(100 * (idx + 1) / count))
return '[%s%s:%s] %s' % (
percent_str,
style.NOTICE(executor_codename),
style.NOTICE(schema_name),
msg
)
connection = connections[options.get('database', get_tenant_database_alias())]
connection.set_schema(schema_name)
stdout = OutputWrapper(sys.stdout)
stdout.style_func = style_func
stderr = OutputWrapper(sys.stderr)
stderr.style_func = style_func
if int(options.get('verbosity', 1)) >= 1:
stdout.write(style.NOTICE("=== Starting migration"))
MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
try:
transaction.commit()
connection.close()
connection.connection = None
except transaction.TransactionManagementError:
if not allow_atomic:
raise
# We are in atomic transaction, don't close connections
pass
connection.set_schema_to_public()
示例10: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, *args, **kwargs):
self.style = color_style()
super(ServerFormatter, self).__init__(*args, **kwargs)
示例11: main_help_text
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def main_help_text(self, commands_only=False):
"""
Returns the script's main help text, as a string.
"""
if commands_only:
usage = sorted(get_commands().keys())
else:
usage = [
"",
"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
"",
"Available subcommands:",
]
commands_dict = collections.defaultdict(lambda: [])
for name, app in six.iteritems(get_commands()):
if app == 'django.core':
app = 'django'
else:
app = app.rpartition('.')[-1]
commands_dict[app].append(name)
style = color_style()
for app in sorted(commands_dict.keys()):
usage.append("")
usage.append(style.NOTICE("[%s]" % app))
for name in sorted(commands_dict[app]):
usage.append(" %s" % name)
return '\n'.join(usage)
示例12: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self):
self.style = color_style()
示例13: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, outfile=sys.stdout):
self.errors = []
self.outfile = outfile
self.style = color_style()
示例14: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, *args, **kwargs):
from django.conf import settings
self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
self.style = color_style()
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
示例15: __init__
# 需要导入模块: from django.core.management import color [as 别名]
# 或者: from django.core.management.color import color_style [as 别名]
def __init__(self, stream):
self.stream = stream
self.errors = []
self.color = color_style()