def validate(iati_parser, xml_etree): base = os.path.dirname(os.path.abspath(__file__)) location = base + "/../schemas/" + iati_parser.VERSION \ + "/iati-activities-schema.xsd" xsd_data = open(location) xmlschema_doc = etree.parse(xsd_data) xsd_data.close() xmlschema = etree.XMLSchema(xmlschema_doc) xml_errors = None try: xmlschema.assertValid(xml_etree) except etree.DocumentInvalid as e: xml_errors = e pass if xml_errors: for error in xml_errors.error_log: element = error.message[( findnth_occurence_in_string(error.message, '\'', 0) + 1):findnth_occurence_in_string(error.message, '\'', 1)] attribute = '-' if 'attribute' in error.message: attribute = error.message[( findnth_occurence_in_string(error.message, '\'', 2) + 1):findnth_occurence_in_string(error.message, '\'', 3)] iati_parser.append_error('XsdValidationError', element, attribute, error.message.split(':')[0], error.line, error.message.split(':')[1], 'unkown for XSD validation errors')
def validate(iati_parser, xml_etree): base = os.path.dirname(os.path.abspath(__file__)) if iati_parser.dataset.filetype == 1: # Activity file location = base + "/../schemas/" + iati_parser.VERSION \ + "/iati-activities-schema.xsd" else: # Organisation file (2) location = base + "/../schemas/" + iati_parser.VERSION \ + "/iati-organisations-schema.xsd" xsd_data = open(location) xmlschema_doc = etree.parse(xsd_data) xsd_data.close() xmlschema = etree.XMLSchema(xmlschema_doc) xml_errors = None try: xmlschema.assertValid(xml_etree) except etree.DocumentInvalid as e: xml_errors = e pass if xml_errors: for error in xml_errors.error_log: element = error.message[ (findnth_occurence_in_string( error.message, '\'', 0 ) + 1):findnth_occurence_in_string( error.message, '\'', 1 ) ] attribute = '-' if 'attribute' in error.message: attribute = error.message[ (findnth_occurence_in_string( error.message, '\'', 2 ) + 1):findnth_occurence_in_string( error.message, '\'', 3 ) ] iati_parser.append_error( 'XsdValidationError', element, attribute, error.message.split(':')[0], error.line, error.message.split(':')[1], 'unkown for XSD validation errors')
def check_registration_agency_validity(self, element_name, element, ref): reg_agency_found = False if ref and findnth_occurence_in_string(ref, '-', 1) > -1: index = findnth_occurence_in_string(ref, '-', 1) reg_agency = self.get_or_none( codelist_models.OrganisationRegistrationAgency, code=ref[:index]) if reg_agency: reg_agency_found = True if not reg_agency_found: self.append_error( 'FieldValidationError', element_name, "ref", "Must be in the format {Registration Agency} - (Registration " "Number}", element.sourceline, ref)
def check_registration_agency_validity(self, element_name, element, ref): reg_agency_found = False if ref and findnth_occurence_in_string(ref, '-', 1) > -1: index = findnth_occurence_in_string(ref, '-', 1) reg_agency = self.get_or_none( codelist_models.OrganisationRegistrationAgency, code=ref[:index] ) if reg_agency: reg_agency_found = True if not reg_agency_found: self.append_error( 'FieldValidationError', element_name, "ref", "Must be in the format {Registration Agency} - (Registration " "Number}", element.sourceline, ref)