class DbUser(Base): __tablename__ = "db_dbuser" id = Column(Integer, primary_key=True) email = Column(String(254), unique=True, index=True) password = Column(String(128)) # Clear text password ? first_name = Column(String(254), nullable=True) last_name = Column(String(254), nullable=True) institution = Column(String(254), nullable=True) is_staff = Column(Boolean, default=False) is_active = Column(Boolean, default=False) last_login = Column(DateTime(timezone=True), default=timezone.now) date_joined = Column(DateTime(timezone=True), default=timezone.now) def get_aiida_class(self): from aiida.backends.djsite.db.models import DbUser as DjangoSchemaDbUser djuser = DjangoSchemaDbUser(id=self.id, email=self.email, password=self.password, first_name=self.first_name, last_name=self.last_name, institution=self.institution, is_staff=self.is_staff, is_active=self.is_active, last_login=self.last_login, date_joined=self.date_joined) return djuser.get_aiida_class()
class DbCalcState(Base): __tablename__ = "db_dbcalcstate" id = Column(Integer, primary_key=True) dbnode = relationship('DbNode', backref=backref('dbstates', passive_deletes=True)) state = Column(String(255)) time = Column(DateTime(timezone=True), default=timezone.now) dbnode_id = Column( Integer, ForeignKey('db_dbnode.id', ondelete="CASCADE", deferrable=True, initially="DEFERRED")) __table_args__ = (UniqueConstraint('dbnode_id', 'state'), )
class DbGroup(Base): __tablename__ = "db_dbgroup" id = Column(Integer, primary_key=True) uuid = Column(UUID(as_uuid=True), default=uuid_func) name = Column(String(255), index=True) type = Column(String(255), default="", index=True) time = Column(DateTime(timezone=True), default=timezone.now) description = Column(Text, nullable=True) user_id = Column( Integer, ForeignKey('db_dbuser.id', ondelete='CASCADE', deferrable=True, initially="DEFERRED")) user = relationship('DbUser', backref=backref('dbgroups', cascade='merge')) dbnodes = relationship('DbNode', secondary=table_groups_nodes, backref="dbgroups", lazy='dynamic') __table_args__ = (UniqueConstraint('name', 'type'), ) def __str__(self): if self.type: return '<DbGroup [type: {}] "{}">'.format(self.type, self.name) else: return '<DbGroup [user-defined] "{}">'.format(self.name) def get_aiida_class(self): from aiida.orm.implementation.django.group import Group as DjangoAiidaGroup from aiida.backends.djsite.db.models import DbGroup as DjangoSchemaDbGroup dbgroup = DjangoSchemaDbGroup( id=self.id, type=self.type, uuid=self.uuid, name=self.name, time=self.time, description=self.description, user_id=self.user_id, ) return DjangoAiidaGroup(dbgroup=dbgroup)
class DbNode(Base): __tablename__ = "db_dbnode" id = Column(Integer, primary_key=True) uuid = Column(UUID(as_uuid=True), default=uuid_func) type = Column(String(255), index=True) label = Column(String(255), index=True, nullable=True) description = Column(Text(), nullable=True) ctime = Column(DateTime(timezone=True), default=timezone.now) mtime = Column(DateTime(timezone=True), default=timezone.now) dbcomputer_id = Column(Integer, ForeignKey('db_dbcomputer.id', deferrable=True, initially="DEFERRED"), nullable=True) dbcomputer = relationship('DbComputer', backref=backref('dbnodes', passive_deletes=True)) user_id = Column(Integer, ForeignKey('db_dbuser.id', deferrable=True, initially="DEFERRED"), nullable=False) user = relationship('DbUser', backref='dbnodes') public = Column(Boolean, default=False) nodeversion = Column(Integer, default=1) attributes = relationship('DbAttribute', uselist=True, backref='dbnode') extras = relationship('DbExtra', uselist=True, backref='dbnode') outputs = relationship("DbNode", secondary="db_dblink", primaryjoin="DbNode.id == DbLink.input_id", secondaryjoin="DbNode.id == DbLink.output_id", backref=backref("inputs", passive_deletes=True), passive_deletes=True) children = relationship("DbNode", secondary="db_dbpath", primaryjoin="DbNode.id == DbPath.parent_id", secondaryjoin="DbNode.id == DbPath.child_id", backref="parents") def get_aiida_class(self): """ Return the corresponding instance of :func:`~aiida.orm.implementation.django.node.Node` or a subclass return by the plugin loader. .. todo:: The behavior is quite pathetic, creating a django DbNode instance to instantiate the aiida instance. These means that every time you load Aiida instances with the QueryBuilder when using Django as a backend, three instances are instantiated for every Aiida instance you load! Could be fixed by allowing DbNode from the dummy nodel to be passed to AiidaNode's __init__. :returns: An instance of the plugin class """ # I need to import the DbNode in the Django model, # and instantiate an object that has the same attributes as self. from aiida.backends.djsite.db.models import DbNode as DjangoSchemaDbNode dbnode = DjangoSchemaDbNode(id=self.id, type=self.type, uuid=self.uuid, ctime=self.ctime, mtime=self.mtime, label=self.label, dbcomputer_id=self.dbcomputer_id, user_id=self.user_id, public=self.public, nodeversion=self.nodeversion) return dbnode.get_aiida_class()