Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
54123c55
Commit
54123c55
authored
Dec 15, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] project sharing OK
parent
6a455036
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
292 additions
and
138 deletions
+292
-138
urls.py
gargantext_web/urls.py
+3
-1
views.py
gargantext_web/views.py
+35
-17
views_optimized.py
gargantext_web/views_optimized.py
+32
-12
copy.py
node/copy.py
+1
-1
NgramsExtractor.py
parsing/NgramsExtractors/NgramsExtractor.py
+4
-4
TurboNgramsExtractor.py
parsing/NgramsExtractors/TurboNgramsExtractor.py
+4
-4
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+3
-3
menu.html
templates/corpus/menu.html
+0
-82
terms.html
templates/corpus/terms.html
+3
-1
projects.html
templates/projects.html
+144
-4
views.py
tests/ngramstable/views.py
+63
-9
No files found.
gargantext_web/urls.py
View file @
54123c55
...
...
@@ -107,7 +107,9 @@ urlpatterns = patterns('',
url
(
r'^explorer$'
,
samtest
.
graph_share
),
# global explorer
url
(
r'^explorer/(\d+)/(\d+)$'
,
samtest
.
graph_share
),
# global explorer
url
(
r'^node_link_share.json$'
,
samtest
.
node_link_share
),
# global explorer
url
(
r'^get_groups$'
,
samtest
.
get_groups
)
url
(
r'^get_groups$'
,
samtest
.
get_groups
),
url
(
r'^api/share/(\d+)/(\d+)$'
,
samtest
.
share_resource
),
# url(r'^lalala/(\d+)/(\d+)$', samtest.copy_corpus_GET),
)
...
...
gargantext_web/views.py
View file @
54123c55
...
...
@@ -232,8 +232,39 @@ def projects(request):
# print(Logger.write("STATIC_ROOT"))
projects
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user_id
,
Node
.
type_id
==
project_type_id
)
.
order_by
(
Node
.
date
)
.
all
()
number
=
len
(
projects
)
# common_users = session.query(User_User.user_parent).filter( User_User.user_id==user_id ).all()
# [ Getting shared projects ] #
common_users
=
[]
common_projects
=
[]
the_query
=
""" SELECT node_user_user.user_parent, auth_user.username
\
FROM node_user_user, auth_user
\
WHERE node_user_user.user_id=
%
d
\
AND node_user_user.user_parent=auth_user.id """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
common_users
=
cursor
.
fetchall
()
except
:
pass
for
u
in
common_users
:
u_id
=
u
[
0
]
u_name
=
u
[
1
]
shared_projects
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
u_id
,
Node
.
type_id
==
project_type_id
)
.
order_by
(
Node
.
date
)
.
all
()
print
(
"admin group user ID:"
,
u_id
,
" | nb_projects:"
,
len
(
shared_projects
))
if
len
(
shared_projects
)
>
0
:
for
p
in
shared_projects
:
common_projects
.
append
(
p
)
if
len
(
common_projects
)
==
0
:
common_projects
=
False
if
len
(
common_users
)
==
0
:
common_users
=
False
# [ / Getting shared projects ] #
form
=
ProjectForm
()
if
request
.
method
==
'POST'
:
...
...
@@ -253,7 +284,9 @@ def projects(request):
'date'
:
date
,
'form'
:
form
,
'number'
:
number
,
'projects'
:
projects
'projects'
:
projects
,
'common_projects'
:
common_projects
,
'common_users'
:
common_users
,
})
...
...
@@ -356,20 +389,6 @@ def corpus(request, project_id, corpus_id):
processing
=
"Error"
# [ / getting workflow status ] #
# [ how many groups ? ] #
nb_groups
=
0
the_query
=
""" SELECT group_id FROM auth_user_groups WHERE user_id=
%
d """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
results
=
cursor
.
fetchall
()
nb_groups
=
len
(
results
)
except
:
pass
# [ / how many groups ? ] #
html
=
t
.
render
(
Context
({
'debug'
:
settings
.
DEBUG
,
'user'
:
request
.
user
,
...
...
@@ -379,7 +398,6 @@ def corpus(request, project_id, corpus_id):
'processing'
:
processing
,
# 'documents': documents,\
'number'
:
number
,
'nb_groups'
:
nb_groups
,
'view'
:
"documents"
}))
...
...
gargantext_web/views_optimized.py
View file @
54123c55
...
...
@@ -18,6 +18,7 @@ from gargantext_web.db import *
from
gargantext_web.db
import
get_or_create_node
from
gargantext_web.settings
import
DEBUG
,
MEDIA_ROOT
from
rest_v1_0.api
import
JsonHttpResponse
from
django.db
import
connection
import
json
import
re
...
...
@@ -51,7 +52,15 @@ def project(request, project_id):
if
not
user
.
is_authenticated
():
return
redirect
(
'/login/?next=
%
s'
%
request
.
path
)
if
project
.
user_id
!=
user
.
id
:
return
HttpResponseForbidden
()
in_group
=
""" SELECT user_parent FROM node_user_user WHERE user_id=
%
d"""
%
(
int
(
user
.
id
)
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
in_group
)
in_group
=
False
for
c
in
cursor
.
fetchall
():
if
c
[
0
]
==
project
.
user_id
:
in_group
=
True
if
not
in_group
:
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
# Let's find out about the children nodes of the project
ChildrenNode
=
aliased
(
Node
)
...
...
@@ -241,7 +250,6 @@ def tfidf(request, corpus_id, ngram_ids):
return
JsonHttpResponse
(
nodes_list
)
def
getCorpusIntersection
(
request
,
corpuses_ids
):
FinalDict
=
False
...
...
@@ -259,7 +267,7 @@ def getCorpusIntersection(request , corpuses_ids):
return
JsonHttpResponse
(
FinalDict
)
# If corpus[1] has a coocurrence.id then lets continue
Cooc
_Avg
=
{}
Cooc
s
=
{}
import
networkx
as
nx
G
=
nx
.
Graph
()
# I use an undirected graph, because direction doesnt matter here, coocs should be a triangular matrix, so...
ngrams_data1
=
session
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_ids
[
0
],
NodeNgramNgram
.
ngramx_id
.
in_
(
node_ids
))
.
all
()
...
...
@@ -275,21 +283,20 @@ def getCorpusIntersection(request , corpuses_ids):
n1
=
e
[
0
]
n2
=
e
[
1
]
# print( G[n1][n2]["weight"] , "\t", n1,",",n2 )
if
n1
not
in
Cooc
_Avg
:
Cooc
_Avg
[
n1
]
=
0
if
n2
not
in
Cooc
_Avg
:
Cooc
_Avg
[
n2
]
=
0
Cooc
_Avg
[
n1
]
+=
G
[
n1
][
n2
][
"weight"
]
Cooc
_Avg
[
n2
]
+=
G
[
n1
][
n2
][
"weight"
]
if
n1
not
in
Cooc
s
:
Cooc
s
[
n1
]
=
0
if
n2
not
in
Cooc
s
:
Cooc
s
[
n2
]
=
0
Cooc
s
[
n1
]
+=
G
[
n1
][
n2
][
"weight"
]
Cooc
s
[
n2
]
+=
G
[
n1
][
n2
][
"weight"
]
FinalDict
=
{}
for
node
in
node_ids
:
if
node
in
Cooc
_Avg
:
FinalDict
[
node
]
=
Cooc
_Avg
[
node
]
/
G
.
degree
(
node
)
if
node
in
Cooc
s
:
FinalDict
[
node
]
=
Cooc
s
[
node
]
/
G
.
degree
(
node
)
# Getting AVG-COOC of each ngram that exists in the cooc-matrix of the compared-corpus.
return
JsonHttpResponse
(
FinalDict
)
def
getUserPortfolio
(
request
,
project_id
):
user
=
request
.
user
user_id
=
cache
.
User
[
request
.
user
.
username
]
.
id
...
...
@@ -298,6 +305,18 @@ def getUserPortfolio(request , project_id):
results
=
{}
projs
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user_id
,
Node
.
type_id
==
project_type_id
)
.
all
()
in_group
=
""" SELECT user_parent FROM node_user_user WHERE user_id=
%
d"""
%
(
int
(
user_id
)
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
in_group
)
for
c
in
cursor
.
fetchall
():
user_parent
=
c
[
0
]
more_projs
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
user_parent
,
Node
.
type_id
==
project_type_id
)
.
all
()
if
more_projs
!=
None
:
for
p
in
more_projs
:
projs
.
append
(
p
)
for
i
in
projs
:
# print (i.id,i.name)
if
i
.
id
not
in
results
:
...
...
@@ -320,4 +339,5 @@ def getUserPortfolio(request , project_id):
if
len
(
results
[
i
.
id
][
"corpuses"
])
==
0
:
del
results
[
i
.
id
]
return
JsonHttpResponse
(
results
)
node/copy.py
View file @
54123c55
...
...
@@ -22,7 +22,7 @@ def copy_corpus(from_id=None, to_id=None, title=None):
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
from_id
)
.
first
()
group_id
=
get_or_create_node
(
nodetype
=
'Group'
,
corpus
=
corpus
)
.
id
print
(
[
from_id
,
cache
.
NodeType
[
'Document'
]
.
id
,
'journal'
,
group_id
,
title
,
to_id
]
)
cursor
.
execute
(
'''
CREATE TEMPORARY TABLE node_node__tmp AS
SELECT
...
...
parsing/NgramsExtractors/NgramsExtractor.py
View file @
54123c55
#
from ..Taggers import NltkTagger
from
..Taggers
import
TurboTagger
from
..Taggers
import
NltkTagger
#
from ..Taggers import TurboTagger
import
nltk
...
...
@@ -22,8 +22,8 @@ class NgramsExtractor:
self
.
stop
()
def
start
(
self
):
#
self.tagger = NltkTagger()
self
.
tagger
=
TurboTagger
()
self
.
tagger
=
NltkTagger
()
#
self.tagger = TurboTagger()
def
stop
(
self
):
pass
...
...
parsing/NgramsExtractors/TurboNgramsExtractor.py
View file @
54123c55
from
.NgramsExtractor
import
NgramsExtractor
#
from ..Taggers import NltkTagger
from
..Taggers
import
TurboTagger
from
..Taggers
import
NltkTagger
#
from ..Taggers import TurboTagger
class
TurboNgramsExtractor
(
NgramsExtractor
):
def
start
(
self
):
#
self.tagger = NltkTagger()
self
.
tagger
=
TurboTagger
()
self
.
tagger
=
NltkTagger
()
#
self.tagger = TurboTagger()
static/js/NGrams_dyna_chart_and_table.js
View file @
54123c55
...
...
@@ -1090,9 +1090,9 @@ var NGrams = {
}
$
(
"#corpusdisplayer"
).
hide
()
if
(
$
(
"#share_button"
).
length
==
0
)
{
$
(
"#ImportList"
).
remove
()
}
//
if( $("#share_button").length==0 ) {
//
$("#ImportList").remove()
//
}
var
url
=
[
...
...
templates/corpus/menu.html
View file @
54123c55
...
...
@@ -48,9 +48,6 @@
{% if number == 0 %}
<a
class=
"btn btn-primary btn-lg"
role=
"button"
href=
"/admin/documents/corpus/{{ corpus.id }}/"
>
Add documents
</a></p>
{% endif %}
{% if nb_groups != None and nb_groups > 0 %}
<a
id=
"share_button"
class=
"btn btn-primary btn-lg"
role=
"button"
>
Share!!!
</a></p>
{% endif %}
</div>
</div>
...
...
@@ -121,46 +118,6 @@
</div>
<div
id=
"sharemodal"
class=
"modal fade"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
class=
"modal-title"
>
Share this Corpus with your Groups
</h3>
</div>
<div
class=
"modal-body form-horizontal"
>
<h4>
List of available groups:
</h4>
<div
id=
"groups_list"
>
here show the groups
</div>
<div
class=
"modal-footer"
>
<button
id=
"closesharemodal"
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
<button
id=
"send_share"
type=
"button"
class=
"btn btn-primary"
>
Share
</button>
</div>
</div>
</div>
</div>
</div>
<style>
label
{
padding
:
10px
;
margin
:
0
0
10px
;
display
:
block
;
}
label
:hover
{
background
:
#eee
;
cursor
:
pointer
;
}
</style>
<script
type=
"text/javascript"
>
function
gotoexplorer
(
elem
)
{
...
...
@@ -212,45 +169,6 @@ label:hover {
}
function
get_groups
()
{
console
.
log
(
"IN get_groups()!"
)
var
url_
=
"/get_groups"
$
.
ajax
({
type
:
"GET"
,
url
:
url_
,
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
_content
=
""
for
(
var
i
in
data
)
{
var
g_id
=
data
[
i
][
0
]
,
g_name
=
data
[
i
][
1
]
_content
+=
'<label><input name="groups" data-id="'
+
g_id
+
'" type="checkbox" /> '
+
g_name
+
'</label>'
}
$
(
"#groups_list"
).
html
(
_content
)
},
error
:
function
(
exception
)
{
console
.
log
(
"exception!:"
+
exception
.
status
)
}
});
}
if
(
$
(
"#share_button"
).
length
>
0
)
{
$
(
"#share_button"
).
click
(
function
()
{
get_groups
()
$
(
"#sharemodal"
).
modal
(
"show"
);
});
$
(
"#send_share"
).
click
(
function
()
{
$
(
'input[name=groups]:checked'
).
each
(
function
()
{
console
.
log
(
$
(
this
).
data
(
"id"
)
);
});
});
}
</script>
...
...
templates/corpus/terms.html
View file @
54123c55
...
...
@@ -322,7 +322,9 @@ input[type=radio]:checked + label {
<!-- </optgroup> -->
</select>
<button
id=
"ImportList"
onclick=
"GetUserPortfolio();"
class=
"btn btn-warning"
>
Import a Corpus-List
</button>
{% if nb_groups > 0 %}
<button
id=
"ImportList"
onclick=
"GetUserPortfolio();"
class=
"btn btn-warning"
>
Import a Corpus-List
</button>
{% endif %}
</div>
...
...
templates/projects.html
View file @
54123c55
...
...
@@ -37,6 +37,33 @@
{% if projects %}
{% for project in projects %}
<!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!-->
<div
class=
"col-md-3 content"
>
<h3><a
href=
"/project/{{ project.id }}"
>
{{ project.name }}
</a>
<button
type=
"button"
class=
"btn btn-xs btn-default"
data-container=
"body"
data-toggle=
"popover"
data-placement=
"bottom"
data-content=
'
<ul>
<li> Rename </li>
<li><a href="/project/{{ project.id }}">Add new corpus</a></li>
<li><a href="/delete/{{ project.id }}">Delete</a></li>
</ul>
'
>
Manage
</button>
{% if common_users %}
<a
style=
"cursor:pointer;"
><img
class=
"share_button"
data-id=
"{{ project.id }}"
title=
"Share it!"
width=
"20px"
src=
"{% static "
img
/
share
.
png
"
%}"
></img></a>
{% endif %}
</h3>
<h4>
{{ project.subtitle }}
<h4>
</div>
{% endfor %}
{% endif %}
{% if common_projects %}
<br><br><br><br><br><br>
<h3><i>
- - Shared projects - -
</i></h3>
{% for project in common_projects %}
<!--<div class="col-md-offset-7 col-md-4 content" style="background-color:grey">!-->
<div
class=
"col-md-3 content"
>
<h3><a
href=
"/project/{{ project.id }}"
>
{{ project.name }}
</a>
...
...
@@ -52,10 +79,6 @@
</h3>
<h4>
{{ project.subtitle }}
<h4>
<!--
<h5>Completed:</h5>
<div class="chart" barColor="#fffff" data-percent="75">75%</div>
--!>
</div>
{% endfor %}
{% endif %}
...
...
@@ -63,4 +86,121 @@
</div>
</div>
<div
id=
"sharemodal"
class=
"modal fade"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h3
class=
"modal-title"
>
Share this Corpus with your Groups
</h3>
</div>
<div
class=
"modal-body form-horizontal"
>
<h4>
List of available groups:
</h4>
<div
id=
"groups_list"
>
here show the groups
</div>
<div
class=
"modal-footer"
>
<button
id=
"closesharemodal"
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
<button
id=
"send_share"
type=
"button"
class=
"btn btn-primary"
>
Share
<span
id=
"simpleloader"
></span></button>
</div>
</div>
</div>
</div>
</div>
<style>
label
{
padding
:
10px
;
margin
:
0
0
10px
;
display
:
block
;
}
label
:hover
{
background
:
#eee
;
cursor
:
pointer
;
}
</style>
<script>
function
getCookie
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
var
cookies
=
document
.
cookie
.
split
(
';'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'='
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
var
last_project
=
-
1
function
get_groups
()
{
console
.
log
(
"IN get_groups()!"
)
var
url_
=
"/get_groups"
$
.
ajax
({
type
:
"GET"
,
url
:
url_
,
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
_content
=
""
for
(
var
i
in
data
)
{
var
g_id
=
data
[
i
][
0
]
,
g_name
=
data
[
i
][
1
]
_content
+=
'<label><input name="groups" data-id="'
+
g_id
+
'" type="checkbox" /> '
+
g_name
+
'</label>'
}
$
(
"#groups_list"
).
html
(
_content
)
},
error
:
function
(
exception
)
{
console
.
log
(
"exception!:"
+
exception
.
status
)
}
});
}
if
(
$
(
".share_button"
).
length
>
0
)
{
$
(
".share_button"
).
click
(
function
(){
last_project
=
$
(
this
).
data
(
"id"
)
get_groups
()
$
(
"#sharemodal"
).
modal
(
"show"
);
});
$
(
"#send_share"
).
click
(
function
()
{
$
(
'input[name=groups]:checked'
).
each
(
function
()
{
$
(
"#send_share"
).
attr
(
"disabled"
,
"disabled"
)
console
.
log
(
$
(
this
).
data
(
"id"
)
);
$
(
"#simpleloader"
).
html
(
'<img width="30px" src="{% static "js/libs/img2/loading-bar.gif" %}"></img>'
)
$
.
ajax
({
url
:
"/api/share/"
+
last_project
+
"/"
+
$
(
this
).
data
(
"id"
),
type
:
'POST'
,
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
"X-CSRFToken"
,
getCookie
(
"csrftoken"
));
},
success
:
function
(
data
)
{
console
.
log
(
"SUCCESS!"
)
window
.
location
.
reload
();
},
error
:
function
(
result
)
{
console
.
log
(
"FAIL!"
)
console
.
log
(
result
)
}
});
});
});
}
</script>
{% endblock %}
tests/ngramstable/views.py
View file @
54123c55
...
...
@@ -87,7 +87,7 @@ def get_ngrams(request , project_id , corpus_id ):
# [ how many groups ? ] #
nb_groups
=
0
the_query
=
""" SELECT
group_id FROM auth_user_groups WHERE user_id=
%
d
"""
%
(
int
(
request
.
user
.
id
)
)
the_query
=
""" SELECT
user_parent FROM node_user_user WHERE user_id=
%
d
"""
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
...
...
@@ -205,20 +205,22 @@ def get_groups( request ):
if
not
request
.
user
.
is_authenticated
():
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
results
=
[]
the_query
=
""" SELECT auth_user_groups.group_id, auth_group.name
\
FROM auth_user_groups,auth_group
\
WHERE auth_user_groups.user_id=
%
d
\
AND auth_user_groups.group_id=auth_group.id """
%
(
int
(
request
.
user
.
id
)
)
# [ getting shared projects ] #
common_users
=
[]
common_projects
=
[]
the_query
=
""" SELECT node_user_user.user_parent, auth_user.username
\
FROM node_user_user, auth_user
\
WHERE node_user_user.user_id=
%
d
\
AND node_user_user.user_parent=auth_user.id """
%
(
int
(
request
.
user
.
id
)
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
the_query
)
result
s
=
cursor
.
fetchall
()
common_user
s
=
cursor
.
fetchall
()
except
:
pass
# [ / getting shared projects ] #
return
JsonHttpResponse
(
result
s
)
return
JsonHttpResponse
(
common_user
s
)
def
graph_share
(
request
,
generic
=
100
,
specific
=
100
):
...
...
@@ -270,3 +272,55 @@ def node_link_share(request):
data
=
get_cooc
(
request
=
request
,
corpus
=
corpus
,
type
=
"node_link"
)
return
JsonHttpResponse
(
data
)
def
copy_corpus_GET
(
request
,
project_id
,
corpus_id
):
from
node
import
copy
corpus_id
=
int
(
corpus_id
)
user_id
=
request
.
user
.
id
project_id
=
project_id
import
random
title
=
"clone_"
+
str
(
random
.
random
())
corpus_clone_id
=
copy
.
create_corpus
(
title
,
project_id
=
project_id
,
user_id
=
user_id
)
# print(corpus_clone_id)
copy
.
copy_corpus
(
from_id
=
corpus_id
,
to_id
=
corpus_clone_id
,
title
=
title
)
return
JsonHttpResponse
([
title
,
corpus_clone_id
])
def
share_resource
(
request
,
resource_id
,
group_id
)
:
results
=
[
"OK"
]
if
request
.
method
==
'POST'
:
project2share
=
session
.
query
(
Node
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
id
==
resource_id
)
.
first
()
if
project2share
!=
None
:
# project exists?
# [ is the received group in fact the group of the current user? ]
in_group
=
""" SELECT * FROM node_user_user WHERE user_id=
%
d AND user_parent=
%
d"""
%
(
int
(
request
.
user
.
id
)
,
int
(
group_id
)
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
in_group
)
if
len
(
cursor
.
fetchall
())
<
1
:
return
JsonHttpResponse
(
{
"request"
:
"forbidden"
}
)
# [ / is the received group in fact the group of the current user? ]
# [ getting all childs ids of this project ]
ids2changeowner
=
[
project2share
.
id
]
corpuses
=
session
.
query
(
Node
.
id
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
parent_id
==
resource_id
,
Node
.
type_id
==
cache
.
NodeType
[
"Corpus"
]
.
id
)
.
all
()
for
corpus
in
corpuses
:
ids2changeowner
.
append
(
corpus
.
id
)
lists
=
session
.
query
(
Node
.
id
,
Node
.
name
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
parent_id
==
corpus
.
id
)
.
all
()
for
l
in
lists
:
ids2changeowner
.
append
(
l
.
id
)
# [ / getting all childs ids of this project ]
# [ changing owner ]
print
(
"ids to change owner: "
,
len
(
ids2changeowner
))
print
(
"old owner:"
,
request
.
user
.
id
,
" | new owner:"
,
group_id
)
query
=
"""UPDATE node_node set user_id=
%
d WHERE id IN (
%
s)"""
%
(
int
(
group_id
)
,
','
.
join
((
str
(
n
)
for
n
in
ids2changeowner
))
)
cursor
=
connection
.
cursor
()
try
:
cursor
.
execute
(
query
)
cursor
.
execute
(
"COMMIT;"
)
except
Exception
as
error
:
print
(
error
)
pass
connection
.
close
()
# [ / changing owner ]
return
JsonHttpResponse
(
results
)
\ No newline at end of file
Write
Preview
Markdown
is supported
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