forked from KasenJ/CommunityPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddrelativesHandler.py
More file actions
27 lines (23 loc) · 872 Bytes
/
AddrelativesHandler.py
File metadata and controls
27 lines (23 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''Yeqin Zheng, 09/07/2014'''
import tornado.ioloop
import tornado.web
import tornado.httpserver
import json
''' Add a relation between two users. Succeed with "1" returned, else with "0". '''
class AddrelativesHandler(tornado.web.RequestHandler):
def get(self):
self.write("<p>AddrelativesHandler</p><form action='/api/addrelatives' method='post'><input type='submit' value='submit'></form>")
def post(self):
#content =self.request.body
content = '{"u_name":"test1","r_name":"test2"}'
j = json.loads(content)
row = self.application.dbapi.getRelationByUsername(j['u_name'], j['r_name'])
if row == 0:
self.application.dbapi.addRelationByUsername(j['u_name'], j['r_name'])
add_message = {'state': 1}
print "add relative success"
else:
add_message = {'state': 0}
print "two already has relative relation"
self.write(add_message)
return