Skip to content

Commit

Permalink
Merge pull request #670 from kobotoolbox/2536-Remove-Excel-Analyser-F…
Browse files Browse the repository at this point in the history
…rom-Download-Options

Removed support for Excel Analyser
  • Loading branch information
noliveleger authored Feb 18, 2021
2 parents d787948 + aedd496 commit 78133d5
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 306 deletions.
1 change: 0 additions & 1 deletion kobocat-template/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ <h2 class="dashboard__group-label">
<a href="{% url "onadata.apps.viewer.views.export_list" content_user.username xform.id_string 'zip' %}" class="download__drop-button">ZIP</a>
<!-- <a href="{% url "onadata.apps.viewer.views.export_list" content_user.username xform.id_string 'gdoc' %}" class="download__drop-button">GDOCS</a> -->
<a href="{% url "onadata.apps.viewer.views.export_list" content_user.username xform.id_string 'kml'%}" class="download__drop-button">KML</a>
<a href="{% url "onadata.apps.viewer.views.export_list" content_user.username xform.id_string 'analyser' %}" class="download__drop-button">Excel Analyser</a>
<a href="{% url "formpack_export_menu" content_user.username xform.id_string %}" class="download__drop-button">Advanced Downloads (beta)</a>
<!-- or: /<username>/exports/<id_string>/ onadata.apps.export.views._wrapper formpack_export_menu -->

Expand Down
4 changes: 1 addition & 3 deletions onadata/apps/viewer/models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __str__(self):
CSV_ZIP_EXPORT = 'csv_zip'
SAV_ZIP_EXPORT = 'sav_zip'
SAV_EXPORT = 'sav'
ANALYSER_EXPORT = 'analyser'

EXPORT_MIMES = {
'xls': 'vnd.ms-excel',
Expand All @@ -55,8 +54,7 @@ def __str__(self):
(KML_EXPORT, 'kml'),
(CSV_ZIP_EXPORT, 'CSV ZIP'),
(SAV_ZIP_EXPORT, 'SAV ZIP'),
(SAV_EXPORT, 'SAV'),
(ANALYSER_EXPORT, 'Analyser')
(SAV_EXPORT, 'SAV')
]

EXPORT_TYPE_DICT = dict(export_type for export_type in EXPORT_TYPES)
Expand Down
41 changes: 0 additions & 41 deletions onadata/apps/viewer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def _create_export(xform, export_type):
# start async export
result = create_kml_export.apply_async(
(), arguments, countdown=10)
elif export_type == Export.ANALYSER_EXPORT:
result = create_analyser_export.apply_async((), arguments, countdown=10)
else:
raise Export.ExportTypeError
if result:
Expand Down Expand Up @@ -126,45 +124,6 @@ def create_xls_export(username, id_string, export_id, query=None,
return gen_export.id


@task()
def create_analyser_export(username, id_string, export_id, query=None):
# Mostly a serving of copy pasta based on the above `create_xls_export()`. Enjoy.

# we re-query the db instead of passing model objects according to
# http://docs.celeryproject.org/en/latest/userguide/tasks.html#state
ext = 'xlsx'

try:
export = Export.objects.get(id=export_id)
except Export.DoesNotExist:
# no export for this ID return None.
return None

# though export is not available when for has 0 submissions, we
# catch this since it potentially stops celery
try:
gen_export = generate_export(Export.ANALYSER_EXPORT, ext, username, id_string, export_id,
query, group_delimiter='/', split_select_multiples=True,
binary_select_multiples=False)
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("Analyser 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


@task()
def create_csv_export(username, id_string, export_id, query=None,
group_delimiter='/', split_select_multiples=True,
Expand Down
233 changes: 0 additions & 233 deletions onadata/libs/utils/analyser_export.py

This file was deleted.

28 changes: 0 additions & 28 deletions onadata/libs/utils/export_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
TAGS,
NOTES
)
from .analyser_export import generate_analyser


# this is Mongo Collection where we will store the parsed submissions
Expand Down Expand Up @@ -579,29 +578,6 @@ def write_row(data, work_sheet, fields, work_sheet_titles):

wb.save(filename=path)

def to_analyser_export(self, path, data, username, xform_id_string, *args):
# Get the XLSForm.
xform = XForm.objects.get(user__username__iexact=username, id_string__exact=xform_id_string)
xlsform_io= xform.to_xlsform()

if xlsform_io is None:
raise RuntimeError('XLSForm `{}` for user `{}` could not be retrieved from storage.'.
format(xform_id_string, username))

prefix = slugify('analyser_data__{}__{}'.format(username, xform_id_string))
with tempfile.NamedTemporaryFile('w+b', prefix=prefix, suffix='.xlsx',) as xls_data:
# Generate a new XLS export to work from.
self.to_xls_export(xls_data.name, data)
xls_data.file.seek(0)

# Generate the analyser file.
analyser_io= generate_analyser(xlsform_io, xls_data)

# Write the generated analyser file to the specified path
# ...which itself points to a temp file.
with open(path, 'wb') as analyser_file:
analyser_file.write(analyser_io.read())

def to_flat_csv_export(
self, path, data, username, id_string, filter_query):
# TODO resolve circular import
Expand Down Expand Up @@ -720,7 +696,6 @@ def generate_export(export_type, extension, username, id_string,
Export.CSV_EXPORT: 'to_flat_csv_export',
Export.CSV_ZIP_EXPORT: 'to_zipped_csv',
Export.SAV_ZIP_EXPORT: 'to_zipped_sav',
Export.ANALYSER_EXPORT: 'to_analyser_export'
}

xform = XForm.objects.get(
Expand All @@ -747,9 +722,6 @@ def generate_export(export_type, extension, username, id_string,
# generate filename
basename = "%s_%s" % (
id_string, datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
if export_type == Export.ANALYSER_EXPORT:
# Analyser exports should be distinguished by more than just their file extension.
basename= '{}_ANALYSER_{}'.format(id_string, datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
filename = basename + "." + extension

# check filename is unique
Expand Down

0 comments on commit 78133d5

Please sign in to comment.