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
3ffad0ed
Commit
3ffad0ed
authored
Mar 28, 2018
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean legacy stuff in Node model
parent
f7a2666f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
99 deletions
+5
-99
base.py
gargantext/models/base.py
+2
-1
nodes.py
gargantext/models/nodes.py
+3
-98
No files found.
gargantext/models/base.py
View file @
3ffad0ed
from
sqlalchemy.schema
import
Column
,
ForeignKey
,
UniqueConstraint
,
Index
from
sqlalchemy.schema
import
Column
,
ForeignKey
,
UniqueConstraint
,
Index
from
sqlalchemy.orm
import
relationship
,
validates
from
sqlalchemy.orm
import
relationship
,
validates
from
sqlalchemy.orm.attributes
import
flag_modified
from
sqlalchemy.types
import
TypeDecorator
,
\
from
sqlalchemy.types
import
TypeDecorator
,
\
Integer
,
REAL
,
Boolean
,
DateTime
,
String
,
Text
Integer
,
REAL
,
Boolean
,
DateTime
,
String
,
Text
from
sqlalchemy_utils.types
import
TSVectorType
from
sqlalchemy_utils.types
import
TSVectorType
...
@@ -9,7 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base
...
@@ -9,7 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base
from
sqlalchemy
import
text
from
sqlalchemy
import
text
__all__
=
[
"Column"
,
"ForeignKey"
,
"UniqueConstraint"
,
"Index"
,
"relationship"
,
__all__
=
[
"Column"
,
"ForeignKey"
,
"UniqueConstraint"
,
"Index"
,
"relationship"
,
"text"
,
"text"
,
"flag_modified"
,
"validates"
,
"ValidatorMixin"
,
"validates"
,
"ValidatorMixin"
,
"Integer"
,
"Float"
,
"Boolean"
,
"DateTime"
,
"String"
,
"Text"
,
"Integer"
,
"Float"
,
"Boolean"
,
"DateTime"
,
"String"
,
"Text"
,
"TSVectorType"
,
"TSVectorType"
,
...
...
gargantext/models/nodes.py
View file @
3ffad0ed
from
gargantext.core.db
import
session
from
gargantext.constants
import
NODETYPES
from
gargantext.constants
import
NODETYPES
,
LISTTYPES
from
datetime
import
datetime
from
.base
import
Base
,
Column
,
ForeignKey
,
relationship
,
TypeDecorator
,
Index
,
\
from
.base
import
Base
,
Column
,
ForeignKey
,
relationship
,
TypeDecorator
,
Index
,
\
Integer
,
Float
,
String
,
DateTime
,
JSONB
,
TSVectorType
,
\
Integer
,
Float
,
String
,
DateTime
,
JSONB
,
TSVectorType
,
\
MutableList
,
MutableDict
,
validates
,
ValidatorMixin
,
text
MutableList
,
MutableDict
,
validates
,
ValidatorMixin
,
text
,
\
flag_modified
from
.users
import
User
from
.users
import
User
__all__
=
[
'Node'
,
'NodeNode'
,
'CorpusNode'
]
__all__
=
[
'Node'
,
'NodeNode'
,
'CorpusNode'
]
...
@@ -118,107 +116,14 @@ class Node(ValidatorMixin, Base):
...
@@ -118,107 +116,14 @@ class Node(ValidatorMixin, Base):
def
validate_name
(
self
,
key
,
value
):
def
validate_name
(
self
,
key
,
value
):
return
self
.
enforce_length
(
key
,
value
)
return
self
.
enforce_length
(
key
,
value
)
@
property
def
ngrams
(
self
):
"""Pseudo-attribute allowing to retrieve a node's ngrams.
Returns a query (which can be further filtered), of which returned rows
are the ngram's weight for this node and the ngram.
"""
from
.
import
NodeNgram
,
Ngram
query
=
(
session
.
query
(
NodeNgram
.
weight
,
Ngram
)
.
select_from
(
NodeNgram
)
.
join
(
Ngram
)
.
filter
(
NodeNgram
.
node_id
==
self
.
id
)
)
return
query
def
as_list
(
self
):
"""Retrieve the current node as a list/matrix of ngrams identifiers.
See `gargantext.util.lists` and `gargantext.constants.LISTTYPES`
for more info.
"""
try
:
return
LISTTYPES
[
self
.
typename
](
self
.
id
)
except
KeyError
:
raise
ValueError
(
'This node
\'
s typename is not convertible to a list:
%
s (accepted values:
%
s)'
%
(
self
.
typename
,
', '
.
join
(
LISTTYPES
.
keys
())
))
def
save_hyperdata
(
self
):
def
save_hyperdata
(
self
):
"""This is a necessary, yet ugly trick.
"""This is a necessary, yet ugly trick.
Indeed, PostgreSQL does not yet manage incremental updates (see
Indeed, PostgreSQL does not yet manage incremental updates (see
https://bashelton.com/2014/03/updating-postgresql-json-fields-via-sqlalchemy/)
https://bashelton.com/2014/03/updating-postgresql-json-fields-via-sqlalchemy/)
"""
"""
from
sqlalchemy.orm.attributes
import
flag_modified
flag_modified
(
self
,
'hyperdata'
)
flag_modified
(
self
,
'hyperdata'
)
# # previous trick (even super-uglier)
# hyperdata = self.hyperdata
# self.hyperdata = None
# session.add(self)
# session.commit()
# self.hyperdata = hyperdata
# session.add(self)
# session.commit()
def
children
(
self
,
typename
=
None
,
order
=
None
):
"""Return a query to all the direct children of the current node.
Allows filtering by typename (see `constants.py`)
"""
query
=
session
.
query
(
Node
)
.
filter
(
Node
.
parent_id
==
self
.
id
)
if
typename
is
not
None
:
query
=
query
.
filter
(
Node
.
typename
==
typename
)
if
order
is
not
None
:
query
=
query
.
order_by
(
Node
.
name
)
return
query
def
add_child
(
self
,
**
kwargs
):
"""Create and return a new direct child of the current node.
"""
return
Node
(
user_id
=
self
.
user_id
,
parent_id
=
self
.
id
,
**
kwargs
)
def
status
(
self
,
action
=
None
,
progress
=
0
,
complete
=
False
,
error
=
None
):
"""Get or update the status of the given action.
If no action is given, the status of the first uncomplete or last item
is returned.
The `complete` parameter should be a boolean.
The `error` parameter should be an exception.
"""
date
=
datetime
.
now
()
# if the hyperdata do not have data about status
if
'statuses'
not
in
self
.
hyperdata
:
self
[
'statuses'
]
=
MutableList
()
# if no action name is given, return the last appended status
if
action
is
None
:
for
status
in
self
[
'statuses'
]:
if
not
status
[
'complete'
]:
return
status
if
len
(
self
[
'statuses'
]):
return
self
[
'statuses'
][
-
1
]
return
None
# retrieve the status concerning by the given action name
for
status
in
self
[
'statuses'
]:
if
status
[
'action'
]
==
action
:
if
error
:
status
[
'error'
]
=
error
if
progress
:
status
[
'progress'
]
=
progress
if
complete
:
status
[
'complete'
]
=
complete
if
error
or
progress
or
complete
:
status
[
'date'
]
=
date
return
status
# if no status has been found for the action, append a new one
self
[
'statuses'
]
.
append
(
MutableDict
(
{
'action'
:
action
,
'progress'
:
progress
,
'complete'
:
complete
,
'error'
:
error
,
'date'
:
date
}
))
return
self
[
'statuses'
][
-
1
]
class
CorpusNode
(
Node
):
class
CorpusNode
(
Node
):
...
...
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