Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sakshi Agrawal
gkcore
Commits
e5839b48
Commit
e5839b48
authored
Nov 17, 2016
by
Navin Karkera
Browse files
Added api for creating tables for Inventory.
parent
354f7b4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
gkcore/views/api_organisation.py
View file @
e5839b48
...
...
@@ -40,6 +40,7 @@ import jwt
import
gkcore
from
gkcore.models.meta
import
dbconnect
from
Crypto.PublicKey
import
RSA
from
gkcore.models.gkdb
import
metadata
@
view_defaults
(
route_name
=
'organisations'
)
class
api_organisation
(
object
):
...
...
@@ -407,3 +408,29 @@ class api_organisation(object):
except
:
self
.
con
.
close
()
return
{
"gkstatus"
:
enumdict
[
"ConnectionFailed"
]}
@
view_config
(
request_method
=
'PUT'
,
request_param
=
"type=getinventory"
,
renderer
=
'json'
)
def
getinventory
(
self
):
token
=
self
.
request
.
headers
[
'gktoken'
]
authDetails
=
authCheck
(
token
)
if
authDetails
[
"auth"
]
==
False
:
return
{
"gkstatus"
:
enumdict
[
"UnauthorisedAccess"
]}
else
:
try
:
self
.
con
=
eng
.
connect
()
user
=
self
.
con
.
execute
(
select
([
gkdb
.
users
.
c
.
userrole
]).
where
(
gkdb
.
users
.
c
.
userid
==
authDetails
[
"userid"
]
))
userRole
=
user
.
fetchone
()
dataset
=
self
.
request
.
json_body
if
userRole
[
0
]
==-
1
:
metadata
.
create_all
(
eng
)
print
"database created successfully"
self
.
con
.
execute
(
"alter table categorysubcategories add foreign key (subcategoryof) references categorysubcategories(categorycode)"
)
self
.
con
.
execute
(
"alter table unitofmeasurement add foreign key (subunitof) references unitofmeasurement(uomid)"
)
result
=
self
.
con
.
execute
(
gkdb
.
organisation
.
update
().
where
(
gkdb
.
organisation
.
c
.
orgcode
==
authDetails
[
"orgcode"
]).
values
(
dataset
))
self
.
con
.
close
()
return
{
"gkstatus"
:
enumdict
[
"Success"
]}
else
:
{
"gkstatus"
:
enumdict
[
"BadPrivilege"
]}
except
:
self
.
con
.
close
()
return
{
"gkstatus"
:
enumdict
[
"ConnectionFailed"
]}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment