Skip to content

Commit

Permalink
Removed Analyzer export
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Jul 30, 2020
1 parent 05f47cd commit a1587e1
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 306 deletions.
4 changes: 2 additions & 2 deletions kobocat-template/static/css/kobo-single-project.css
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ a.dashboard__formbutton-refresh {

.dashboard__download__drop {
position: absolute;
right: 22px;
left: 0;
bottom: -150px;
width: 124px;
border: 1px solid #E7E8E9;
Expand Down Expand Up @@ -629,4 +629,4 @@ span.poshytip {
.dashboard__download__drop {
bottom: -190px;
}
}
}
1 change: 0 additions & 1 deletion kobocat-template/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ <h2 class="dashboard__group-label">
<a href="{% url "onadata.apps.viewer.views.export_list" content_user.username xform.id_string 'csv' %}" class="download__drop-button">CSV</a>
<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 '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>
</div>
</div>

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 @@ -28,7 +28,6 @@ def __str__(self):
CSV_EXPORT = 'csv'
KML_EXPORT = 'kml'
ZIP_EXPORT = 'zip'
ANALYSER_EXPORT = 'analyser'

EXPORT_MIMES = {
'xls': 'vnd.ms-excel',
Expand All @@ -42,8 +41,7 @@ def __str__(self):
(XLS_EXPORT, 'Excel'),
(CSV_EXPORT, 'CSV'),
(ZIP_EXPORT, 'ZIP'),
(KML_EXPORT, 'kml'),
(ANALYSER_EXPORT, 'Analyser')
(KML_EXPORT, 'kml')
]

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 @@ -60,8 +60,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 @@ -116,45 +114,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
Binary file not shown.
231 changes: 0 additions & 231 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 @@ -47,7 +47,6 @@
TAGS,
NOTES
)
from .analyser_export import generate_analyser


# this is Mongo Collection where we will store the parsed submissions
Expand Down Expand Up @@ -514,29 +513,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 @@ -565,7 +541,6 @@ def generate_export(export_type, extension, username, id_string,
export_type_func_map = {
Export.XLS_EXPORT: 'to_xls_export',
Export.CSV_EXPORT: 'to_flat_csv_export',
Export.ANALYSER_EXPORT: 'to_analyser_export'
}

xform = XForm.objects.get(
Expand All @@ -592,9 +567,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 a1587e1

Please sign in to comment.