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
bacd5e62
Commit
bacd5e62
authored
Mar 31, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUGFIX] Delete Node(s) ok.
parent
5a84cd93
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
50 deletions
+27
-50
api.py
gargantext_web/api.py
+5
-8
urls.py
gargantext_web/urls.py
+1
-1
views.py
gargantext_web/views.py
+21
-41
No files found.
gargantext_web/api.py
View file @
bacd5e62
...
...
@@ -11,9 +11,9 @@ from sqlalchemy import text, distinct
from
sqlalchemy.sql
import
func
from
sqlalchemy.orm
import
aliased
from
gargantext_web.views
import
trash_node
from
gargantext_web.views
import
move_to_trash
from
.db
import
*
from
node
import
models
def
DebugHttpResponse
(
data
):
return
HttpResponse
(
'<html><body style="background:#000;color:#FFF"><pre>
%
s</pre></body></html>'
%
(
str
(
data
),
))
...
...
@@ -200,7 +200,7 @@ class NodesChildrenDuplicates(APIView):
count
=
len
(
duplicate_nodes
)
for
node
in
duplicate_nodes
:
print
(
"deleting node "
,
node
.
id
)
node
.
delete
(
)
move_to_trash
(
node
.
id
)
# print(delete_query)
# # delete_query.delete(synchronize_session=True)
# session.flush()
...
...
@@ -579,6 +579,7 @@ class Nodes(APIView):
return
JsonHttpResponse
({
'id'
:
node
.
id
,
'name'
:
node
.
name
,
'parent_id'
:
node
.
parent_id
,
'type'
:
cache
.
NodeType
[
node
.
type_id
]
.
name
,
# 'type': node.type__name,
#'metadata': dict(node.metadata),
...
...
@@ -598,11 +599,7 @@ class Nodes(APIView):
try
:
previous_type_id
=
node
.
type_id
node
.
type_id
=
cache
.
NodeType
[
'Trash'
]
.
id
session
.
add
(
node
)
session
.
commit
()
move_to_trash
(
node_id
)
msgres
=
node_id
+
" moved to Trash"
except
Exception
as
error
:
...
...
gargantext_web/urls.py
View file @
bacd5e62
...
...
@@ -33,7 +33,7 @@ urlpatterns = patterns('',
# Project Management
url
(
r'^projects/$'
,
views
.
projects
),
url
(
r'^project/(\d+)/$'
,
views_optimized
.
project
),
url
(
r'^delete/(\d+)$'
,
views
.
trash
_node
),
# => api.node('id' = id, children = 'True', copies = False)
url
(
r'^delete/(\d+)$'
,
views
.
delete
_node
),
# => api.node('id' = id, children = 'True', copies = False)
# Corpus management
url
(
r'^project/(\d+)/corpus/(\d+)/$'
,
views
.
corpus
),
...
...
gargantext_web/views.py
View file @
bacd5e62
...
...
@@ -455,7 +455,21 @@ def empty_trash():
node
.
delete
()
def
trash_node
(
request
,
node_id
):
def
move_to_trash
(
node_id
):
try
:
node
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
previous_type_id
=
node
.
type_id
node
.
type_id
=
cache
.
NodeType
[
'Trash'
]
.
id
session
.
add
(
node
)
session
.
commit
()
return
(
previous_type_id
)
except
Exception
as
error
:
print
(
"can not move to trash Node"
+
node_id
+
":"
+
error
)
def
delete_node
(
request
,
node_id
):
# do we have a valid user?
user
=
request
.
user
...
...
@@ -466,52 +480,18 @@ def trash_node(request, node_id):
if
node
.
user_id
!=
user
.
id
:
return
HttpResponseForbidden
()
previous_type_id
=
node
.
type_id
node
.
type_id
=
cache
.
NodeType
[
'Trash'
]
.
id
session
.
add
(
node
)
session
.
commit
()
previous_type_id
=
move_to_trash
(
node_id
)
if
previous_type_id
==
cache
.
NodeType
[
'Project'
]
.
id
:
if
previous_type_id
==
cache
.
NodeType
[
'Corpus'
]
.
id
:
return
HttpResponseRedirect
(
'/project/'
+
str
(
node
.
parent_id
))
else
:
return
HttpResponseRedirect
(
'/projects/'
)
elif
previous_type_id
==
cache
.
NodeType
[
'Corpus'
]
.
id
:
return
HttpResponseRedirect
(
'/project/'
+
str
(
session
.
query
(
Node
.
id
)
.
filter
(
Node
.
id
==
node
.
parent_id
)
.
first
()[
0
]))
if
settings
.
DEBUG
==
True
:
empty_trash
()
def
delete_node
(
request
,
node_id
):
#nodes = session.query(Node).filter(or_(Node.id == node_id, Node.parent_id == node_id)).all()
# try:
# resources = session.query(Node_Resource).filter(Node_Resource.node_id==node_id).all()
# if resources is not None:
# for resource in resources:
# session.delete(resource)
#
# except Exception as error:
# print(error)
#
# node = session.query(Node).filter(Node.id == node_id).first()
# if node is not None:
# session.delete(node)
# session.commit()
node
=
models
.
Node
.
objects
.
get
(
id
=
node_id
)
with
transaction
.
atomic
():
try
:
node
.
children
.
delete
()
except
Exception
as
error
:
print
(
error
)
node
.
delete
()
if
node
.
type_id
==
cache
.
NodeType
[
'Project'
]
.
id
:
return
HttpResponseRedirect
(
'/projects/'
)
elif
node
.
type_id
==
cache
.
NodeType
[
'Corpus'
]
.
id
:
return
HttpResponseRedirect
(
'/project/'
+
node_id
)
def
delete_corpus
(
request
,
project_id
,
node_id
):
# ORM Django
...
...
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