Commits

Kenneth Love committed 15fd894

show message when key doesn't exist

Comments (0)

Files changed (2)

 @app.route('/new', methods=['GET', 'POST'])
 def new_key():
     form = StringForm(request.form or None)
-    if request.method == 'POST':
-        if form.validate():
-            key = request.form['key_name']
-            value = request.form['key_value']
+    if form.validate_on_submit():
+        key = request.form['key_name']
+        value = request.form['key_value']
 
-            r = get_redis_connection(session)
-            if not r:
-                return redirect(url_for('setup'))
+        r = get_redis_connection(session)
+        if not r:
+            return redirect(url_for('setup'))
 
-            if r.exists(key):
-                return jsonify(flash=key + ' already exists.')
+        if r.exists(key):
+            return jsonify(flash=key + ' already exists.')
 
-            try:
-                r.set(key, value)
-                flash('%s was saved successfully.' % key)
-                return redirect('#%s' % key)
-            except:
-                return jsonify(flash=key + ' was not saved successfully.')
+        try:
+            r.set(key, value)
+            flash('%s was saved successfully.' % key)
+            return redirect('#%s' % key)
+        except:
+            return jsonify(flash=key + ' was not saved successfully.')
 
     return render_template('new_key.html', form=form)
 
     if not r:
         return redirect(url_for('setup'))
 
-    rtype = r.type(key)
-    if rtype == 'hash':
-        output = r.hgetall(key)
-    elif rtype == 'set':
-        output = r.smembers(key)
-    elif rtype == 'zset':
-        output = r.zrange(key, 0, -1, withscores=True)
-    elif rtype == 'list':
-        output = [r.lindex(key, n) for n in xrange(r.llen(key))]
+    if r.exists(key):
+        rtype = r.type(key)
+        if rtype == 'hash':
+            output = r.hgetall(key)
+        elif rtype == 'set':
+            output = r.smembers(key)
+        elif rtype == 'zset':
+            output = r.zrange(key, 0, -1, withscores=True)
+        elif rtype == 'list':
+            output = [r.lindex(key, n) for n in xrange(r.llen(key))]
+        else:
+            output = r.get(key)
+        return render_template('key.html', rtype=rtype, key=key, output=output)
     else:
-        output = r.get(key)
-    return render_template('key.html', rtype=rtype, key=key, output=output)
+        return render_template('no_key.html', key=key)
 
 @app.route('/key/save/<key>', methods=['POST'])
 def save(key):

templates/no_key.html

+<h1>Oops!</h1>
+<p>The key <strong>{{ key }}</strong> doesn't seem to exist in this database.</p>
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.