Commits

Kenneth Love committed fe5e113

hash saving works

  • Participants
  • Parent commits 1060835

Comments (0)

Files changed (1)

 r = redis.Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT,
     db=settings.REDIS_DB)
 
+@app.route('/info/')
+def info():
+    """ View for info about your redis set up. """
+    return render_template('info.html', info=r.info().items())
+
 @app.route('/')
 def index():
+    """ All available keys. """
     keys = r.keys()
     return render_template('index.html', keys=keys)
 
 @app.route('/key/<key>')
 def key(key):
+    """ Info for the key. """
     rtype = r.type(key)
     if rtype == 'hash':
         output = r.hgetall(key)
         output = r.get(key)
     return render_template('key.html', key=key, output=output)
 
-@app.route('/info/')
-def info():
-    return render_template('info.html', info=r.info().items())
-
 @app.route('/key/save/<key>', methods=['POST'])
 def save(key):
+    """ Update the value of a key. """
     rtype = r.type(key)
     value = request.form['value']
 
     if rtype == 'hash':
         r.delete(key)
-        r.hset(key, value)
+
+        value = request.form['value'].strip("{}")
+        values = [k.split(':', 1) for k in value.split(',')]
+        for k, v in values:
+            r.hset(key, k.strip("' "), v.strip("' "))
+
     elif rtype == 'string':
         r.set(key, value)
-        flash(key + ' was saved successfully')
+
+    flash(key + ' was saved successfully')
 
     return redirect(url_for('key', key=key))