def create_kml_export(username, id_string, export_id, query=None): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_kml_export( Export.KML_EXPORT, 'kml', username, id_string, export_id, query) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception("KML Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) raise else: return gen_export.id
def create_xls_export(username, id_string, export_id, query=None, force_xlsx=True, group_delimiter='/', split_select_multiples=True): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state ext = 'xls' if not force_xlsx else 'xlsx' export = Export.objects.get(id=export_id) # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery try: gen_export = generate_export( Export.XLS_EXPORT, ext, username, id_string, export_id, query, group_delimiter, split_select_multiples) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception("XLS Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) #raise for now to let celery know we failed # - doesnt seem to break celery` raise else: return gen_export.id
def create_csv_zip_export(username, id_string, export_id, query=None, group_delimiter='/', split_select_multiples=True): export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_export(Export.CSV_ZIP_EXPORT, 'zip', username, id_string, export_id, query, group_delimiter, split_select_multiples) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception( "CSV ZIP Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) raise else: return gen_export.id
def create_csv_export(username, id_string, export_id, query=None, group_delimiter='/', split_select_multiples=True): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_export( Export.CSV_EXPORT, 'csv', username, id_string, export_id, query, group_delimiter, split_select_multiples) except NoRecordsFoundError: # not much we can do but we don't want to report this as the user # should not even be on this page if the survey has no records export.internal_status = Export.FAILED export.save() except Exception as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception("CSV Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) raise else: return gen_export.id
def create_kml_export(username, id_string, export_id, query=None): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_kml_export(Export.KML_EXPORT, 'kml', username, id_string, export_id, query) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception( "KML Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) raise else: return gen_export.id
def test_report_exception_with_exc_info(self): e = Exception("A test exception") try: raise e except Exception as e: exc_info = sys.exc_info() try: report_exception(subject="Test report exception", info=e, exc_info=exc_info) except Exception as e: raise AssertionError("%s" % e)
def create_zip_export(username, id_string, export_id, query=None): export = Export.objects.get(id=export_id) try: gen_export = generate_attachments_zip_export(Export.ZIP_EXPORT, "zip", username, id_string, export_id, query) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = {"export_id": export_id, "username": username, "id_string": id_string} report_exception("Zip Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e) raise else: if not settings.TESTING_MODE: delete_export.apply_async((), {"export_id": gen_export.id}, countdown=settings.ZIP_EXPORT_COUNTDOWN) return gen_export.id
def create_csv_zip_export(username, id_string, export_id, query=None, group_delimiter="/", split_select_multiples=True): export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_export( Export.CSV_ZIP_EXPORT, "zip", username, id_string, export_id, query, group_delimiter, split_select_multiples ) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = {"export_id": export_id, "username": username, "id_string": id_string} report_exception( "CSV ZIP Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info(), ) raise else: return gen_export.id
def create_csv_export(username, id_string, export_id, query=None, group_delimiter="/", split_select_multiples=True): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_export( Export.CSV_EXPORT, "csv", username, id_string, export_id, query, group_delimiter, split_select_multiples ) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = {"export_id": export_id, "username": username, "id_string": id_string} report_exception( "CSV Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info(), ) raise else: return gen_export.id
def create_xls_export(username, id_string, export_id, query=None, force_xlsx=True, group_delimiter='/', split_select_multiples=True): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state ext = 'xls' if not force_xlsx else 'xlsx' export = Export.objects.get(id=export_id) # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery try: gen_export = generate_export(Export.XLS_EXPORT, ext, username, id_string, export_id, query, group_delimiter, split_select_multiples) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception( "XLS Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) #raise for now to let celery know we failed # - doesnt seem to break celery` raise else: return gen_export.id
def create_zip_export(username, id_string, export_id, query=None): export = Export.objects.get(id=export_id) try: gen_export = generate_attachments_zip_export(Export.ZIP_EXPORT, 'zip', username, id_string, export_id, query) except (Exception, NoRecordsFoundError) as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception( "Zip Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e) raise else: if not settings.TESTING_MODE: delete_export.apply_async((), {'export_id': gen_export.id}, countdown=settings.ZIP_EXPORT_COUNTDOWN) return gen_export.id
def create_csv_export(username, id_string, export_id, query=None, group_delimiter='/', split_select_multiples=True): # we re-query the db instead of passing model objects according to # http://docs.celeryproject.org/en/latest/userguide/tasks.html#state export = Export.objects.get(id=export_id) try: # though export is not available when for has 0 submissions, we # catch this since it potentially stops celery gen_export = generate_export(Export.CSV_EXPORT, 'csv', username, id_string, export_id, query, group_delimiter, split_select_multiples) except NoRecordsFoundError: # not much we can do but we don't want to report this as the user # should not even be on this page if the survey has no records export.internal_status = Export.FAILED export.save() except Exception as e: export.internal_status = Export.FAILED export.save() # mail admins details = { 'export_id': export_id, 'username': username, 'id_string': id_string } report_exception( "CSV Export Exception: Export ID - " "%(export_id)s, /%(username)s/%(id_string)s" % details, e, sys.exc_info()) raise else: return gen_export.id