Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import models
- from models import Customer
- from flask import Flask, request, session, redirect, url_for, render_template, flash
- import os
- app = Flask(__name__)
- @app.route('/',methods = ['GET','POST'])
- def enter_ID():
- if request.method == 'POST':
- Galactic_ID = request.form['Galactic_ID']
- if Customer(Galactic_ID).find():
- return redirect(url_for('Customer_relationships',Galactic_ID=request.form['Galactic_ID'])
- else:
- return "Wrong Galactic_ID"
- else:
- return render_template('Gal.html')
- @app.route('/Customer_Details/<Galactic_ID>')
- def Customer_relationships(Galactic_ID):
- if Customer(Galactic_ID).get_relationships():
- return render_template('rel.html',Galactic_ID=Galactic_ID)
- if __name__ == '__main__':
- host = os.getenv('IP','0.0.0.0')
- port = int(os.getenv('PORT',5000))
- app.secret_key = os.urandom(24)
- app.run(host=host,port=port)
- import py2neo
- from py2neo import Graph,Node,Relationship
- graph = Graph()
- from py2neo.packages.httpstream import http
- from flask import Flask,json,jsonify
- http.socket_timeout = 99999
- class Customer:
- def __init__(self,Galactic_ID):
- self.Galactic_ID = Galactic_ID
- def find(self):
- Customer = graph.find_one("Customer","Galactic_ID",self.Galactic_ID)
- return Customer
- def get_relationships(self):
- query = """Match (C:Customer)-[r:Customer_Send]->(Send:Customer)
- where C.Galactic_ID = {Galactic_ID} Return Send.Galactic_ID as ID """
- record = graph.cypher.execute(query,Galactic_ID = self.Galactic_ID,Customer='ID')
- returnObject = []
- for record in records:
- returnObject.append(
- {
- 'Customer':record.ID
- }
- )
- x = json.dumps(returnObject)
- return x
- <!doctype html>
- <head>
- <meta charset="UTF-8">
- <title>Customer Details</title>
- <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
- </head>
- <body>
- <script>
- $.ajax({
- type: "POST",
- accept: "application/json",
- contentType:"application/json; charset=utf-8",
- url: "/Customer_relationships",
- data: JSON.stringify(x),
- success: function(data, textStatus, jqXHR){
- console.log(data);
- },
- failure: function(msg){console.log("failed")}
- });
- </script>
- <title> Customer Details</title>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement