Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions onadata/apps/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,54 +0,0 @@

import re

import pyxform.odk_validate


#############################################################################
# WARNING
# This is a monkey patch to fix a bug in odk and should be removed as soon as
# the fix is upstream
#############################################################################

def _cleanup_errors(error_message):

# this is the same code as the original function
def get_last_item(xpathStr):
l = xpathStr.split("/")
return l[len(l) - 1]

def replace_function(match):
strmatch = match.group()
if strmatch.startswith("/html/body") \
or strmatch.startswith("/root/item") \
or strmatch.startswith("/html/head/model/bind") \
or strmatch.endswith("/item/value"):
return strmatch
return "${%s}" % get_last_item(match.group())
pattern = "(/[a-z0-9\-_]+(?:/[a-z0-9\-_]+)+)"
error_message = re.compile(pattern, flags=re.I).sub(replace_function,
error_message)
k = []
lastline = ''
for line in error_message.splitlines():
has_java_filename = line.find('.java:') is not -1
is_a_java_method = line.find('\tat') is not -1
is_duplicate = (line == lastline)
lastline = line
if not has_java_filename and not is_a_java_method and not is_duplicate:
if line.startswith('java.lang.RuntimeException: '):
line = line.replace('java.lang.RuntimeException: ', '')
if line.startswith('org.javarosa.xpath.XPathUnhandledException: '):
line = line.replace('org.javarosa.xpath.XPathUnhandledException: ', '')
if line.startswith('java.lang.NullPointerException'):
continue
k.append(line)

# original value causing UnicodeDecodeError
#return u'\n'.join(k)

# Fix:
return '\n'.join(k).decode('ascii', errors="replace")


pyxform.odk_validate._cleanup_errors = _cleanup_errors
32 changes: 0 additions & 32 deletions onadata/apps/logger/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from django.views.decorators.csrf import csrf_exempt
from django_digest import HttpDigestAuthenticator
from pyxform import Survey
from pyxform.spss import survey_to_spss_label_zip
from wsgiref.util import FileWrapper

from onadata.apps.main.models import UserProfile, MetaData
Expand Down Expand Up @@ -443,37 +442,6 @@ def download_jsonform(request, username, id_string):
return response


def download_spss_labels(request, username, form_id_string):
xform = get_object_or_404(XForm,
user__username__iexact=username,
id_string__exact=form_id_string)
owner = User.objects.get(username__iexact=username)
helper_auth_helper(request)

if not has_permission(xform, owner, request, xform.shared):
return HttpResponseForbidden('Not shared.')

try:
xlsform_io= xform.to_xlsform()
if not xlsform_io:
messages.add_message(request, messages.WARNING,
_(u'No XLS file for your form '
u'<strong>%(id)s</strong>')
% {'id': form_id_string})
return HttpResponseRedirect("/%s" % username)
except:
return HttpResponseServerError('Error retrieving XLSForm.')

survey= Survey.from_xls(filelike_obj=xlsform_io)
zip_filename= '{}_spss_labels.zip'.format(xform.id_string)
zip_io= survey_to_spss_label_zip(survey, xform.id_string)

response = StreamingHttpResponse(FileWrapper(zip_io),
content_type='application/zip; charset=utf-8')
response['Content-Disposition'] = 'attachment; filename={}'.format(zip_filename)
return response


@is_owner
@require_POST
def delete_xform(request, username, id_string):
Expand Down
2 changes: 0 additions & 2 deletions onadata/apps/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@
url(r"^(?P<username>\w+)/exports/(?P<id_string>[^/]+)/(?P<export_type>\w+)"
"/(?P<filename>[^/]+)$",
'onadata.apps.viewer.views.export_download'),
url(r'^(?P<username>\w+)/forms/(?P<form_id_string>[^/]+)/spss_labels\.zip$',
'onadata.apps.logger.views.download_spss_labels', name='download_spss_labels'),
url(r'^(?P<username>\w+)/exports/', include('onadata.apps.export.urls')),

url(r'^(?P<username>\w+)/reports/', include('onadata.apps.survey_report.urls')),
Expand Down
4 changes: 1 addition & 3 deletions requirements/base.pip
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ poster==0.8.1
psycopg2==2.5.4
pymongo==2.7.2
lxml==3.4.0
#-e git+https://github.com/onaio/pyxform.git@onaio#egg=pyxform
# kobo fork supports csvs with utf, character escaping, etc.
-e git+https://github.com/kobotoolbox/[email protected]#egg=pyxform
pyxform==0.11.5
django-reversion==2.0.8
xlrd==0.9.3
xlwt==0.7.5
Expand Down