From 510db3f6a892b6ef1971cf9f458c253d23a229a5 Mon Sep 17 00:00:00 2001 From: dage <641846382@qq.com> Date: Tue, 22 Jul 2014 10:26:09 +0800 Subject: [PATCH 1/2] 2014/7/22 by linhu --- code/dbapi.py | 27 ++++++++++++++++++++++++++ code/handler/Addtemprelation.py | 15 ++++++++++++++ code/handler/AddtemprelationHandler.py | 15 ++++++++++++++ code/handler/__init__.py | 3 ++- code/main.py | 3 ++- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 code/handler/Addtemprelation.py create mode 100644 code/handler/AddtemprelationHandler.py diff --git a/code/dbapi.py b/code/dbapi.py index c296a7f..9df1733 100644 --- a/code/dbapi.py +++ b/code/dbapi.py @@ -633,5 +633,32 @@ def setCreditByEventIdAndUserName(self,eid,username,credit): return {"errorCode":200,"errorDesc":""} #07/10 + + #add relation from temprelation or not + # lin 7/21 + def addrelation(self,uid,cid,condition,kind): + cursor = self.db.cursor(cursorclass=MySQLdb.cursors.DictCursor) + if(condition!="yes"): + sql="delete from temprelation where uid=%s and cid=%s" + param=(uid,cid) + cursor.execute(sql,param) + self.db.commit() + data=[{'state':0},{'dec':"the cid not accept the request"}]#not accept the request return 0 + result=json.dumps(data) + return result + else: + sql="insert relation(usrid,cid,kind)value(%s,%s,%s)" + param=(uid,cid,kind) + cursor.execute(sql,param) + sql="delete from temprelation where uid=%s and cid=%s" + param=(uid,cid) + cursor.execute(sql,param) + self.db.commit() + data=[{'state':1},{'dec':"add relation success"}]#add relation success return state 1 + result=json.dumps(data) + return result + cursor.close() + + def __del__(self): self.db.close() diff --git a/code/handler/Addtemprelation.py b/code/handler/Addtemprelation.py new file mode 100644 index 0000000..d4e5258 --- /dev/null +++ b/code/handler/Addtemprelation.py @@ -0,0 +1,15 @@ +import tornado.ioloop +import tornado.web +import tornado.httpserver +import json + +class startFollowHandler(tornado.web.RequestHandler): + def get(self): + self.write("

startFollowHandler

") + + def post(self): + content='{"uid":1,"cid":2,"kind":1,"condition":yes}' + j=json.loads(content) + result=self.application.dbapi.addrelation(j['uid'],j['cid'],j['conditon'],j['kind']) + print result + \ No newline at end of file diff --git a/code/handler/AddtemprelationHandler.py b/code/handler/AddtemprelationHandler.py new file mode 100644 index 0000000..dcc7e14 --- /dev/null +++ b/code/handler/AddtemprelationHandler.py @@ -0,0 +1,15 @@ +import tornado.ioloop +import tornado.web +import tornado.httpserver +import json + +class AddtemprelationHandler(tornado.web.RequestHandler): + def get(self): + self.write("

AddtemprelationHandler

") + + def post(self): + content='{"uid":1,"cid":2,"kind":1,"condition":"yes"}' + j=json.loads(content) + result=self.application.dbapi.addrelation(j['uid'],j['cid'],j['condition'],j['kind']) + print result + \ No newline at end of file diff --git a/code/handler/__init__.py b/code/handler/__init__.py index 1aecfa3..708bb43 100644 --- a/code/handler/__init__.py +++ b/code/handler/__init__.py @@ -19,4 +19,5 @@ "UpdateUserInfoHandler", "startFollowHandler", "cancelFollowHandler", - "GetArroundEvent"] + "GetArroundEvent", + "AddtemprelationHandler"] diff --git a/code/main.py b/code/main.py index ec0c974..b17becf 100644 --- a/code/main.py +++ b/code/main.py @@ -37,7 +37,8 @@ def __init__(self): (r"/api/updateuserinfo",UpdateUserInfoHandler.UpdateUserInfoHandler), (r"/api/getAround",GetArroundEvent.GetArroundEvent), (r"/api/startfollow",startFollowHandler.startFollowHandler), - (r"/api/cancelfollow",cancelFollowHandler.cancelFollowHandler)] + (r"/api/cancelfollow",cancelFollowHandler.cancelFollowHandler), + (r"/api/addtemprelation",AddtemprelationHandler.AddtemprelationHandler)] tornado.web.Application.__init__(self,handlers,**settings) self.dbapi=dbapi.dbapi() self.util=util.util() From 2faa3f4e9e02dd1ed424571af5951da982b5cfcd Mon Sep 17 00:00:00 2001 From: dage <641846382@qq.com> Date: Tue, 22 Jul 2014 10:30:49 +0800 Subject: [PATCH 2/2] 2014/7/22 by linhu2.0 --- code/handler/Addtemprelation.py | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 code/handler/Addtemprelation.py diff --git a/code/handler/Addtemprelation.py b/code/handler/Addtemprelation.py deleted file mode 100644 index d4e5258..0000000 --- a/code/handler/Addtemprelation.py +++ /dev/null @@ -1,15 +0,0 @@ -import tornado.ioloop -import tornado.web -import tornado.httpserver -import json - -class startFollowHandler(tornado.web.RequestHandler): - def get(self): - self.write("

startFollowHandler

") - - def post(self): - content='{"uid":1,"cid":2,"kind":1,"condition":yes}' - j=json.loads(content) - result=self.application.dbapi.addrelation(j['uid'],j['cid'],j['conditon'],j['kind']) - print result - \ No newline at end of file