Python django.core.management.color.color_style() Examples
The following are 19
code examples of django.core.management.color.color_style().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.management.color
, or try the search function
.
Example #1
Source File: 0008_populate_exam_run_for_exam_grades.py From micromasters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 ) ) )
Example #2
Source File: runserver.py From django-livereload-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: load_ag_scenario_table.py From urbanfootprint with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: log.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super().__init__(*args, **kwargs)
Example #5
Source File: log.py From python2017 with MIT License | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super(ServerFormatter, self).__init__(*args, **kwargs)
Example #6
Source File: elasticapm.py From apm-agent-python with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, stream): self.stream = stream self.errors = [] self.color = color_style()
Example #7
Source File: basehttp.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #8
Source File: validation.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def __init__(self, outfile=sys.stdout): self.errors = [] self.outfile = outfile self.style = color_style()
Example #9
Source File: base.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def __init__(self): self.style = color_style()
Example #10
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #11
Source File: log.py From python with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super(ServerFormatter, self).__init__(*args, **kwargs)
Example #12
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: base.py From django-tenants with MIT License | 5 votes |
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()
Example #14
Source File: development.example.py From django2-project-template with MIT License | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super().__init__(*args, **kwargs)
Example #15
Source File: __init__.py From DeerU with GNU General Public License v3.0 | 5 votes |
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)
Example #16
Source File: __init__.py From DeerU with GNU General Public License v3.0 | 5 votes |
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)
Example #17
Source File: log.py From bioforum with MIT License | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super().__init__(*args, **kwargs)
Example #18
Source File: basehttp.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def __init__(self, *args, **kwargs): self.style = color_style() super(WSGIRequestHandler, self).__init__(*args, **kwargs)
Example #19
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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)