Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import models
  2. from models import Customer
  3. from flask import Flask, request, session, redirect, url_for, render_template, flash
  4. import os
  5. app = Flask(__name__)
  6. @app.route('/',methods = ['GET','POST'])
  7. def enter_ID():
  8. if request.method == 'POST':
  9. Galactic_ID = request.form['Galactic_ID']
  10. if Customer(Galactic_ID).find():
  11.  
  12.  
  13. return redirect(url_for('Customer_relationships',Galactic_ID=request.form['Galactic_ID'])
  14. else:
  15. return "Wrong Galactic_ID"
  16.  
  17. else:
  18. return render_template('Gal.html')
  19.  
  20. @app.route('/Customer_Details/<Galactic_ID>')
  21. def Customer_relationships(Galactic_ID):
  22. if Customer(Galactic_ID).get_relationships():
  23. return render_template('rel.html',Galactic_ID=Galactic_ID)
  24.  
  25. if __name__ == '__main__':
  26. host = os.getenv('IP','0.0.0.0')
  27. port = int(os.getenv('PORT',5000))
  28. app.secret_key = os.urandom(24)
  29. app.run(host=host,port=port)
  30.  
  31. import py2neo
  32. from py2neo import Graph,Node,Relationship
  33. graph = Graph()
  34. from py2neo.packages.httpstream import http
  35. from flask import Flask,json,jsonify
  36. http.socket_timeout = 99999
  37.  
  38. class Customer:
  39. def __init__(self,Galactic_ID):
  40. self.Galactic_ID = Galactic_ID
  41.  
  42. def find(self):
  43. Customer = graph.find_one("Customer","Galactic_ID",self.Galactic_ID)
  44. return Customer
  45. def get_relationships(self):
  46. query = """Match (C:Customer)-[r:Customer_Send]->(Send:Customer)
  47. where C.Galactic_ID = {Galactic_ID} Return Send.Galactic_ID as ID """
  48. record = graph.cypher.execute(query,Galactic_ID = self.Galactic_ID,Customer='ID')
  49. returnObject = []
  50. for record in records:
  51. returnObject.append(
  52. {
  53. 'Customer':record.ID
  54.  
  55.  
  56. }
  57. )
  58. x = json.dumps(returnObject)
  59.  
  60. return x
  61.  
  62. <!doctype html>
  63. <head>
  64. <meta charset="UTF-8">
  65. <title>Customer Details</title>
  66. <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
  67. </head>
  68. <body>
  69. <script>
  70.  
  71. $.ajax({
  72. type: "POST",
  73. accept: "application/json",
  74. contentType:"application/json; charset=utf-8",
  75. url: "/Customer_relationships",
  76. data: JSON.stringify(x),
  77. success: function(data, textStatus, jqXHR){
  78. console.log(data);
  79. },
  80. failure: function(msg){console.log("failed")}
  81. });
  82.  
  83. </script>
  84.  
  85.  
  86.  
  87. <title> Customer Details</title>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement