From 1a34901f021759b2d60a2f9c8ef9eec88f0a01a9 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Tue, 28 Feb 2017 17:54:10 +0000 Subject: [PATCH] - add topics from graph to the database --- app.py | 16 +++++++++++++--- models.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 84d642c..bbf9166 100644 --- a/app.py +++ b/app.py @@ -33,11 +33,14 @@ class LearnApp(object): self.online = {} # connect to database and check registered students - self.setup_db('students.db') # FIXME + self.db_setup('students.db') # FIXME # build dependency graph self.build_dependency_graph('demo/config.yaml') # FIXME + # add topics from depgraph to the database + self.db_add_topics() + # ------------------------------------------------------------------------ def login(self, uid, try_pw): with self.db_session() as s: @@ -180,9 +183,16 @@ class LearnApp(object): self.depgraph = g # ------------------------------------------------------------------------ + def db_add_topics(self): + with self.db_session() as s: + tt = [t[0] for t in s.query(Topic.id).all()] # db list of topics + nn = self.depgraph.nodes_iter() # topics in the graph + s.add_all([Topic(id=n) for n in nn if n not in tt]) + + # ------------------------------------------------------------------------ # setup and check database - def setup_db(self, db): - engine = create_engine(f'sqlite:///{db}', echo=False) + def db_setup(self, db): + engine = create_engine(f'sqlite:///{db}', echo=True) self.Session = sessionmaker(bind=engine) try: with self.db_session() as s: diff --git a/models.py b/models.py index f18342d..bfc0bb9 100644 --- a/models.py +++ b/models.py @@ -74,5 +74,5 @@ class Topic(Base): # --- students = relationship('StudentTopic', back_populates='topic') - def __init__(self, id): - self.id = id + # def __init__(self, id): + # self.id = id -- libgit2 0.21.2