1. Chris Mutel
  2. brightway2-ui

Commits

Chris Mutel  committed f8b3a99

Fix jQueryFilePicker using broken unicode encoder

  • Participants
  • Parent commits 9049451
  • Branches default

Comments (0)

Files changed (2)

File bw2ui/web/app.py

View file
 from flask import Flask, url_for, render_template, request, redirect, abort
 from fuzzywuzzy import process
 from jobs import JobDispatch, InvalidJob
+from urllib import unquote as _unquote
 from utils import get_job_id, get_job, set_job_status, json_response
 import itertools
 import json
 import urllib2
 
 
+def jqfilepicker_unquote(source):
+    """
+Stupid Javascript (insert joke here...) and jQueryFilePicker
+http://stackoverflow.com/questions/300445/how-to-unquote-a-urlencoded-unicode-string-in-python
+https://github.com/simogeo/Filemanager/issues/40
+    """
+    result = _unquote(source)
+    if '%u' in result:
+        result = result.replace('%u', '\\u').decode('unicode_escape')
+    return result
+
 app = Flask(__name__)
 
 ###########################
 @app.route("/fp-api", methods=["POST"])
 def fp_api():
     full = bool(request.args.get("full", False))
-    path = urllib2.unquote(request.form["dir"])
+    path = jqfilepicker_unquote(request.form["dir"])
     try:
         root, dirs, files = os.walk(path).next()
     except StopIteration:
             "dir": True,
             "path": os.path.join(root, dir_name),
             "name": dir_name
-            })
+        })
     for file_name in files:
         data.append({
             "dir": False,
             "ext": file_name.split(".")[-1].lower(),
             "path": os.path.join(root, file_name),
             "name": file_name
-            })
+        })
     return render_template("fp-select.html", dirtree=data)
 
 #######################

File bw2ui/web/templates/index.html

View file
     </table>
 </div>
 <div class="span-12 last">
-    <p>Data directory is <i>{{ config.dir }}</i></p>
+    <p>Data directory is <i>{{ config.udir }}</i></p>
 </div>
 <div class="span-6">
     <a href="/lca"><button>Calculate LCA</button></a><br>
     "bJQueryUI": true
 });
 </script>
-{% endblock %}
+{% endblock %}