Fix KML, CSV, Shapefile advanced search exports #103
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Github Issue #76
Previously exports were only working for basic searches and were
broken for most advanced search filters. They now work for all
advanced search filters. Tested on TreeZilla.
The problem:
The advanced search routine builds up queryset for several models
and exports the queryset.query (raw sql query) to ogr2ogr, which
reruns the queries and exports to the aforementioned formats. The
problem is that Django is mishandling type coercions for certain
database fields that are stored as textual representations of other
values. For example, we store native_status as a varchar, but its
value is usually restricted to "True" or "False", which was being
sent to the querybuilder as True or False, the boolean values. The
other known example is integer values stored as varchars.
The Solution:
After discussing the possibility of enabling type coercion at the
database level, it was decided that a localized changed would be
safer than a global one. So, adding some functions that sanitize
the raw SQL that goes to ogr2ogr to be the correct textual string
instead of the represented value.