def check_template_choices(self, value): if not value: return False self.choices = value error = self._check_choices() if error: error_info = error[0].msg.replace('choices', 'template_choices') raise SystemCheckError('\nERROR:\n%s: %s' % ( self.__class__.__name__, error_info, )) return True
def get_pk_prefixed_filename_func( cls, upload_to: Union[str, Callable[[models.Model, str], str]]): """ Prefixes filenames with the PK (primary key) of each instance. When saving a newly created instance (which has no PK), the filename is instead prefixed with a token, which is later replaced with the PK right after the instance is saved (this is done through the ``post_save`` signal). :param upload_to: the same value as described in https://docs.djangoproject.com/en/stable/ref/models/fields/#django.db.models.FileField.upload_to :return: a function which can be passed to the ``upload_to`` argument of a ``FileField`` (or a subclass). """ if not upload_to: raise SystemCheckError( "The `upload_to` argument must be a string or a callable," " which should ensure that the files of this model field are placed in a folder only used by this specific field." ) return partial(cls._actual_upload_to, upload_to=upload_to)
def execute(self, *args, **options): raise SystemCheckError("BAD SYSTEM")
def application(env, start_response): if isinstance(exc, SystemCheckError): error_message = ansi_escape.sub('', str(exc)) raise SystemCheckError(error_message) raise exc
def check(self, app_configs=None, tags=None, display_num_errors=False, include_deployment_checks=False, fail_level=checks.ERROR): """ Use the system check framework to validate entire Django project. Raise CommandError for any serious message (error or critical errors). If there are only light messages (like warnings), print them to stderr and don't raise an exception. """ all_issues = self._run_checks( app_configs=app_configs, tags=tags, include_deployment_checks=include_deployment_checks, ) header, body, footer = "", "", "" visible_issue_count = 0 # excludes silenced warnings if all_issues: debugs = [ e for e in all_issues if e.level < checks.INFO and not e.is_silenced() ] infos = [ e for e in all_issues if checks.INFO <= e.level < checks.WARNING and not e.is_silenced() ] warnings = [ e for e in all_issues if checks.WARNING <= e.level < checks.ERROR and not e.is_silenced() ] errors = [ e for e in all_issues if checks.ERROR <= e.level < checks.CRITICAL and not e.is_silenced() ] criticals = [ e for e in all_issues if checks.CRITICAL <= e.level and not e.is_silenced() ] sorted_issues = [ (criticals, 'CRITICALS'), (errors, 'ERRORS'), (warnings, 'WARNINGS'), (infos, 'INFOS'), (debugs, 'DEBUGS'), ] for issues, group_name in sorted_issues: if issues: visible_issue_count += len(issues) formatted = (self.style.ERROR(str(e)) if e.is_serious() else self.style.WARNING(str(e)) for e in issues) formatted = "\n".join(sorted(formatted)) body += '\n%s:\n%s\n' % (group_name, formatted) if visible_issue_count: header = "System check identified some issues:\n" if display_num_errors: if visible_issue_count: footer += '\n' footer += "System check identified %s (%s silenced)." % ( "no issues" if visible_issue_count == 0 else "1 issue" if visible_issue_count == 1 else "%s issues" % visible_issue_count, len(all_issues) - visible_issue_count, ) if any( e.is_serious(fail_level) and not e.is_silenced() for e in all_issues): msg = self.style.ERROR( "SystemCheckError: %s" % header) + body + footer raise SystemCheckError(msg) else: msg = header + body + footer if msg: if visible_issue_count: self.stderr.write(msg, lambda x: x) else: self.stdout.write(msg)