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
b0566599
Commit
b0566599
authored
Nov 11, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUGFIX] Resources - Debugged the duplicata check when appending resource to node
parent
b609b1d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
models.py
node/models.py
+20
-16
No files found.
node/models.py
View file @
b0566599
...
@@ -11,7 +11,7 @@ from parsing.Caches import LanguagesCache, NgramsExtractorsCache, NgramsCaches
...
@@ -11,7 +11,7 @@ from parsing.Caches import LanguagesCache, NgramsExtractorsCache, NgramsCaches
from
parsing.FileParsers
import
*
from
parsing.FileParsers
import
*
from
time
import
time
from
time
import
time
from
collections
import
defaultdict
from
collections
import
defaultdict
from
hashlib
import
md5
import
hashlib
from
gargantext_web.settings
import
MEDIA_ROOT
from
gargantext_web.settings
import
MEDIA_ROOT
...
@@ -88,25 +88,29 @@ class Node(CTENode):
...
@@ -88,25 +88,29 @@ class Node(CTENode):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
def
get_resources
(
self
):
return
Resource
.
objects
.
select_related
(
'node_resource'
)
.
filter
(
node_resource__node
=
self
)
def
add_resource
(
self
,
**
kwargs
):
def
add_resource
(
self
,
**
kwargs
):
# only for tests
# only for tests
# resource = Resource(guid=str(time()), digest=str(time()), **kwargs )
# resource = Resource(guid=str(time()), digest=str(time()), **kwargs )
# Compute the hash
resource
=
Resource
(
**
kwargs
)
m
=
md5
()
# User
m
.
update
(
open
(
str
(
resource
.
file
))
.
read
())
if
'user'
not
in
kwargs
and
'user_id'
not
in
kwargs
:
resource
.
digest
=
m
.
hexdigest
()
resource
.
user
=
self
.
user
resource
.
save
()
# Compute the digest
h
=
hashlib
.
md5
()
f
=
open
(
str
(
resource
.
file
),
'rb'
)
h
.
update
(
f
.
read
())
f
.
close
()
resource
.
digest
=
h
.
hexdigest
()
# check if a resource on this node already has this hash
# check if a resource on this node already has this hash
try
:
tmp_resource
=
self
.
get_resources
()
.
filter
(
digest
=
resource
.
digest
)
.
first
()
node_resource
=
Node_Resource
.
objects
.
get
(
if
tmp_resource
:
node__id
=
self
.
id
,
return
tmp_resource
resource__digest
=
resource
.
digest
else
:
)
resource
.
save
()
resource
=
node_resource
.
resource
except
:
pass
# link with the resource
# link with the resource
node_resource
=
Node_Resource
(
node_resource
=
Node_Resource
(
node
=
self
,
node
=
self
,
...
...
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