Commits

Lars Yencken committed 928eb6c

Fix the kanji not found case.

Comments (0)

Files changed (1)

simsearch/__init__.py

 import mercurial.ui
 import mercurial.node
 import simplejson
+import mongoengine
 
 import models
 
     kanji_ok = _is_kanji(kanji)
     context = base_context()
 
+    context.update({
+            'kanji': kanji,
+            'kanji_ok': kanji_ok,
+        })
     if not kanji or not kanji_ok:
         # show the search dialog
-        context.update({
-                'kanji': kanji,
-                'kanji_ok': kanji_ok,
-            })
         if kanji:
             context['error'] = 'Please enter a single kanji only as input.'
         return flask.render_template('search/index.html', **context)
 
-    # show the search plane instead
+    try:
+        node = models.Node.objects.get(pivot=kanji)
+    except mongoengine.queryset.DoesNotExist:
+        context['error'] = u'Sorry, %s not found' % kanji
+        return flask.render_template('search/index.html', **context)
 
     # make sure the path is ok
     path = flask.request.args.get('path', '')
         path = []
 
     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.config['N_NEIGHBOURS_RECALLED']]