Lars Yencken avatar Lars Yencken committed 8d1bfca

Fix up remaining flask issues for search and translation.

Comments (0)

Files changed (5)

simsearch/__init__.py

     path = list(path) + [kanji]
     node = models.Node.objects.get(pivot=kanji)
     neighbours = [n.kanji for n in sorted(node.neighbours, reverse=True)]
-    neighbours = neighbours[:app.conf['N_NEIGHBOURS_RECALLED']]
+    neighbours = neighbours[:app.config['N_NEIGHBOURS_RECALLED']]
 
     context.update({'data': simplejson.dumps({
                     'kanji': kanji,
         models.Node.update(path)
         models.Trace.log(flask.request, path)
 
-    return flask.redirect(flask.url_for('translate'), args=[kanji])
+    t = models.Translation.objects.get(kanji=kanji)
+    if t is None:
+        flask.abort(404)
 
-@app.route('/search/json/<pivot>/')
+    c = base_context()
+    c['translation'] = t
+    return flask.render_template('translate/kanji.html', **c)
+
+@app.route('/search/<pivot>/')
 def search_json(pivot):
     "Returns the search display data as JSON."
     pivot = pivot or flask.request.args.get('pivot')

simsearch/models.py

 
     @classmethod
     def log(cls, request, path):
-        ip = request.META['REMOTE_ADDR']
+        ip = request.remote_addr
         cls(ip_address=ip, path=list(path)).save()
 
 class Translation(mongoengine.Document):

simsearch/templates/404.html

 {% block inner_content %}
 <h1>Page not found</h1>
 <p>Hi there! I'm not sure which page you were looking for, but we don't seem
-to have it. If you're lost, <a href="{% url search_index %}">search page</a>
+to have it. If you're lost, <a href="/">search page</a>
 is always a good place to start.</p>
 {% endblock %}

simsearch/templates/search/display.html

       };
       var pivot = d(paper.width / 2, paper.height / 2, data['kanji']);
       pivot.node.onclick = function() {
-        window.location.href = '{% url search_target %}?kanji=' + data['kanji'] + '&path=' + data['path'];
+        window.location.href = '/translate/' + data['kanji'] + '/' + '?path=' + data['path'];
       };
       draw_tier(data['tier1'], 1, paper, d, animate);
       draw_tier(data['tier2'], 2, paper, d, animate);
         }
         e.node.onclick = function(k) {
           return function() {
-            window.location.href = '{% url search_index %}?kanji=' + k +
+            window.location.href = '/?kanji=' + k +
                 '&path=' + data['path'];
           };
         }(kanji);

simsearch/templates/translate/kanji.html

       <th width="20%">On</th>
       <td>
       {% for r in translation.on_readings %}
-        {{r}}{% if not forloop.last %},{% endif %}
+        {{r}}{% if not loop.last %},{% endif %}
       {% endfor %}
       </td>
     </tr>
       <th>Kun</th>
       <td>
       {% for r in translation.kun_readings %}
-        {{r}}{% if not forloop.last %},{% endif %}
+        {{r}}{% if not loop.last %},{% endif %}
       {% endfor %}
       </td>
     </tr>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.