Commits

Kenneth Love committed f8fa6bf

working on save

  • Participants
  • Parent commits 2e9c693

Comments (0)

Files changed (2)

-from flask import Flask, render_template
+from flask import Flask, render_template, redirect, url_for, request
 import redis
 app = Flask(__name__)
 app.debug = True
 
 @app.route('/key/<key>')
 def key(key):
-    if r.type(key) == 'hash':
+    rtype = r.type(key)
+    if rtype == 'hash':
         output = r.hgetall(key)
-    elif r.type(key) == 'set':
+    elif rtype == 'set':
         output = r.smembers(key)
     else:
         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):
+    rtype = r.type(key)
+    value = request.form['value'].strip('{}')
+    new_value = dict([kv.split(':') for kv in value])
+
+    return ', '.join(new_value.keys())
+    if rtype == 'hash':
+        #r.delete(key)
+        #r.set(key, request.form['value'])
+        #r.set(key, "{'balls':'lick them'}")
+        pass
+
+    return redirect(url_for('key', key=key))
 
 if __name__ == '__main__':
     app.run()

templates/key.html

 </head>
 <body>
 	<h1>{{ key }}</h1>
-	<pre>{{ output }}</pre>
+	<form action="{{ url_for('save', key=key) }}" method="post">
+		<textarea name="value" cols="80" rows="20">{{ output }}</textarea>
+		<br>
+		<input type="submit" value="save">
+	</form>
 	<a href="{{ url_for('index') }}">back</a>
 </body>
 </html>