def update_annotations(self): """Update the annotations for our file with the annotations for any previous matching file, if it exists.""" if not (self.file and self.prev_file): # We don't have two Files to work with. Nothing to do. return hash_ = self.file.original_hash if ValidationAnnotation.objects.filter(file_hash=hash_).exists(): # We already have annotations for this file hash. # Don't add any more. return comparator = ValidationComparator( json.loads(self.file.validation.validation)) keys = [json.dumps(key) for key in comparator.messages.iterkeys()] annos = ValidationAnnotation.objects.filter( file_hash=self.prev_file.original_hash, message_key__in=keys) ValidationAnnotation.objects.bulk_create( ValidationAnnotation(file_hash=hash_, message_key=anno.message_key, ignore_duplicates=anno.ignore_duplicates) for anno in annos)
def annotation(hash_, message, **kw): """Create a ValidationAnnotation object for the given file hash, and the key of the given message, with the given keywords.""" key = utils.ValidationComparator.message_key(message) return ValidationAnnotation(file_hash=hash_, message_key=json.dumps(key), **kw)
def annotation(hash_, key, **kw): return ValidationAnnotation(file_hash=hash_, message_key=key, **kw)