Commit 0df6b588 authored by ishan masdekar's avatar ishan masdekar
Browse files

added enumdict error handler in organisation api

parent 8752f7c7
......@@ -31,7 +31,7 @@ Contributor:
from pyramid.view import view_defaults, view_config
from gkcore import eng
from gkcore import eng, enumdict
from gkcore.models import gkdb
from sqlalchemy.sql import select, distinct
import json
......@@ -49,21 +49,27 @@ class api_organisation(object):
@view_config(request_method='GET', renderer ='json')
def getOrgs(self):
try:
result = con.execute(select([gkdb.organisation.c.orgname, gkdb.organisation.c.orgtype]).distinct())
orgs = []
for row in result:
orgs.append({"orgname":row["orgname"], "orgtype":row["orgtype"]})
print orgs
return orgs
return {"gkstatus":enumdict["Success"], "gkdata":orgs}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(route_name='orgyears', request_method='GET', renderer ='json')
def getYears(self):
try:
result = con.execute(select([gkdb.organisation.c.yearstart, gkdb.organisation.c.yearend,gkdb.organisation.c.orgcode]).where(and_(gkdb.organisation.c.orgname==self.request.matchdict["orgname"], gkdb.organisation.c.orgtype == self.request.matchdict["orgtype"])))
years = []
for row in result:
years.append({"yearstart":str(row["yearstart"]), "yearend":str(row["yearend"]),"orgcode":row["orgcode"]})
print years
return years
return {"gkstatus":enumdict["Success"],"gkdata":years}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(request_method='POST',renderer='json')
def postOrg(self):
......@@ -159,24 +165,29 @@ class api_organisation(object):
record = result.fetchone()
token = jwt.encode({"orgcode":userdata["orgcode"],"userid":record["userid"]},gkcore.secret,algorithm='HS256')
return {"status":"ok","token":token }
return {"gkstatus":enumdict["Success"],"token":token }
else:
return {"status":"invalid"}
return {"gkstatus":enumdict["ConnectionFailed"]}
else:
return False
return {"gkstatus":enumdict["ConnectionFailed"]}
except:
result = con.execute(gkdb.organisation.delete().where(gkdb.organisation.c.orgcode==orgcode["orgcode"]))
return {"gkstatus":enumdict["ConnectionFailed"]}
else:
return False
return {"gkstatus":enumdict["ConnectionFailed"]}
except:
return False
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(route_name='organisation', request_method='GET',renderer='json')
def getOrg(self):
try:
result = con.execute(select([gkdb.organisation]).where(gkdb.organisation.c.orgcode==self.request.matchdict["orgcode"]))
row = result.fetchone()
orgDetails={"orgname":row["orgname"], "orgtype":row["orgtype"], "yearstart":str(row["yearstart"]), "yearend":str(row["yearend"]),"orgcity":row["orgcity"], "orgaddr":row["orgaddr"], "orgpincode":row["orgpincode"], "orgstate":row["orgstate"], "orgcountry":row["orgcountry"], "orgtelno":row["orgtelno"], "orgfax":row["orgfax"], "orgwebsite":row["orgwebsite"], "orgemail":row["orgemail"], "orgpan":row["orgpan"], "orgmvat":row["orgmvat"], "orgstax":row["orgstax"], "orgregno":row["orgregno"], "orgregdate":row["orgregdate"], "orgfcrano":row["orgfcrano"], "orgfcradate":row["orgfcradate"], "roflag":row["roflag"], "booksclosedflag":row["booksclosedflag"] }
return orgDetails
return {"gkstatus":enumdict["Success"],"gkdata":orgDetails}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
@view_config(request_method='PUT', renderer='json')
def putOrg(self):
token = self.request.headers['gktoken']
......@@ -196,6 +207,7 @@ class api_organisation(object):
{"gkstatus": enumdict["BadPrivilege"]}
except:
return {"gkstatus": enumdict["ConnectionFailed"]}
@view_config(request_method='DELETE', renderer='json')
def deleteOrg(self):
token = self.request.headers['gktoken']
......@@ -217,7 +229,10 @@ class api_organisation(object):
@view_config(route_name='orgid', request_method='GET',renderer='json')
def getOrgCode(self):
try:
result = con.execute(select([gkdb.organisation.c.orgcode]).where(and_(gkdb.organisation.c.orgname==self.request.matchdict["orgname"], gkdb.organisation.c.orgtype==self.request.matchdict["orgtype"], gkdb.organisation.c.yearstart==self.request.matchdict["yearstart"], gkdb.organisation.c.yearend==self.request.matchdict["yearend"])))
row = result.fetchone()
orgcode={"orgcode":row["orgcode"]}
return orgcode
return {"gkstatus":enumdict["Success"],"gkdata":orgcode}
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment