def validate_content(fileName, contentMetaData): # make sure the uploaded version is valid xml exitMessages = DaisyPipeline.validate(fileName) if exitMessages: return exitMessages # make sure the meta data of the uploaded version corresponds # to the meta data in the document xmlContent = XMLContent() try: errorList = xmlContent.validateContentMetaData(fileName , **contentMetaData) except etree.XMLSyntaxError as e: return "The uploaded file is not a valid DTBook XML document:" + e.message if errorList: return "; ".join( ("The meta data '%s' in the uploaded file does not correspond to the value in the document: '%s' instead of '%s'" % errorTuple for errorTuple in errorList))
def validate_content(fileName, contentMetaData, removeFile=False): # make sure the uploaded version is valid xml exitMessages = DaisyPipeline.validate(fileName) if exitMessages: if removeFile: os.remove(fileName) raise forms.ValidationError( ["The uploaded file is not a valid DTBook XML document: "] + exitMessages) # make sure the meta data of the uploaded version corresponds # to the meta data in the document xmlContent = XMLContent() errorList = xmlContent.validateContentMetaData(fileName , **contentMetaData) if removeFile: os.remove(fileName) if errorList: raise forms.ValidationError( map(lambda errorTuple : "The meta data '%s' in the uploaded file does not correspond to the value in the document: '%s' instead of '%s'" % errorTuple, errorList))