예제 #1
0
파일: tasks.py 프로젝트: ACTillage/formhub
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
예제 #2
0
파일: tasks.py 프로젝트: ACTillage/formhub
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
예제 #3
0
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
예제 #4
0
파일: tasks.py 프로젝트: ACTillage/formhub
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
예제 #5
0
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
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
파일: tasks.py 프로젝트: rrfenton/formhub
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
예제 #9
0
파일: tasks.py 프로젝트: rrfenton/formhub
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
예제 #10
0
파일: tasks.py 프로젝트: rrfenton/formhub
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
예제 #11
0
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
예제 #12
0
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
예제 #13
0
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