def check_metadata_is_valid(form, entity, user, new_metadata, field): if type(new_metadata) != unicode: new_metadata = new_metadata.decode('utf-8', 'ignore') errors = validate(entity, new_metadata, user) if errors: # We don't raise ValidationError since we can have multiple errors form._errors[field] = form.error_class(errors) del form.cleaned_data[field]
def check_metadata_is_valid(form, entity, user, new_metadata, field): if type(new_metadata) != unicode: new_metadata = new_metadata.decode('utf-8', 'ignore') errors = validate(entity, new_metadata, user) if errors: # We don't raise ValidationError since we can have multiple errors form._errors[field] = form.error_class(errors) del form.cleaned_data[field]
def handle(self, *args, **options): if len(args) != 2: raise CommandError("This command takes exactly 2 arguments") entity_id, metadata_file = args # get the entity try: entity = Entity.objects.get(id=int(entity_id)) except ValueError: raise CommandError("The entity_id argument must be an integer") except Entity.DoesNotExist: raise CommandError("There is no entity with entity_id=%s" % entity_id) # load the file doc = open(metadata_file, "r").read() # validate the metadata errors = validate(entity, doc) if errors: print("There were errors while validating the entity %s:" % entity) for error in errors: print(error)
def handle(self, *args, **options): if len(args) != 2: raise CommandError('This command takes exactly 2 arguments') entity_id, metadata_file = args # get the entity try: entity = Entity.objects.get(id=int(entity_id)) except ValueError: raise CommandError('The entity_id argument must be an integer') except Entity.DoesNotExist: raise CommandError('There is no entity with entity_id=%s' % entity_id) # load the file doc = open(metadata_file, 'r').read() # validate the metadata errors = validate(entity, doc) if errors: print('There were errors while validating the entity %s:' % entity) for error in errors: print(error)
def check_metadata_is_valid(form, entity, user, new_metadata, field): errors = validate(entity, new_metadata.encode('utf-8'), user) if errors: # We don't raise ValidationError since we can have multiple errors form._errors[field] = form.error_class(errors) del form.cleaned_data[field]