Skip to content

Commit

Permalink
!RMS ONLY! Use vanilla pyxform
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm committed Jun 27, 2018
1 parent c0d119c commit 6076546
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 58 deletions.
54 changes: 0 additions & 54 deletions onadata/apps/api/__init__.py
@@ -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
3 changes: 2 additions & 1 deletion onadata/apps/logger/views.py
Expand Up @@ -33,7 +33,7 @@
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 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 @@ -466,6 +466,7 @@ def download_spss_labels(request, username, form_id_string):

survey= Survey.from_xls(filelike_obj=xlsform_io)
zip_filename= '{}_spss_labels.zip'.format(xform.id_string)
raise NotImplementedError('Requires KoBo fork of pyxform')
zip_io= survey_to_spss_label_zip(survey, xform.id_string)

response = StreamingHttpResponse(FileWrapper(zip_io),
Expand Down
5 changes: 2 additions & 3 deletions requirements/base.pip
Expand Up @@ -18,9 +18,8 @@ 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/pyxform.git@2.017.36#egg=pyxform
# Use vanilla pyxform for RMS; caveat: breaks SPSS export
pyxform==0.11.2
django-reversion==2.0.8
xlrd==0.9.3
xlwt==0.7.5
Expand Down

0 comments on commit 6076546

Please sign in to comment.