def check(self, **kwargs): errors = super().check(**kwargs) if not self.width_field or not self.height_field: errors.append( checks.Error( "ImageField without width_field/height_field is slow!", hint="auto_add_fields=True automatically adds the fields.", obj=self, id="imagefield.E001", )) if not self.ppoi_field: errors.append( checks.Info( "ImageField without ppoi_field.", hint="auto_add_fields=True automatically adds the field.", obj=self, id="imagefield.I001", )) if self.null is True: errors.append( checks.Info( "ImageField shouldn't use null=True.", hint=( "String-based fields shouldn't use null=True, one way" " to represent the absence of a value is enough."), obj=self, id="imagefield.I002", )) return errors
def check_deprecated_settings(app_configs=None, **kwargs): errors = [] for old, new, dep_ver, remove_ver in DEPRECATIONS: # Old setting just disappeared, we just want you to cleanup if hasattr(settings, old) and new is None: errors.append( checks.Info( ("Setting %s was removed in Pootle %s." % (old, dep_ver)), hint=("Remove %s from your settings." % old), id="pootle.I002", )) continue # Both old and new defined, we'd like you to remove the old setting if hasattr(settings, old) and hasattr(settings, new): errors.append( checks.Info( ("Setting %s was replaced by %s in Pootle %s. Both are set." % (old, new, dep_ver)), hint=("Remove %s from your settings." % old), id="pootle.I002", )) continue # Old setting is present and new setting is not defined: # - Warn and copy # - Fail hard if its too old if hasattr(settings, old) and not hasattr(settings, new): from pootle import VERSION if VERSION >= tuple(int(x) for x in remove_ver.split(".")): errors.append( checks.Critical( ("Setting %s is deprecated and was removed in Pootle %s." % (old, remove_ver)), hint=("Use %s instead." % new), id="pootle.W002", )) else: errors.append( checks.Warning( ("Setting %s is deprecated and will be removed in " "Pootle %s." % (old, remove_ver)), hint=("Use %s instead." % new), id="pootle.W002", )) setattr(settings, new, getattr(settings, old)) continue return errors
def check_migrations_applied(app_configs, **kwargs): """ A Django check to see if all migrations have been applied correctly. """ from django.db.migrations.loader import MigrationLoader errors = [] # Load migrations from disk/DB try: loader = MigrationLoader(connection, ignore_no_migrations=True) except (ImproperlyConfigured, ProgrammingError, OperationalError): msg = "Can't connect to database to check migrations" return [checks.Info(msg, id=INFO_CANT_CHECK_MIGRATIONS)] graph = loader.graph if app_configs: app_labels = [app.label for app in app_configs] else: app_labels = loader.migrated_apps for node, migration in graph.nodes.items(): if migration.app_label not in app_labels: continue if node not in loader.applied_migrations: msg = 'Unapplied migration {}'.format(migration) # NB: This *must* be a Warning, not an Error, because Errors # prevent migrations from being run. errors.append(checks.Warning(msg, id=WARNING_UNAPPLIED_MIGRATION)) return errors
def _check_model(cls): errors = super()._check_model() _will_check_workflow = cls.__dict__.get('_will_check_workflow', True) if _will_check_workflow and not cls._meta.abstract: if not inspect.isclass(cls.ACTION): errors.append( checks.Error( 'a StatableModel must have an attribute "ACTION" as an inner-class', obj=cls)) elif not issubclass(cls.ACTION, LabeledIntEnum): errors.append( checks.Info( 'a StatableModel ACTION should be LabeledIntEnum', obj=cls)) if not inspect.isclass(cls.STATUS): errors.append( checks.Error( 'a StatableModel must have an attribute "STATUS" as an inner-class', obj=cls)) elif not issubclass(cls.STATUS, LabeledIntEnum): errors.append( checks.Info( 'a StatableModel STATUS should be LabeledIntEnum', obj=cls)) if type(cls.TRANSITION) is not list: errors.append( checks.Error( 'a StatableModel must have an attribute "TRANSITION" as a list', obj=cls)) else: errors.extend(cls._build_transition_map()) return errors
def check(self, **kwargs): errors = super(ImageField, self).check(**kwargs) if not self.width_field or not self.height_field: errors.append( checks.Error( "ImageField without width_field/height_field is slow!", hint="auto_add_fields=True automatically adds the fields.", obj=self, id="imagefield.E001", )) if not self.ppoi_field: errors.append( checks.Info( "ImageField without ppoi_field.", hint="auto_add_fields=True automatically adds the field.", obj=self, id="imagefield.I001", )) return errors