Parcourir la source

update router

- decrease mongodb connection timeout
- return ok templates needed for ajax calls
Maximilian Ronniger il y a 10 ans
Parent
commit
ef53c9a087
1 fichiers modifiés avec 12 ajouts et 6 suppressions
  1. 12 6
      src/index.py

+ 12 - 6
src/index.py

@@ -3,10 +3,12 @@ from flask import Flask, render_template, request, redirect
 import os
 from pymongo import MongoClient
 from bson.objectid import ObjectId
-
+#from json import dumps
+import json
 
 def connect():
-    connection = MongoClient("10.0.1.10", 27017)
+    connection = MongoClient("10.0.1.10", 27017,connectTimeoutMS=10000)
+    #connection = MongoClient("127.0.0.1", 27017,connectTimeoutMS=10000)
     handle = connection["dpTapeDB"]
     handle.authenticate("gui", "GahN7chi")
     return handle
@@ -29,9 +31,14 @@ def index_old():
 
 @app.route("/loaddata", methods=['GET'])
 def loaddata():
-    results = [x for x in handle.digilst.find()[0:5]]
+    results = [x for x in handle.digilst.find()[0:100]]
     return render_template('data.json', results=results)
 
+@app.route("/load", methods=['GET'])
+def load():
+    results = [x for x in handle.digilst.find()[0:10]]
+    return json.dumps(results)
+
 @app.route("/insert", methods=['GET'])
 def insert():
     return render_template("insert.html")
@@ -69,8 +76,7 @@ def write_insert():
                            "Category": category, "Duration": duration,
                            "Location": location, "Format": format,
                            "Note": note, "Status": status})
-    return redirect("/insert")
-
+    return render_template("ok.txt")
 
 @app.route("/write_update", methods=['POST'])
 def write_update():
@@ -85,7 +91,7 @@ def write_update():
 def write_delete():
     mongoid = ObjectId(request.form.get("mongoid"))
     handle.digilst.remove({"_id": mongoid})
-    return redirect("/delete")
+    return render_template("ok.txt")
 
 
 if __name__ == '__main__':