Commit 8fdc4870 authored by sim's avatar sim

[REFACT] Move Base and models imports where they belongs

parent 2e8958d7
......@@ -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
......
from .base import Base
from .nodes import *
from .hyperdata import *
from .users import *
......
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()
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
......
from gargantext.util.db import *
from .base import Base, Column, ForeignKey, relationship, \
Integer, Float, String
from .nodes import Node
__all__ = ['Ngram', 'NodeNgram', 'NodeNodeNgram', 'NodeNgramNgram']
......
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
......
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
......
......@@ -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
########################################################################
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment