def _validate_external_instances(instances): """ Must have unique names. - Duplications could come from across groups; this checks the form. - Errors are pooled together into a (hopefully) helpful message. """ seen = {} for i in instances: element = i.name if seen.get(element) is None: seen[element] = [i] else: seen[element].append(i) errors = [] for element, copies in seen.items(): if len(copies) > 1: contexts = ", ".join(x.context for x in copies) errors.append( "Instance names must be unique within a form. " "The name '{i}' was found {c} time(s), " "under these contexts: {contexts}".format( i=element, c=len(copies), contexts=contexts ) ) if errors: raise ValidationError("\n".join(errors))
def survey2xform(survey, xform_path, formatted=False, validated=True): warnings = [] survey.print_xform_to_file(xform_path, validate=False, pretty_print=formatted, warnings=warnings, enketo=False) if validated: with open(xform_path, 'rb') as xform: response = requests.post(VALIDATE_SERVER, data=xform, headers={ 'Content-Type': 'application/xml', 'Accept': 'application/json' }) json = response.json() if (not json['valid']): raise ValidationError("\n".join( [msg['message'] for msg in json['output']])) return warnings
def validate(self, path_to_xform): self._run_odk_validate(path_to_xform) self._parse_odk_validate_output() if not self.is_valid(): raise ValidationError(self.get_odk_validate_output())