api_organisation.py 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
from cornice.resource import resource, view 
from gkcore import eng
from gkcore.models import gkdb
from sqlalchemy.sql import select
import json 
from sqlalchemy.engine.base import Connection
con = Connection
con = eng.connect()

10
@resource(collection_path='/organisation',path='/organisation/{orgcode}')
11
12
13
14
15
class api_organisation(object):
	def __init__(self,request):
		self.request = request

	def collection_get(self):
16
		result = con.execute(select([gkdb.organisation.c.orgcode, gkdb.organisation.c.orgname, gkdb.organisation.c.orgtype,gkdb.organisation.c.yearstart,gkdb.organisation.c.yearend]))
17
18
		orgs = []
		for row in result:
19
			orgs.append({"orgcode":row["orgcode"], "orgname":row["orgname"], "orgtype":row["orgtype"], "yearstart":row["yearstart"], "yearend":row["yearend"]})
20
21
22
23
24
25
26
27
28
		print orgs
		return orgs
		
	@view(renderer='json', accept='text/json')
	def collection_post(self):
		result = self.request.json_body
		con.execute(gkdb.organisation.insert(),[result])

		print result
29
30
		return True	
	
31
32
	def get(self,):
		result = con.execute(select([gkdb.organisation]).where(gkdb.organisation.c.orgcode==self.request.matchdict["orgcode"]))
33
34
35
36
37
		orgDetails = []
		row = result.fetchone()
		orgDetails.append({"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