class Category(Entity): using_options(tablename='category') name = Field(Unicode, primary_key=True) code_sous_cat = Field(Unicode) path = Field(Unicode) url = Field(Unicode) videos = OneToMany('Video') config = ManyToMany('Config', inverse='categories') config_availables = ManyToMany('Config', inverse='categories_availables') def __init__(self, name, dir_user, code_sous_cat, url, create_path=False): self.name = unicode(name) if dir_user: self.path = os.path.join(unicode(dir_user), self.name) self.code_sous_cat = unicode(code_sous_cat) self.url = unicode(url) self.videos = [] if create_path and not os.path.exists(self.path): try: os.makedirs(self.path) except Exception, e: print "%s ne peut être créé" % self.path exit(2)
class Group(Entity): group_id = Field(Integer, primary_key=True) group_name = Field(Unicode(16), unique=True) display_name = Field(Unicode(255)) created = Field(DateTime, default=datetime.now) users = ManyToMany('User', inverse='groups') permissions = ManyToMany('Permission', inverse='groups') using_options(tablename='tg_group')
class nmap_host(Entity): # host attributes checked = Field(String) os_match = Field(String) os_accuracy = Field(String) ip = Field(String) ipv4 = Field(String) ipv6 = Field(String) macaddr = Field(String) status = Field(String) hostname = Field(String) vendor = Field(String) uptime = Field(String) lastboot = Field(String) distance = Field(String) state = Field(String) count = Field(String) # host relationships os = ManyToMany('nmap_os') ports = ManyToMany('nmap_port') def __init__(self, os_match='', os_accuracy='', ip='', ipv4='', ipv6='', macaddr='', status='', hostname='', vendor='', uptime='', lastboot='', distance='', state='', count=''): self.checked = 'False' self.os_match = os_match self.os_accuracy = os_accuracy self.ip = ip self.ipv4 = ipv4 self.ipv6 = ipv6 self.macaddr = macaddr self.status = status self.hostname = hostname self.vendor = vendor self.uptime = uptime self.lastboot = lastboot self.distance = distance self.state = state self.count = count
class Config(Entity): using_options(tablename='config') dir_user = Field(Unicode) player = Field(Unicode) blacklist = ManyToMany('Download', inverse='blacklist') categories_availables = ManyToMany('Category') categories = ManyToMany('Category') def __init__(self, dir_user, player): self.dir_user = unicode(dir_user) self.player = unicode(player) self.categories_availables = [] self.categories = [] self.blacklist = []
class HaploGroup(Entity): """ 2009-3-30 table to store the haplotype groups generated from Alex """ short_name = Field(String(40), unique=True) ref_ecotype = ManyToOne( "Ecotype", colname='ref_ecotypeid', ondelete='CASCADE', onupdate='CASCADE') #the ecotype with the best reference genotype. latitude = Field(Float) longitude = Field(Float) max_snp_typing_error_rate = Field(Float) comment = Field(String(8192)) ecotypes = ManyToMany("Ecotype", tablename='haplo_group2ecotype', ondelete='CASCADE', onupdate='CASCADE') created_by = Field(String(200)) updated_by = Field(String(200)) date_created = Field(DateTime, default=datetime.now) date_updated = Field(DateTime) using_options(tablename='haplo_group', metadata=__metadata__, session=__session__) using_table_options(mysql_engine='InnoDB') using_table_options(UniqueConstraint('short_name', 'ref_ecotypeid'))
class DataCard(Entity): '''Card mapper''' using_options(tablename='card') title = Field(UnicodeText) index = Field(Integer) creation_date = Field(DateTime, default=datetime.datetime.utcnow) column = ManyToOne('DataColumn') # feature data to move to card extensions members = ManyToMany('DataUser') def update(self, other): self.title = other.title self.index = other.index session.flush() # Methods for data belonging to card extensions def remove_member(self, datauser): if datauser in self.members: self.members.remove(datauser) @property def archived(self): return self.column.archive
class DataLabel(Entity): """Label mapper """ using_options(tablename='label') title = Field(Unicode(255)) color = Field(Unicode(255)) board = ManyToOne('DataBoard') cards = ManyToMany('DataCard', tablename='label_cards__card_labels') index = Field(Integer) def copy(self): new_data = DataLabel(title=self.title, color=self.color, index=self.index) return new_data def remove(self, card): self.cards.remove(card) def add(self, card): self.cards.append(card) @classmethod def get_by_card(cls, card): q = cls.query q = q.filter(cls.cards.contains(card)) return q.order_by(cls.index)
class DataLabel(Entity): """Label mapper """ using_options(tablename='label') title = Field(Unicode(255)) color = Field(Unicode(255)) board = ManyToOne('DataBoard') cards = ManyToMany('DataCard', tablename='label_cards__card_labels') index = Field(Integer) def copy(self, parent): new_data = DataLabel(title=self.title, color=self.color, index=self.index, board=parent) session.flush() return new_data @classmethod def get_by_card(cls, card): q = cls.query q = q.filter(cls.cards.contains(card)) return q.all() @classmethod def add_to_card(cls, card, id): label = cls.get(id) if not card in label.cards: label.cards.append(card) @classmethod def remove_from_card(cls, card, id): label = cls.get(id) if card in label.cards: label.cards.remove(card)
class Download(Entity): using_options(tablename='download') url = Field(Unicode, primary_key=True) category = ManyToOne('Category') name = Field(Unicode) path = Field(Unicode) date = Field(Unicode) description = Field(Unicode) blacklist = ManyToMany('Config', inverse='blacklist') def __init__(self, url, category, name, description, date=None): self.url = unicode(url) self.category = category self.description = unicode(description) self.name = unicode(name) self.name = self.name.replace(' ', '_').replace('/', '-') self.date = unicode(date) self.path = unicode(os.path.join(self.category.path, self.name + '.ts')) def rm(self): try: print self.path os.remove(self.path) except: print "cannot remove" pass
class Citation(Entity): """ 2012.6.6 """ cit_id = Field(Integer) #- the unique id of citation cit_key = Field(Text) # -- citation key pubmed_id = Field( Integer) # -- unique id in PubMed database (0 if not in PubMed) medline_id = Field( Integer) # -- unique id in MedLine database (0 if not in MedLine) url = Field(Text) # -- URL associated with citation text = Field(Text) #-- any text (usually article name and authors). #-- The following characters are escaped in this text by a backslash: #-- newline (appear as "\n"), #-- tab character ("\t"), #-- double quotes ('\"'), #-- backslash character ("\\"). tax_list = ManyToMany("Node", tablename='citation2node', local_colname='citation_id') # -- list of node ids separated by a single space created_by = Field(String(256)) updated_by = Field(String(256)) date_created = Field(DateTime, default=datetime.now) date_updated = Field(DateTime) using_options(tablename='citation') using_table_options(mysql_engine='InnoDB')
class Movie(Entity): title = Field(Unicode(60)) description = Field(Unicode(512)) releasedate = Field(DateTime) director = ManyToOne('Director', inverse='movies') actors = ManyToMany('Actor', inverse='movies', tablename='movie_casting') using_options(tablename='movies')
class Permission(Entity): """A relationship that determines what each Group can do""" using_options(tablename="permission", auto_primarykey="permission_id") permission_name = Field(Unicode(16), unique=True) groups = ManyToMany("Group")
class sys_groups(Entity): gid = Field(Integer, primary_key=True) groupname = Field(String(30), required=True) group_password = Field(String(64), required=True) users = OneToMany('sys_users') groupusers = ManyToMany('sys_users', tablename='sys_groupmembers') using_options(tablename='sys_groups') using_table_options(mysql_engine='InnoDB')
class Host(Entity): using_options(tablename='hosts') ip = Field(String) hostnames = ManyToMany('Hostname') def __init__(self, ip=None, hostnames=[]): self.ip = ip self.hostnames = hostnames
class Hostname(Entity): using_options(tablename='hostnames') hostname = Field(String) hosts = ManyToMany('Host') def __init__(self, hostname=None, hosts=[]): self.hostname = hostname self.hosts = hosts
class DataLabel(Entity): """Label mapper """ using_options(tablename='label') title = Field(Unicode(255)) color = Field(Unicode(255)) board = ManyToOne('DataBoard') cards = ManyToMany('DataCard') index = Field(Integer)
class Ecotype(Entity): """ 2009-3-30 add column haplo_groups. """ donor = ManyToOne("Person", colname='donorid', ondelete='CASCADE', onupdate='CASCADE') collector = ManyToOne("Person", colname='collectorid', ondelete='CASCADE', onupdate='CASCADE') site = ManyToOne("Site", colname='siteid', ondelete='CASCADE', onupdate='CASCADE') trip = ManyToOne("Trip", colname='tripid', ondelete='CASCADE', onupdate='CASCADE') organism = ManyToOne("Organism", colname='organismid', ondelete='CASCADE', onupdate='CASCADE') cross = ManyToOne("Cross", colname='crossid', ondelete='CASCADE', onupdate='CASCADE') name = Field(String(50)) alias = Field(String(50)) description = Field(String(270)) barcode = Field(String(14)) stockparent = Field(String(10)) nativename = Field(String(50)) collectiondate = Field(DateTime) latitude = Field(Float) longitude = Field(Float) locationquality = Field(Integer) elevation = Field(String(5)) dnastatus = Field(Integer) bulkstatus = Field(Integer) bulkdate = Field(DateTime) labderived = Field(Boolean) incompleteplex = Field(Integer) haplo_groups = ManyToMany("HaploGroup", tablename='haplo_group2ecotype', ondelete='CASCADE', onupdate='CASCADE') geographic_integrity = ManyToOne("GeographicIntegrity", colname='geographic_integrity_id', ondelete='CASCADE', onupdate='CASCADE') using_options(tablename='ecotype', metadata=__metadata__, session=__session__) using_table_options(mysql_engine='InnoDB')
class Comentario(Entity): data = Field(DateTime) autor = Field(Unicode) autor_url = Field(Unicode) instituicao = Field(Unicode) contribuicao = Field(Unicode) justificativa = Field(Unicode) opiniao = Field(Unicode) proposta = Field(Unicode) tags = ManyToMany(Tag, inverse='comentarios') paragrafo = ManyToOne(Paragrafo)
class Group(Entity): """An ultra-simple group definition.""" using_options(tablename="group", auto_primarykey="group_id") group_name = Field(Unicode(16), unique=True) display_name = Field(Unicode(255)) created = Field(DateTime, default=datetime.now) users = ManyToMany("User") permissions = ManyToMany( "Permission", inverse="groups", tablename="group_permission", local_colname="group_id", remote_colname="permission_id", )
class Tag(Entity): using_options(tablename='tags') name = Field(Unicode(60), required=True) movies = ManyToMany('Movie') def __unicode__(self): return self.name class Admin(EntityAdmin): form_size = (400,200) list_display = ['name'] form_display = ['name', 'movies'] lines_per_row = 2
class nmap_port(Entity): port_id = Field(String) protocol = Field(String) state = Field(String) host = ManyToOne('nmap_host') service = ManyToOne('nmap_service') script = ManyToMany('nmap_script') def __init__(self, port_id, protocol, state, host, service=''): self.port_id = port_id self.protocol = protocol self.state = state self.host = host self.service = service
class Station(Entity): name = Field(String(256)) url = Field(String(256)) bitrate = ManyToOne('Bitrate') stream = ManyToOne('Stream') genres = ManyToMany('Genre') def __init__(self, **kwars): for key, value in kwars.items(): setattr(self, key, value) def __repr__(self): return '<Station %s>' % (self.name)
class User(Entity): user_id = Field(Integer, primary_key=True) user_name = Field(Unicode(16), unique=True) email_address = Field(Unicode(255), unique=True) display_name = Field(Unicode(255)) password = Field(Unicode(40)) created = Field(DateTime, default=datetime.now) groups = ManyToMany('Group', inverse='users') using_options(tablename='tg_user') @property def permissions(self): perms = set() for g in self.groups: perms = perms | set(g.permissions) return perms
class Node(Entity): """ 2012.6.6 taxonomy node and its parent node """ tax_id = Field(Integer, unique=True, primary_key=True) #-- node id in GenBank taxonomy database parent_tax_id = Field( Integer) #2012.6.7 some parent taxonomy node might not exist at all. #parent_tax = ManyToOne('%s.Node'%__name__, colname='parent_tax_id', ondelete='CASCADE', onupdate='CASCADE') rank = Field(Text) #-- rank of this node (superkingdom, kingdom, ...) embl_code = Field(Text) #-- locus-name prefix; not unique division = ManyToOne('%s.Division' % __name__, colname='division_id', ondelete='CASCADE', onupdate='CASCADE') #see division.dmp file inherited_div_flag = Field( Integer) # (1 or 0) -- 1 if node inherits division from parent genetic_code = ManyToOne('%s.Gencode' % __name__, colname='genetic_code_id', ondelete='CASCADE', onupdate='CASCADE') # -- see gencode.dmp file inherited_GC_flag = Field( Integer) #(1 or 0) -- 1 if node inherits genetic code from parent mitochondrial_genetic_code = ManyToOne('%s.Gencode'%__name__, colname='mitochondrial_genetic_code_id', \ ondelete='CASCADE', onupdate='CASCADE') # -- see gencode.dmp file inherited_MGC_flag = Field( Integer ) #(1 or 0) # -- 1 if node inherits mitochondrial gencode from parent GenBank_hidden_flag = Field( Integer ) # (1 or 0) -- 1 if name is suppressed in GenBank entry lineage hidden_subtree_root_flag = Field( Integer) #(1 or 0) -- 1 if this subtree has no sequence data yet comments = Field(Text) citation_list = ManyToMany("Citation", tablename='citation2node', local_colname='tax_id') created_by = Field(String(256)) updated_by = Field(String(256)) date_created = Field(DateTime, default=datetime.now) date_updated = Field(DateTime) using_options(tablename='node') using_table_options(mysql_engine='InnoDB')
class Contrib(Entity): """Mapper for the `contrib' entity """ using_options(shortnames=True) title = Field(String(256)) content = Field(String(600)) original = Field(String(600), default='') status = Field(Boolean, default=False) enabled = Field(Boolean, default=True) parent = Field(Integer, default=0) moderation = Field(Boolean, default=False) user = ManyToOne('User') creation_date = Field(DateTime, default=datetime.now) children = ManyToMany('Contrib') theme = Field(Enum( u'cuidado', u'familia', u'emergencia', u'medicamentos', u'regional' ))
class CallMethod(Entity): """ 2009-5-19 add ManyToMany relationship towards Accession """ short_name = Field(String(100), nullable=False, unique=True) method_description = Field(String(8000)) data_description = Field(String(8000)) comment = Field(String(8000)) created_by = Field(String(128)) updated_by = Field(String(128)) date_created = Field(DateTime, default=datetime.now) date_updated = Field(DateTime) accession_ls = ManyToMany("Accession", tablename='accession2call_method', ondelete='CASCADE', onupdate='CASCADE') using_options(tablename='call_method', metadata=__metadata__, session=__session__) using_table_options(mysql_engine='InnoDB')
class Accession(Entity): """ 2009-5-19 add ManyToMany relationship towards CallMethod """ name = Field(String(100), nullable=False, unique=True) ecotype_id = Field(Integer) duplicate = Field(Integer) accession_2010_id = Field(Integer) created_by = Field(String(128)) updated_by = Field(String(128)) date_created = Field(DateTime, default=datetime.now) date_updated = Field(DateTime) call_method_ls = ManyToMany("CallMethod", tablename='accession2call_method', ondelete='CASCADE', onupdate='CASCADE') using_options(tablename='accession', metadata=__metadata__, session=__session__) using_table_options(mysql_engine='InnoDB')
class DataCard(Entity): '''Card mapper''' using_options(tablename='card') title = Field(UnicodeText) index = Field(Integer) creation_date = Field(DateTime, default=datetime.datetime.utcnow) column = ManyToOne('DataColumn') # feature data to move to card extensions members = ManyToMany('DataUser') def copy(self, parent): new_data = DataCard(title=self.title, column=parent) session.flush() return new_data # Methods for data belonging to card extensions def make_cover(self, asset): """ """ DataCard.get(self.id).cover = asset.data def remove_cover(self): """ """ DataCard.get(self.id).cover = None def remove_member(self, datauser): if datauser in self.members: self.members.remove(datauser) @property def archived(self): return self.column.archive
class User(Entity): """Reasonably basic User definition. Probably would want additional attributes. """ using_options(tablename="tg_user", auto_primarykey="user_id") user_name = Field(Unicode(16), required=True, unique=True) email_address = Field(Unicode(255), required=True, unique=True) display_name = Field(Unicode(255)) created = Field(DateTime, default=datetime.now) _password = Field(Unicode(40), colname="password", required=True) groups = ManyToMany( "Group", inverse="users", tablename="tg_user_group", local_colname="group_id", remote_colname="user_id", ) def _set_password(self, password): """encrypts password on the fly""" self._password = self.__encrypt_password(password) def _get_password(self): """returns password""" return self._password password = descriptor = property(_get_password, _set_password) def __encrypt_password(self, password): """Hash the given password with SHA1.""" if isinstance(password, unicode): password_8bit = password.encode('UTF-8') else: password_8bit = password hashed_password = sha1() hashed_password.update(password_8bit) hashed_password = hashed_password.hexdigest() # make sure the hased password is an UTF-8 object at the end of the # process because SQLAlchemy _wants_ a unicode object for Unicode columns if not isinstance(hashed_password, unicode): hashed_password = hashed_password.decode('UTF-8') return hashed_password def validate_password(self, password): """Check the password against existing credentials. this method _MUST_ return a boolean. @param password: the password that was provided by the user to try and authenticate. This is the clear text version that we will need to match against the (possibly) encrypted one in the database. @type password: unicode object """ return self.password == self.__encrypt_password(password)
class A(Entity): cs = ManyToMany('..db1.c.C')