Commit 463cc4bd authored by Krishnakant Mane's avatar Krishnakant Mane
Browse files

Merge branch 'Alter' into 'master'

Code to alter database fields

See merge request !268
parents 2562d8a9 9cdab0a6
......@@ -6,7 +6,7 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
GNUKhata is Free Software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.and old.stockflag = 's'
the License, or (at your option) any later version.
GNUKhata is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -23,6 +23,7 @@ Contributors:
"Krishnakant Mane" <kk@gmail.com>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
"Prajkta Patkar"<prajkta.patkar007@gmail.com>
"""
from sqlalchemy.engine import create_engine
from gkcore.models.gkdb import metadata
......@@ -45,3 +46,19 @@ def inventoryMigration(con,eng):
except:
con.execute("alter table users add column themename text default 'Default'")
return 0
def addFields(con,eng):
metadata.create_all(eng)
try:
con.execute("select noofpackages,modeoftransport from delchal")
con.execute("select recieveddate from transfernote")
except:
con.execute("alter table transfernote add recieveddate date")
con.execute("alter table delchal add noofpackages int")
con.execute("alter table delchal add modeoftransport text")
return 0
......@@ -6,7 +6,7 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
GNUKhata is Free Software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.and old.stockflag = 's'
the License, or (at your option) any later version.
GNUKhata is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -38,13 +38,14 @@ from pyramid.response import Response
from pyramid.view import view_defaults, view_config
from sqlalchemy.ext.baked import Result
from Crypto.PublicKey import RSA
from gkcore.models.meta import inventoryMigration
from gkcore.models.meta import inventoryMigration,addFields
import jwt
import gkcore
con= Connection
@view_config(route_name='login',request_method='POST',renderer='json')
def gkLogin(request):
"""
purpose: take org code, username and password and authenticate the user.
Return true if username and password matches or false otherwise.
......@@ -60,6 +61,13 @@ def gkLogin(request):
con.execute(select([gkdb.organisation.c.invflag]))
except:
inventoryMigration(con,eng)
try:
con.execute(select([gkdb.delchal.c.modeoftransport,gkdb.delchal.c.noofpackages]))
con.execute(select([gkdb.transfernote.c.recieveddate]))
except:
addFields(con,eng)
dataset = request.json_body
result = con.execute(select([gkdb.users.c.userid]).where(and_(gkdb.users.c.username==dataset["username"], gkdb.users.c.userpassword== dataset["userpassword"], gkdb.users.c.orgcode==dataset["orgcode"])) )
if result.rowcount == 1:
......@@ -87,7 +95,7 @@ def gkLogin(request):
except:
return {"gkstatus":enumdict["ConnectionFailed"]}
finally:
con.close()
con.close()
@view_config(route_name='login',request_method='GET',renderer='json')
def getuserorgdetails(request):
......
......@@ -6,7 +6,7 @@ Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
GNUKhata is Free Software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.and old.stockflag = 's'
the License, or (at your option) any later version.
GNUKhata is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -41,7 +41,8 @@ import gkcore
from gkcore.models.meta import dbconnect
from Crypto.PublicKey import RSA
from gkcore.models.gkdb import metadata
from gkcore.models.meta import inventoryMigration
from gkcore.models.meta import inventoryMigration,addFields
con= Connection
@view_defaults(route_name='organisations')
class api_organisation(object):
......@@ -107,6 +108,12 @@ class api_organisation(object):
self.con.execute(select([gkdb.organisation.c.invflag]))
except:
inventoryMigration(self.con,eng)
try:
con.execute(select([gkdb.delchal.c.modeoftransport,gkdb.delchal.c.noofpackages]))
con.execute(select([gkdb.transfernote.c.recieveddate]))
except:
addFields(self.con,eng)
result = self.con.execute(gkdb.organisation.insert(),[orgdata])
if result.rowcount==1:
code = self.con.execute(select([gkdb.organisation.c.orgcode]).where(and_(gkdb.organisation.c.orgname==orgdata["orgname"], gkdb.organisation.c.orgtype==orgdata["orgtype"], gkdb.organisation.c.yearstart==orgdata["yearstart"], gkdb.organisation.c.yearend==orgdata["yearend"])))
......
Markdown is supported
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