Here are the examples of the python api django.core.checks.Error taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
200 Examples
3
Example 1
View licensedef _check_exclude(self, cls, model): """ Check that exclude is a sequence without duplicates. """ if cls.exclude is None: # default value is None return [] elif not isinstance(cls.exclude, (list, tuple)): return must_be('a list or tuple', option='exclude', obj=cls, id='admin.E014') elif len(cls.exclude) > len(set(cls.exclude)): return [ checks.Error( "The value of 'exclude' contains duplicate field(s).", hint=None, obj=cls, id='admin.E015', ) ] else: return []
3
Example 2
View licensedef _check_radio_fields_value(self, cls, model, val, label): """ Check type of a value of `radio_fields` dictionary. """ from django.contrib.admin.options import HORIZONTAL, VERTICAL if val not in (HORIZONTAL, VERTICAL): return [ checks.Error( "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label, hint=None, obj=cls, id='admin.E024', ) ] else: return []
3
Example 3
View licensedef _check_view_on_site_url(self, cls, model): if hasattr(cls, 'view_on_site'): if not callable(cls.view_on_site) and not isinstance(cls.view_on_site, bool): return [ checks.Error( "The value of 'view_on_site' must be a callable or a boolean value.", hint=None, obj=cls, id='admin.E025', ) ] else: return [] else: return []
3
Example 4
View licensedef _check_list_display_links_item(self, cls, model, field_name, label): if field_name not in cls.list_display: return [ checks.Error( "The value of '%s' refers to '%s', which is not defined in 'list_display'." % ( label, field_name ), hint=None, obj=cls, id='admin.E111', ) ] else: return []
3
Example 5
View licensedef _check_relation(self, cls, parent_model): try: _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name) except ValueError as e: return [checks.Error(e.args[0], hint=None, obj=cls, id='admin.E202')] else: return []
3
Example 6
View licensedef must_be(type, option, obj, id): return [ checks.Error( "The value of '%s' must be %s." % (option, type), hint=None, obj=obj, id=id, ), ]
3
Example 7
View licensedef must_inherit_from(parent, option, obj, id): return [ checks.Error( "The value of '%s' must inherit from '%s'." % (option, parent), hint=None, obj=obj, id=id, ), ]
3
Example 8
View licensedef refer_to_missing_field(field, option, model, obj, id): return [ checks.Error( "The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % ( option, field, model._meta.app_label, model._meta.object_name ), hint=None, obj=obj, id=id, ), ]
3
Example 9
View licensedef _check_field_name(self): if self.name.endswith("_"): return [ checks.Error( 'Field names must not end with an underscore.', hint=None, obj=self, id='fields.E001', ) ] else: return []
3
Example 10
View licensedef _check_object_id_field(self): try: self.model._meta.get_field(self.fk_field) except FieldDoesNotExist: return [ checks.Error( "The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field, hint=None, obj=self, id='contenttypes.E001', ) ] else: return []
3
Example 11
View license@register(Tags.models) def check_all_models(app_configs=None, **kwargs): errors = [] for model in apps.get_models(): if app_configs is None or model._meta.app_config in app_configs: if not inspect.ismethod(model.check): errors.append( Error( "The '%s.check()' class method is " "currently overridden by %r." % ( model.__name__, model.check), hint=None, obj=model, id='models.E020' ) ) else: errors.extend(model.check(**kwargs)) return errors
3
Example 12
View licensedef _check_unique(self): if self._unique_set_explicitly: return [ checks.Error( "'unique' is not a valid argument for a %s." % self.__class__.__name__, hint=None, obj=self, id='fields.E200', ) ] else: return []
3
Example 13
View licensedef _check_primary_key(self): if self._primary_key_set_explicitly: return [ checks.Error( "'primary_key' is not a valid argument for a %s." % self.__class__.__name__, hint=None, obj=self, id='fields.E201', ) ] else: return []
3
Example 14
View licensedef _check_image_library_installed(self): try: from django.utils.image import Image # NOQA except ImproperlyConfigured: return [ checks.Error( 'Cannot use ImageField because Pillow is not installed.', hint=('Get Pillow at https://pypi.python.org/pypi/Pillow ' 'or run command "pip install pillow".'), obj=self, id='fields.E210', ) ] else: return []
3
Example 15
View licensedef _check_db_index(self): # Taken from django.db.models.fields.__init__ if self.db_index not in (None, True, False): return [ checks.Error( "'db_index' must be None, True or False.", hint=None, obj=self, id='fields.E006', ) ] else: return []
3
Example 16
View licensedef _check_exclude(self, cls, model): """ Check that exclude is a sequence without duplicates. """ if cls.exclude is None: # default value is None return [] elif not isinstance(cls.exclude, (list, tuple)): return must_be('a list or tuple', option='exclude', obj=cls, id='admin.E014') elif len(cls.exclude) > len(set(cls.exclude)): return [ checks.Error( "The value of 'exclude' contains duplicate field(s).", hint=None, obj=cls, id='admin.E015', ) ] else: return []
3
Example 17
View licensedef _check_radio_fields_value(self, cls, model, val, label): """ Check type of a value of `radio_fields` dictionary. """ from django.contrib.admin.options import HORIZONTAL, VERTICAL if val not in (HORIZONTAL, VERTICAL): return [ checks.Error( "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label, hint=None, obj=cls, id='admin.E024', ) ] else: return []
3
Example 18
View licensedef _check_view_on_site_url(self, cls, model): if hasattr(cls, 'view_on_site'): if not callable(cls.view_on_site) and not isinstance(cls.view_on_site, bool): return [ checks.Error( "The value of 'view_on_site' must be a callable or a boolean value.", hint=None, obj=cls, id='admin.E025', ) ] else: return [] else: return []
3
Example 19
View licensedef _check_list_display_links_item(self, cls, model, field_name, label): if field_name not in cls.list_display: return [ checks.Error( "The value of '%s' refers to '%s', which is not defined in 'list_display'." % ( label, field_name ), hint=None, obj=cls, id='admin.E111', ) ] else: return []
3
Example 20
View licensedef _check_relation(self, cls, parent_model): try: _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name) except ValueError as e: return [checks.Error(e.args[0], hint=None, obj=cls, id='admin.E202')] else: return []
3
Example 21
View licensedef must_be(type, option, obj, id): return [ checks.Error( "The value of '%s' must be %s." % (option, type), hint=None, obj=obj, id=id, ), ]
3
Example 22
View licensedef must_inherit_from(parent, option, obj, id): return [ checks.Error( "The value of '%s' must inherit from '%s'." % (option, parent), hint=None, obj=obj, id=id, ), ]
3
Example 23
View licensedef refer_to_missing_field(field, option, model, obj, id): return [ checks.Error( "The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % ( option, field, model._meta.app_label, model._meta.object_name ), hint=None, obj=obj, id=id, ), ]
3
Example 24
View licensedef _check_field_name(self): if self.name.endswith("_"): return [ checks.Error( 'Field names must not end with an underscore.', hint=None, obj=self, id='fields.E001', ) ] else: return []
3
Example 25
View licensedef _check_object_id_field(self): try: self.model._meta.get_field(self.fk_field) except FieldDoesNotExist: return [ checks.Error( "The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field, hint=None, obj=self, id='contenttypes.E001', ) ] else: return []
3
Example 26
View license@register(Tags.models) def check_all_models(app_configs=None, **kwargs): errors = [] for model in apps.get_models(): if app_configs is None or model._meta.app_config in app_configs: if not inspect.ismethod(model.check): errors.append( Error( "The '%s.check()' class method is " "currently overridden by %r." % ( model.__name__, model.check), hint=None, obj=model, id='models.E020' ) ) else: errors.extend(model.check(**kwargs)) return errors
3
Example 27
View licensedef check_field(self, field, **kwargs): class ErrorList(list): """A dummy list class that emulates API used by the older validate_field() method. When validate_field() is fully deprecated, this dummy can be removed too. """ def add(self, opts, error_message): self.append(checks.Error(error_message, hint=None, obj=field)) errors = ErrorList() # Some tests create fields in isolation -- the fields are not attached # to any model, so they have no `model` attribute. opts = field.model._meta if hasattr(field, 'model') else None self.validate_field(errors, field, opts) return list(errors)
3
Example 28
View licensedef _check_unique(self): if self._unique_set_explicitly: return [ checks.Error( "'unique' is not a valid argument for a %s." % self.__class__.__name__, hint=None, obj=self, id='fields.E200', ) ] else: return []
3
Example 29
View licensedef _check_primary_key(self): if self._primary_key_set_explicitly: return [ checks.Error( "'primary_key' is not a valid argument for a %s." % self.__class__.__name__, hint=None, obj=self, id='fields.E201', ) ] else: return []
3
Example 30
View licensedef _check_image_library_installed(self): try: from PIL import Image # NOQA except ImportError: return [ checks.Error( 'Cannot use ImageField because Pillow is not installed.', hint=('Get Pillow at https://pypi.python.org/pypi/Pillow ' 'or run command "pip install Pillow".'), obj=self, id='fields.E210', ) ] else: return []
3
Example 31
View licensedef _add_error(errors, msg, ident): errors.append( Error( msg, hint=None, obj=BitField, id='coredata.E%03i' % (ident) ) )
3
Example 32
View license@register(Tags.templates) def check_pydata_installed_before_workshops(**kwargs): errors = [] if settings.INSTALLED_APPS.index('pydata') > \ settings.INSTALLED_APPS.index('workshops'): errors.append( Error( '`pydata` installed after `workshops` app.', hint=('Add `pydata` to INSTALLED_APPS before the `workshops` app.'), id='amy.E003', ), ) return errors
3
Example 33
View license@register(Tags.security) def check_pydata_username_password_in_settings(**kwargs): errors = [] if not hasattr(settings, 'PYDATA_USERNAME_SECRET'): errors.append( Error('`PYDATA_USERNAME_SECRET` is missing in settings.py'), ) if not hasattr(settings, 'PYDATA_PASSWORD_SECRET'): errors.append( Error('`PYDATA_PASSWORD_SECRET` is missing in settings.py'), ) return errors
3
Example 34
View license@register() def base_form_class_check(app_configs, **kwargs): from wagtail.wagtailadmin.forms import WagtailAdminPageForm from wagtail.wagtailcore.models import get_page_models errors = [] for cls in get_page_models(): if not issubclass(cls.base_form_class, WagtailAdminPageForm): errors.append(Error( "{}.base_form_class does not extend WagtailAdminPageForm".format( cls.__name__), hint="Ensure that {}.{} extends WagtailAdminPageForm".format( cls.base_form_class.__module__, cls.base_form_class.__name__), obj=cls, id='wagtailadmin.E001')) return errors
3
Example 35
View license@register() def get_form_class_check(app_configs, **kwargs): from wagtail.wagtailadmin.forms import WagtailAdminPageForm from wagtail.wagtailcore.models import get_page_models errors = [] for cls in get_page_models(): edit_handler = cls.get_edit_handler() if not issubclass(edit_handler.get_form_class(cls), WagtailAdminPageForm): errors.append(Error( "{cls}.get_edit_handler().get_form_class({cls}) does not extend WagtailAdminPageForm".format( cls=cls.__name__), hint="Ensure that the EditHandler for {cls} creates a subclass of WagtailAdminPageForm".format( cls=cls.__name__), obj=cls, id='wagtailadmin.E002')) return errors
3
Example 36
View license@register(Tags.compatibility) def check_compatibility(app_configs, **kwargs): cache_alias = cachalot_settings.CACHALOT_CACHE caches = {cache_alias: settings.CACHES[cache_alias]} errors = [] for setting, k, valid_values in ( (settings.DATABASES, 'ENGINE', VALID_DATABASE_ENGINES), (caches, 'BACKEND', VALID_CACHE_BACKENDS)): for config in setting.values(): value = config[k] if value not in valid_values: errors.append( Error( '`%s` is not compatible with django-cachalot.' % value, id='cachalot.E001', ) ) return errors
3
Example 37
View licensedef _check_mariadb_dyncol(self): errors = [] if mariadb_dyncol is None: errors.append( checks.Error( "'mariadb_dyncol' is required to use DynamicField", hint="Install the 'mariadb_dyncol' library from 'pip'", obj=self, id='django_mysql.E012' ) ) return errors
3
Example 38
View licensedef _check_default(self): errors = [] if isinstance(self.default, (list, dict)): errors.append( checks.Error( 'Do not use mutable defaults for JSONField', hint=collapse_spaces(''' Mutable defaults get shared between all instances of the field, which probably isn't what you want. You should replace your default with a callable, e.g. replace default={{}} with default=dict. The default you passed was '{}'. '''.format(self.default)), obj=self, id='django_mysql.E017', ) ) return errors
3
Example 39
View licensedef check(self, **kwargs): errors = super(SizedBinaryField, self).check(**kwargs) if self.size_class not in (1, 2, 3, 4): errors.append( checks.Error( 'size_class must be 1, 2, 3, or 4', hint=None, obj=self, id='django_mysql.E007' ) ) return errors
3
Example 40
View licensedef check(self, **kwargs): errors = super(SizedTextField, self).check(**kwargs) if self.size_class not in (1, 2, 3, 4): errors.append( checks.Error( 'size_class must be 1, 2, 3, or 4', hint=None, obj=self, id='django_mysql.E008' ) ) return errors
3
Example 41
View licensedef _check_exclude(self, obj): """ Check that exclude is a sequence without duplicates. """ if obj.exclude is None: # default value is None return [] elif not isinstance(obj.exclude, (list, tuple)): return must_be('a list or tuple', option='exclude', obj=obj, id='admin.E014') elif len(obj.exclude) > len(set(obj.exclude)): return [ checks.Error( "The value of 'exclude' contains duplicate field(s).", hint=None, obj=obj.__class__, id='admin.E015', ) ] else: return []
3
Example 42
View licensedef _check_radio_fields_value(self, obj, val, label): """ Check type of a value of `radio_fields` dictionary. """ from django.contrib.admin.options import HORIZONTAL, VERTICAL if val not in (HORIZONTAL, VERTICAL): return [ checks.Error( "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label, hint=None, obj=obj.__class__, id='admin.E024', ) ] else: return []
3
Example 43
View licensedef _check_view_on_site_url(self, obj): if hasattr(obj, 'view_on_site'): if not callable(obj.view_on_site) and not isinstance(obj.view_on_site, bool): return [ checks.Error( "The value of 'view_on_site' must be a callable or a boolean value.", hint=None, obj=obj.__class__, id='admin.E025', ) ] else: return [] else: return []
3
Example 44
View licensedef _check_list_display_links_item(self, obj, field_name, label): if field_name not in obj.list_display: return [ checks.Error( "The value of '%s' refers to '%s', which is not defined in 'list_display'." % ( label, field_name ), hint=None, obj=obj.__class__, id='admin.E111', ) ] else: return []
3
Example 45
View licensedef _check_relation(self, obj, parent_model): try: _get_foreign_key(parent_model, obj.model, fk_name=obj.fk_name) except ValueError as e: return [checks.Error(e.args[0], hint=None, obj=obj.__class__, id='admin.E202')] else: return []
3
Example 46
View licensedef must_be(type, option, obj, id): return [ checks.Error( "The value of '%s' must be %s." % (option, type), hint=None, obj=obj.__class__, id=id, ), ]
3
Example 47
View licensedef must_inherit_from(parent, option, obj, id): return [ checks.Error( "The value of '%s' must inherit from '%s'." % (option, parent), hint=None, obj=obj.__class__, id=id, ), ]
3
Example 48
View licensedef refer_to_missing_field(field, option, model, obj, id): return [ checks.Error( "The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % ( option, field, model._meta.app_label, model._meta.object_name ), hint=None, obj=obj.__class__, id=id, ), ]
3
Example 49
View licensedef _check_field_name(self): if self.name.endswith("_"): return [ checks.Error( 'Field names must not end with an underscore.', hint=None, obj=self, id='fields.E001', ) ] else: return []
3
Example 50
View licensedef _check_object_id_field(self): try: self.model._meta.get_field(self.fk_field) except FieldDoesNotExist: return [ checks.Error( "The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field, hint=None, obj=self, id='contenttypes.E001', ) ] else: return []