Skip to content

Commit

Permalink
Merge pull request #1322 from SEL-Columbia/improve_export
Browse files Browse the repository at this point in the history
Improve export
  • Loading branch information
prabhasp committed Apr 24, 2014
2 parents ee60df8 + 82b8e31 commit 5e8e176
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
39 changes: 23 additions & 16 deletions odk_viewer/models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,30 @@ def full_filepath(self):

@classmethod
def exports_outdated(cls, xform, export_type):
# get newest export for xform
"""Return a boolean:
True if there has yet to be an export of this XForm in this type
or if the most recent export of this XForm in this type was prior to the latest submission
False otherwise
"""

result = True # default to re-generating the export

try:
latest_export = Export.objects.filter(
xform=xform, export_type=export_type,
internal_status__in=[Export.SUCCESSFUL, Export.PENDING])\
.latest('created_on')
except cls.DoesNotExist:
return True
else:
if latest_export.time_of_last_submission is not None \
and xform.time_of_last_submission_update() is not None:
return latest_export.time_of_last_submission <\
xform.time_of_last_submission_update()
else:
# return true if we can't determine the status, to force
# auto-generation
return True
latest_export = Export.objects.filter(models.Q(internal_status=Export.SUCCESSFUL) |
models.Q(internal_status=Export.PENDING),
xform=xform,
export_type=export_type).latest('created_on')

# there exists an export of this XForm for this data type
# but has there been an XForm submission since?
# (if either of these are None, it triggers a TypeError, caught below)

result = ( latest_export.time_of_last_submission < xform.time_of_last_submission_update() )

except (cls.DoesNotExist, TypeError):
pass

return result

@classmethod
def is_filename_unique(cls, xform, filename):
Expand Down
14 changes: 9 additions & 5 deletions utils/export_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,16 @@ def query_mongo(username, id_string, query=None, hide_deleted=True):


def should_create_new_export(xform, export_type):
from odk_viewer.models import Export
if Export.objects.filter(xform=xform, export_type=export_type).count() == 0\
or Export.exports_outdated(xform, export_type=export_type):
return True
return False
"""Determine whether or not a new export file for this
xform and data type should be generated.
This legacy logic is really ugly: the exports_outdated() really
should *not* be a classmethod of Export, but doing it incrementally
like this for now, until can do a more thorough overhaul later.
"""

from odk_viewer.models import Export # ugly!
return Export.exports_outdated(xform, export_type=export_type)

def newset_export_for(xform, export_type):
"""
Expand Down

0 comments on commit 5e8e176

Please sign in to comment.