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
1b4c81be
Commit
1b4c81be
authored
Jan 18, 2016
by
ishan masdekar
Browse files
now when creating organisation an admin user will also be created.
parent
6e45c24b
Changes
1
Hide whitespace changes
Inline
Side-by-side
gkcore/views/api_organisation.py
View file @
1b4c81be
...
...
@@ -36,6 +36,7 @@ from gkcore.models import gkdb
from
sqlalchemy.sql
import
select
import
json
from
sqlalchemy.engine.base
import
Connection
from
sqlalchemy
import
and_
con
=
Connection
con
=
eng
.
connect
()
...
...
@@ -54,10 +55,24 @@ class api_organisation(object):
@
view
(
renderer
=
'json'
,
accept
=
'text/json'
)
def
collection_post
(
self
):
dataset
=
self
.
request
.
json_body
result
=
con
.
execute
(
gkdb
.
organisation
.
insert
(),[
dataset
])
print
result
return
result
.
rowcount
try
:
dataset
=
self
.
request
.
json_body
result
=
con
.
execute
(
gkdb
.
organisation
.
insert
(),[
dataset
])
try
:
orgcode
=
con
.
execute
(
select
([
gkdb
.
organisation
.
c
.
orgcode
]).
where
(
and_
(
gkdb
.
organisation
.
c
.
orgname
==
dataset
[
"orgname"
],
gkdb
.
organisation
.
c
.
orgtype
==
dataset
[
"orgtype"
],
gkdb
.
organisation
.
c
.
yearstart
==
dataset
[
"yearstart"
],
gkdb
.
organisation
.
c
.
yearend
==
dataset
[
"yearend"
])))
user
=
{
"username"
:
"admin"
,
"userrole"
:
-
1
,
"userpassword"
:
"admin"
}
row
=
orgcode
.
fetchone
()
user
[
"orgcode"
]
=
row
[
"orgcode"
]
result1
=
con
.
execute
(
gkdb
.
Users
.
insert
(),[
user
])
return
True
except
:
result
=
con
.
execute
(
gkdb
.
organisation
.
delete
().
where
(
gkdb
.
organisation
.
c
.
orgcode
==
row
[
"orgcode"
]))
return
False
except
:
return
False
def
get
(
self
):
result
=
con
.
execute
(
select
([
gkdb
.
organisation
]).
where
(
gkdb
.
organisation
.
c
.
orgcode
==
self
.
request
.
matchdict
[
"orgcode"
]))
...
...
@@ -67,12 +82,14 @@ class api_organisation(object):
return
orgDetails
def
collection_put
(
self
):
#auth check
dataset
=
self
.
request
.
json_body
result
=
con
.
execute
(
gkdb
.
organisation
.
update
().
where
(
gkdb
.
organisation
.
c
.
orgcode
==
dataset
[
"orgcode"
]).
values
(
dataset
))
print
result
.
rowcount
return
result
.
rowcount
def
collection_delete
(
self
):
#auth check
dataset
=
self
.
request
.
json_body
result
=
con
.
execute
(
gkdb
.
organisation
.
delete
().
where
(
gkdb
.
organisation
.
c
.
orgcode
==
dataset
[
"orgcode"
]))
print
result
.
rowcount
...
...
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