Issue #267 was marked as a duplicate of this issue.
Added some checks for missing data before they are used to populate arrays. My broken radiographic export now works. To make this fix watertight every field that is used in the arrays needs to have this check done on it. I will sort that at a later date. References issue #120.
Attempting to create a nicer way of testing for objects existing, refs #120. @dplatten, can you take a look? I've only made the changes to DX csv export. It seems to work, however, I can't generate the error that should happen if something doesn't exist! The method doesn't work for the defs on the models.
Taken return_if_exists out of dx_export and put it into tools/get_values.py as return_for_export. Added conversion to unicode, for both strings and decimals etc. Used the function for the common fields in the xlsx DX export, haven't done the per exposure fields yet. Refs #120. Added patient sex to the DX xlsx export, refs #235
I guess if the ObjectDoesNotExist thing is because the model instance hasn't been created, then there is no reason for that check to be in return_for_export. But the function might still be useful in turning everything into a unicode string - we've had problems with exporting decimals, hence the str() functions, but if we have non-ASCII characters in the text fields then maybe it is safer to turn everything into unicode?
Thoughts @dplatten ?
@edmcdonagh, I think this looks good. I'm going to expand your code so that it is used throughout the dx_export file, test it, and then commit it back.
Expanded Ed's method to the whole of the csv export for radiographic studies. Tested: copes with my errors. References issue #120