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
8fdc4870
Commit
8fdc4870
authored
Jul 03, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] Move Base and models imports where they belongs
parent
2e8958d7
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
37 additions
and
25 deletions
+37
-25
dbmigrate.py
dbmigrate.py
+2
-2
__init__.py
gargantext/models/__init__.py
+1
-0
base.py
gargantext/models/base.py
+17
-0
hyperdata.py
gargantext/models/hyperdata.py
+2
-1
ngrams.py
gargantext/models/ngrams.py
+2
-2
nodes.py
gargantext/models/nodes.py
+5
-2
users.py
gargantext/models/users.py
+5
-2
db.py
gargantext/util/db.py
+1
-13
json.py
gargantext/util/json.py
+1
-1
framework.py
unittests/framework.py
+1
-2
No files found.
dbmigrate.py
View file @
8fdc4870
...
...
@@ -18,8 +18,8 @@ if __name__ == "__main__":
django_models_names
=
set
(
model
.
_meta
.
db_table
for
model
in
django_models
)
# migrate SQLAlchemy models
from
gargantext
import
models
from
gargantext.util.db
import
Base
,
engine
from
gargantext
.models
import
Base
from
gargantext.util.db
import
engine
sqla_models_names
=
(
model
for
model
in
Base
.
metadata
.
tables
.
keys
()
if
model
not
in
django_models_names
...
...
gargantext/models/__init__.py
View file @
8fdc4870
from
.base
import
Base
from
.nodes
import
*
from
.hyperdata
import
*
from
.users
import
*
...
...
gargantext/models/base.py
0 → 100644
View file @
8fdc4870
from
sqlalchemy.schema
import
Column
,
ForeignKey
,
UniqueConstraint
from
sqlalchemy.orm
import
relationship
from
sqlalchemy.types
import
TypeDecorator
,
\
Integer
,
Float
,
Boolean
,
DateTime
,
String
,
Text
from
sqlalchemy.dialects.postgresql
import
JSONB
,
DOUBLE_PRECISION
as
Double
from
sqlalchemy.ext.mutable
import
MutableDict
,
MutableList
from
sqlalchemy.ext.declarative
import
declarative_base
__all__
=
[
"Column"
,
"ForeignKey"
,
"UniqueConstraint"
,
"relationship"
,
"Integer"
,
"Float"
,
"Boolean"
,
"DateTime"
,
"String"
,
"Text"
,
"TypeDecorator"
,
"JSONB"
,
"Double"
,
"MutableDict"
,
"MutableList"
,
"Base"
]
Base
=
declarative_base
()
gargantext/models/hyperdata.py
View file @
8fdc4870
from
gargantext.util.db
import
*
from
gargantext.constants
import
INDEXED_HYPERDATA
from
.base
import
Base
,
Column
,
ForeignKey
,
TypeDecorator
,
\
Integer
,
Double
,
DateTime
,
String
,
Text
from
.nodes
import
Node
import
datetime
...
...
gargantext/models/ngrams.py
View file @
8fdc4870
from
gargantext.util.db
import
*
from
.base
import
Base
,
Column
,
ForeignKey
,
relationship
,
\
Integer
,
Float
,
String
from
.nodes
import
Node
__all__
=
[
'Ngram'
,
'NodeNgram'
,
'NodeNodeNgram'
,
'NodeNgramNgram'
]
...
...
gargantext/models/nodes.py
View file @
8fdc4870
from
gargantext.util.db
import
*
from
gargantext.util.db
import
session
from
gargantext.util.files
import
upload
from
gargantext.constants
import
*
from
datetime
import
datetime
from
.base
import
Base
,
Column
,
ForeignKey
,
relationship
,
TypeDecorator
,
\
Integer
,
Float
,
String
,
DateTime
,
JSONB
,
\
MutableList
,
MutableDict
from
.users
import
User
__all__
=
[
'Node'
,
'NodeNode'
,
'CorpusNode'
]
...
...
@@ -22,7 +25,7 @@ class NodeType(TypeDecorator):
class
Node
(
Base
):
"""This model can fit many purposes:
myFirstCorpus = session.query(CorpusNode).first()
It intends to provide a generic model, allowing hierarchical structure
...
...
gargantext/models/users.py
View file @
8fdc4870
from
django.contrib.auth
import
models
from
gargantext.util.db
import
*
from
gargantext.util.db
import
session
,
aliased
from
datetime
import
datetime
from
.base
import
Base
,
Column
,
ForeignKey
,
UniqueConstraint
,
\
Integer
,
Boolean
,
DateTime
,
String
__all__
=
[
'User'
,
'Contact'
]
class
User
(
Base
):
...
...
@@ -60,7 +63,7 @@ class User(Base):
"""check if a given node is owned by the user"""
return
(
node
.
user_id
==
self
.
id
)
or
\
node
.
id
in
(
contact
.
id
for
contact
in
self
.
contacts
())
def
get_params
(
self
,
username
=
None
):
print
(
self
.
__dict__
.
items
())
return
self
.
hyperdata
...
...
gargantext/util/db.py
View file @
8fdc4870
...
...
@@ -6,7 +6,6 @@ from gargantext.util.json import json_dumps
# get engine, session, etc.
########################################################################
from
sqlalchemy.orm
import
sessionmaker
,
scoped_session
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
delete
def
get_engine
():
...
...
@@ -22,24 +21,13 @@ def get_engine():
engine
=
get_engine
()
Base
=
declarative_base
()
session
=
scoped_session
(
sessionmaker
(
bind
=
engine
))
########################################################################
# tools to build models
########################################################################
from
sqlalchemy.types
import
*
from
sqlalchemy.schema
import
Column
,
ForeignKey
,
UniqueConstraint
from
sqlalchemy.dialects.postgresql
import
JSONB
,
DOUBLE_PRECISION
from
sqlalchemy.ext.mutable
import
MutableDict
,
MutableList
Double
=
DOUBLE_PRECISION
########################################################################
# useful for queries
########################################################################
from
sqlalchemy.orm
import
aliased
,
relationship
from
sqlalchemy.orm
import
aliased
from
sqlalchemy
import
func
,
desc
########################################################################
...
...
gargantext/util/json.py
View file @
8fdc4870
...
...
@@ -10,7 +10,7 @@ __all__ = ['json_encoder', 'json_dumps']
class
JSONEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
obj
):
from
gargantext.
util.db
import
Base
from
gargantext.
models
import
Base
if
isinstance
(
obj
,
Base
):
return
{
key
:
value
...
...
unittests/framework.py
View file @
8fdc4870
...
...
@@ -26,8 +26,7 @@ environ.setdefault("DJANGO_SETTINGS_MODULE", "gargantext.settings")
DATABASES
[
'default'
][
'NAME'
]
=
DATABASES
[
'default'
][
'TEST'
][
'NAME'
]
setup
()
# models can now be imported
from
gargantext
import
models
# Base is now filled
from
gargantext.util.db
import
Base
# contains metadata.tables
from
gargantext.models
import
Base
# contains metadata.tables
# ------------------------------------------------------------------------------
# thanks to our hack, util.db.engine and util.db.session already use the test DB
...
...
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