azavea/OpenTreeMap — pull request #39 by jwalgran (2012-11-27 20:50:28+00:00)
Title: Update API to bidirectionally convert choice values

Greenprint requested that the number of tree condition values be
reduced. Because the iOS application has the choice options embedded
in a config file, the API must be able to bidirectionally convert 'old'
choices to 'new' choices.

This commit accomplishes this by:

0. Defining a schema for settings.CHOICE_CONVERSIONS where forward and reverse choice conversions can be defined and triggered by mobile platform and version. Example:

CHOICE_CONVERSIONS = {
'condition': {
'version-threshold': {
'ios': '1.2'
},
'forward': [
("1", "8"),
("2", "8"),
("3", "9"),
("4", "9"),
("5", "10"),
("6", "11"),
("7", "11")
],
'reverse': [
("8", "1"),
("9", "3"),
("10", "5"),
("11", "7"),
]
}
}

0. Adding a helper method to parse version information from the ApplicationVersion header sent with the API requests.

0. Modifying the API calls that accept and return plot/tree JSON to convert
choice values using the mapping defined in the CHOICE_CONVERSIONS setting
_only_ if the app version is below the specified threshold.

TODO: The pending values in the API responses are not yet being converted.