Commit 59c3792a authored by delanoe's avatar delanoe

[ADMIN] Init accounts for mass creation with group.

parent 06b4cdd5
## TODO
## Version 3.0.6.2
* Guided Tour * Guided Tour
* Sources form highlighting crawlers
## Version 3.0.6.1 ## Version 3.0.6.1
* Sources form highlighting crawlers * SQL Table change. Update:
* psql gargandb
* drop table contacts
* ./manage.py dbmigrate.py
* Init accounts with ISC-PIF partner group
* Link to Licence * Link to Licence
## Version 3.0.6 ## Version 3.0.6
......
...@@ -6,7 +6,6 @@ from datetime import datetime ...@@ -6,7 +6,6 @@ from datetime import datetime
from .users import User from .users import User
__all__ = ['Node', 'NodeNode'] __all__ = ['Node', 'NodeNode']
class NodeType(TypeDecorator): class NodeType(TypeDecorator):
......
...@@ -3,11 +3,9 @@ from gargantext.util.db import * ...@@ -3,11 +3,9 @@ from gargantext.util.db import *
from datetime import datetime from datetime import datetime
__all__ = ['User'] __all__ = ['User', 'Contact']
class User(Base): class User(Base):
# The properties below are a reflection of Django's auth module's models. # The properties below are a reflection of Django's auth module's models.
__tablename__ = models.User._meta.db_table __tablename__ = models.User._meta.db_table
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -48,6 +46,7 @@ class User(Base): ...@@ -48,6 +46,7 @@ class User(Base):
return query return query
def contacts_nodes(self, typename=None): def contacts_nodes(self, typename=None):
from .nodes import Node
for contact in self.contacts(): for contact in self.contacts():
contact_nodes = (session contact_nodes = (session
.query(Node) .query(Node)
...@@ -61,15 +60,16 @@ class User(Base): ...@@ -61,15 +60,16 @@ class User(Base):
"""check if a given node is owned by the user""" """check if a given node is owned by the user"""
return (node.user_id == self.id) or \ return (node.user_id == self.id) or \
node.id in (contact.id for contact in self.contacts()) node.id in (contact.id for contact in self.contacts())
def get_params(self, username=None): def get_params(self, username=None):
print(self.__dict__.items()) print(self.__dict__.items())
return self.hyperdata return self.hyperdata
class Contact(Base): class Contact(Base):
__tablename__ = 'contacts' __tablename__ = 'contacts'
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True, autoincrement=True)
user1_id = Column(Integer, primary_key=True) user1_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'))
user2_id = Column(Integer, primary_key=True) user2_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'))
is_blocked = Column(Boolean(), default=False) is_blocked = Column(Boolean(), default=False)
date_creation = Column(DateTime(timezone=False)) date_creation = Column(DateTime(timezone=False))
......
...@@ -2,7 +2,9 @@ from gargantext import settings ...@@ -2,7 +2,9 @@ from gargantext import settings
from gargantext.util.json import json_dumps from gargantext.util.json import json_dumps
########################################################################
# get engine, session, etc. # get engine, session, etc.
########################################################################
from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import delete from sqlalchemy import delete
...@@ -25,21 +27,24 @@ Base = declarative_base() ...@@ -25,21 +27,24 @@ Base = declarative_base()
session = scoped_session(sessionmaker(bind=engine)) session = scoped_session(sessionmaker(bind=engine))
########################################################################
# tools to build models # tools to build models
########################################################################
from sqlalchemy.types import * from sqlalchemy.types import *
from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB, DOUBLE_PRECISION from sqlalchemy.dialects.postgresql import JSONB, DOUBLE_PRECISION
from sqlalchemy.ext.mutable import MutableDict, MutableList from sqlalchemy.ext.mutable import MutableDict, MutableList
Double = DOUBLE_PRECISION Double = DOUBLE_PRECISION
########################################################################
# useful for queries # useful for queries
########################################################################
from sqlalchemy.orm import aliased from sqlalchemy.orm import aliased
from sqlalchemy import func, desc from sqlalchemy import func, desc
########################################################################
# bulk insertions # bulk insertions
########################################################################
import psycopg2 import psycopg2
def get_cursor(): def get_cursor():
...@@ -54,7 +59,6 @@ def get_cursor(): ...@@ -54,7 +59,6 @@ def get_cursor():
return db, db.cursor() return db, db.cursor()
class bulk_insert: class bulk_insert:
def __init__(self, table, fields, data, cursor=None): def __init__(self, table, fields, data, cursor=None):
# prepare the iterator # prepare the iterator
self.iter = iter(data) self.iter = iter(data)
...@@ -85,7 +89,6 @@ class bulk_insert: ...@@ -85,7 +89,6 @@ class bulk_insert:
readline = read readline = read
def bulk_insert_ifnotexists(model, uniquekey, fields, data, cursor=None, do_stats=False): def bulk_insert_ifnotexists(model, uniquekey, fields, data, cursor=None, do_stats=False):
""" """
Inserts bulk data with an intermediate check on a uniquekey Inserts bulk data with an intermediate check on a uniquekey
......
This diff is collapsed.
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