# Path: plugin.py
# class Plugin:
# class PluginManager:
# class Documents:
#     def __init__(self):
#     def user(self):
#     def process(self, request):
#     def unload(self):
#     def __init__(self):
#     def load_plugin(self, name, reload=False):
#     def get_plugins(self):
#     def send_request(self, plugin, request):
#     def __init__(self, plugin: Plugin):
#     def set_document_type(self, name: str):
#     def set_document_table(self, table):
#     def get(self, pid):
#     def list(self, owner):
#     def create(self, pdoc: PluginDocument):
#     def update(pdoc: PluginDocument):
#     def delete(self, pdoc: PluginDocument):
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: plugins/dbupload/dbprofile.py
# class Gene(TableBase):
#     __tablename__ = 'allgeneinfo_all'
#     tax_id = Column(String(10))
#     gene_id = Column(String(10), primary_key=True)
#     Symbol = Column(String(64))
#     LocusTag = Column(Text)
#     Synonyms = Column(Text)
#     dbXrefs = Column(Text)
#     chromosome = Column(Text)
#     map_location = Column(Text)
#     description = Column(Text)
#     type_of_gene = Column(Text)
#     Symbol_from_nomenclature_authority = Column(Text)
#     Full_name_from_nomenclature_authority = Column(Text)
#     Nomenclature_status = Column(Text)
#     Other_designations = Column(Text)
#     Modification_date = Column(Date)


from time import time
from plugin import Plugin, PluginDocument
from database import TableBase, Column, Text, Integer, Boolean
from database import engine, session
from .dbupload.dbprofile import Gene

    def save(self, id, title, data, img, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and doc.owner == self.user.id):
            raise ValueError('Document %d does not exists.' % id)
        doc.title = title
        doc.text = data
        doc.description = img
        doc.last_modified = time()
        self.documents.update(doc)
        return {}

    def list(self, **kwargs):
        docs = self.documents.list(self.user.id)
        return dict(ids=list(map(lambda x:x.id, docs)))

    def load(self, id, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and (doc.owner == self.user.id or doc.public)):
            raise ValueError('Document %d does not exists.' % id)
        return dict(data=doc.text, title=doc.title, owner=doc.owner, ctime=doc.created, mtime=doc.last_modified,
                public=doc.public, comments=eval(doc.comments), praises=len(eval(doc.praises)), img=doc.description)

    def delete(self, id, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and doc.owner == self.user.id):
            raise ValueError('Document %d does not exists.' % id)

# Path: plugin.py
# class Plugin:
# class PluginManager:
# class Documents:
#     def __init__(self):
#     def user(self):
#     def process(self, request):
#     def unload(self):
#     def __init__(self):
#     def load_plugin(self, name, reload=False):
#     def get_plugins(self):
#     def send_request(self, plugin, request):
#     def __init__(self, plugin: Plugin):
#     def set_document_type(self, name: str):
#     def set_document_table(self, table):
#     def get(self, pid):
#     def list(self, owner):
#     def create(self, pdoc: PluginDocument):
#     def update(pdoc: PluginDocument):
#     def delete(self, pdoc: PluginDocument):
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: plugins/dbupload/dbprofile.py
# class Gene(TableBase):
#     __tablename__ = 'allgeneinfo_all'
#     tax_id = Column(String(10))
#     gene_id = Column(String(10), primary_key=True)
#     Symbol = Column(String(64))
#     LocusTag = Column(Text)
#     Synonyms = Column(Text)
#     dbXrefs = Column(Text)
#     chromosome = Column(Text)
#     map_location = Column(Text)
#     description = Column(Text)
#     type_of_gene = Column(Text)
#     Symbol_from_nomenclature_authority = Column(Text)
#     Full_name_from_nomenclature_authority = Column(Text)
#     Nomenclature_status = Column(Text)
#     Other_designations = Column(Text)
#     Modification_date = Column(Date)


# Path: plugins/pano.py
from time import time
from plugin import Plugin, PluginDocument
from database import TableBase, Column, Text, Integer, Boolean
from database import engine, session
from .dbupload.dbprofile import Gene


    def save(self, id, title, data, img, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and doc.owner == self.user.id):
            raise ValueError('Document %d does not exists.' % id)
        doc.title = title
        doc.text = data
        doc.description = img
        doc.last_modified = time()
        self.documents.update(doc)
        return {}

    def list(self, **kwargs):
        docs = self.documents.list(self.user.id)
        return dict(ids=list(map(lambda x:x.id, docs)))

    def load(self, id, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and (doc.owner == self.user.id or doc.public)):
            raise ValueError('Document %d does not exists.' % id)
        return dict(data=doc.text, title=doc.title, owner=doc.owner, ctime=doc.created, mtime=doc.last_modified,
                public=doc.public, comments=eval(doc.comments), praises=len(eval(doc.praises)), img=doc.description)

    def delete(self, id, **kwargs):
        id = int(id)
        doc = self.documents.get(id)
        if not (doc and doc.owner == self.user.id):
            raise ValueError('Document %d does not exists.' % id)

        self.documents.delete(doc)