def validate_model_label(cls, value): from django.apps import apps try: apps.get_model(*value.split(".")) except Exception as exc: raise ValidationError(format_exception(exc))
def validate_model_label(cls, value): try: get_model(*value.split('.')) except AppRegistryNotReady: # circular dependency on init time pass except Exception as exc: raise ValidationError(format_exception(exc))
def validate_expression(self, service, method): try: obj = service.content_type.model_class().objects.all()[0] except IndexError: return try: bool(getattr(self, method)(obj)) except Exception as exc: raise ValidationError(format_exception(exc))
def validate_import_class(cls, value): try: import_class(value) except ImportError as exc: if "cannot import name 'settings'" in str(exc): # circular dependency on init time pass except Exception as exc: raise ValidationError(format_exception(exc))
def clean_value(self): value = self.cleaned_data['value'] if not value: return parser.NotSupported() if not isinstance(value, str): value = parser.serialize(value) try: value = eval(value, parser.get_eval_context()) except Exception as exc: raise ValidationError(format_exception(exc)) self.setting.validate_value(value) if not isinstance(value, self.setting_type): if self.setting_type in (tuple, list) and isinstance(value, (tuple, list)): value = self.setting_type(value) return value
def clean_value(self): value = self.cleaned_data['value'] if not value: return parser.NotSupported() if not isinstance(value, str): value = parser.serialize(value) try: value = eval(value, parser.get_eval_context()) except Exception as exc: raise ValidationError(format_exception(exc)) self.setting.validate_value(value) # if not isinstance(value, self.setting_type): # if self.setting_type in (tuple, list) and isinstance(value, (tuple, list)): # value = self.setting_type(value) return value
def __init__(self, *args, **kwargs): self.name, self.default = args for name, value in kwargs.items(): setattr(self, name, value) self.value = self.get_value(self.name, self.default) try: self.validate_value(self.value) except ValidationError as exc: # Init time warning sys.stderr.write("Error validating setting %s with value %s\n" % (self.name, self.value)) sys.stderr.write(format_exception(exc)) raise exc except AppRegistryNotReady: # lazy bastards pass self.settings[name] = self
def validate_import_class(cls, value): try: import_class(value) except Exception as exc: raise ValidationError(format_exception(exc))
def validate_model_label(cls, value): from django.apps import apps try: apps.get_model(*value.split('.')) except Exception as exc: raise ValidationError(format_exception(exc))