<NME> application.py
<BEF> 
# all the imports
import os
from flask import Flask, request, session, g, redirect, url_for, \
     abort, render_template, flash, jsonify

from rsted.html import rst2html as _rst2html

import redis

# create our little application :)
from rsted.pdf import rst2pdf as _rst2pdf
app.config.from_pyfile(os.environ.get('RSTED_CONF', 'settings.py'))

def connect_redis():
    return redis.Redis(host='localhost', port=6379, db=0)

r = connect_redis()

@app.before_request
def before_request():
    global r
    try:
        result = r.ping()
    except:
        r = connect_redis()
    else:
        if not result:
            r = connect_redis()

@app.context_processor
def ctx_pro():

# create our little application :)
app = Flask(__name__)
app.config.from_pyfile(os.environ.get('RSTED_CONF', 'settings.py'))

def index():
    saved_doc_id = request.args.get('n')
    rst = ''
    #if saved_doc_id:
    #    saved_doc = SavedDocument.objects.filter(hash=saved_doc_id)
    #    if saved_doc[:]:
    #        rst = saved_doc[0].rst
    js_params = {'rst': rst, 'theme': request.args.get('theme', '')}
    return render_template('index.html', js_params=js_params)

        'is_active': view_is_active
    }

@app.route("/")
@render_html('index.html')
def index():
    yield 'js_params', {'theme': request.args.get('theme', '')}


@app.route('/about/')
    html = _rst2html(rst, theme=theme)
    return html

if __name__ == '__main__':
    app.run(host='0.0.0.0')

    responce.headers['Content-Disposition'] = 'attachment; filename="rst.pdf"'
    responce.headers['Content-Transfer-Encoding'] = 'binary'
    return responce


if __name__ == '__main__':
    app.run(host=app.config.get('HOST', '0.0.0.0'),
            port=app.config.get('PORT', 5000))

<MSG> implement saving

<DFF> @@ -1,11 +1,10 @@
-
+#!/usr/bin/env python
 # all the imports
 import os
 from flask import Flask, request, session, g, redirect, url_for, \
-     abort, render_template, flash, jsonify
+     abort, render_template, flash, jsonify, make_response
 
 from rsted.html import rst2html as _rst2html
-
 import redis
 
 # create our little application :)
@@ -13,20 +12,7 @@ app = Flask(__name__)
 app.config.from_pyfile(os.environ.get('RSTED_CONF', 'settings.py'))
 
 def connect_redis():
-    return redis.Redis(host='localhost', port=6379, db=0)
-
-r = connect_redis()
-
-@app.before_request
-def before_request():
-    global r
-    try:
-        result = r.ping()
-    except:
-        r = connect_redis()
-    else:
-        if not result:
-            r = connect_redis()
+    return redis.Redis(host=app.config.get('REDIS_HOST', 'localhost'), port=app.config.get('REDIS_PORT', 6379), db=0)
 
 @app.context_processor
 def ctx_pro():
@@ -38,10 +24,11 @@ def ctx_pro():
 def index():
     saved_doc_id = request.args.get('n')
     rst = ''
-    #if saved_doc_id:
-    #    saved_doc = SavedDocument.objects.filter(hash=saved_doc_id)
-    #    if saved_doc[:]:
-    #        rst = saved_doc[0].rst
+    if saved_doc_id:
+        r = connect_redis()
+        saved_doc = r.get(saved_doc_id)
+        if saved_doc:
+            rst = saved_doc
     js_params = {'rst': rst, 'theme': request.args.get('theme', '')}
     return render_template('index.html', js_params=js_params)
 
@@ -58,6 +45,22 @@ def rst2html():
     html = _rst2html(rst, theme=theme)
     return html
 
+@app.route('/srv/save_rst/', methods=['POST'])
+def save_rst():
+    rst = request.form.get('rst')
+    if not rst:
+        return ''
+    
+    from hashlib import md5
+    r = connect_redis()
+    
+    hash = md5(rst).hexdigest()
+    r.setnx(hash, rst)
+    r.save()
+    response = make_response(hash)
+    response.headers['Content-Type'] = 'text/plain'
+    return response
+
 if __name__ == '__main__':
     app.run(host='0.0.0.0')
 

implement saving