Lars Yencken avatar Lars Yencken committed 928eb6c

Fix the kanji not found case.

Comments (0)

Files changed (1)


 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']]
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
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.