Commit 1a34901f021759b2d60a2f9c8ef9eec88f0a01a9
1 parent
ed34db4c
Exists in
master
and in
1 other branch
- add topics from graph to the database
Showing
2 changed files
with
15 additions
and
5 deletions
Show diff stats
app.py
@@ -33,11 +33,14 @@ class LearnApp(object): | @@ -33,11 +33,14 @@ class LearnApp(object): | ||
33 | self.online = {} | 33 | self.online = {} |
34 | 34 | ||
35 | # connect to database and check registered students | 35 | # connect to database and check registered students |
36 | - self.setup_db('students.db') # FIXME | 36 | + self.db_setup('students.db') # FIXME |
37 | 37 | ||
38 | # build dependency graph | 38 | # build dependency graph |
39 | self.build_dependency_graph('demo/config.yaml') # FIXME | 39 | self.build_dependency_graph('demo/config.yaml') # FIXME |
40 | 40 | ||
41 | + # add topics from depgraph to the database | ||
42 | + self.db_add_topics() | ||
43 | + | ||
41 | # ------------------------------------------------------------------------ | 44 | # ------------------------------------------------------------------------ |
42 | def login(self, uid, try_pw): | 45 | def login(self, uid, try_pw): |
43 | with self.db_session() as s: | 46 | with self.db_session() as s: |
@@ -180,9 +183,16 @@ class LearnApp(object): | @@ -180,9 +183,16 @@ class LearnApp(object): | ||
180 | self.depgraph = g | 183 | self.depgraph = g |
181 | 184 | ||
182 | # ------------------------------------------------------------------------ | 185 | # ------------------------------------------------------------------------ |
186 | + def db_add_topics(self): | ||
187 | + with self.db_session() as s: | ||
188 | + tt = [t[0] for t in s.query(Topic.id).all()] # db list of topics | ||
189 | + nn = self.depgraph.nodes_iter() # topics in the graph | ||
190 | + s.add_all([Topic(id=n) for n in nn if n not in tt]) | ||
191 | + | ||
192 | + # ------------------------------------------------------------------------ | ||
183 | # setup and check database | 193 | # setup and check database |
184 | - def setup_db(self, db): | ||
185 | - engine = create_engine(f'sqlite:///{db}', echo=False) | 194 | + def db_setup(self, db): |
195 | + engine = create_engine(f'sqlite:///{db}', echo=True) | ||
186 | self.Session = sessionmaker(bind=engine) | 196 | self.Session = sessionmaker(bind=engine) |
187 | try: | 197 | try: |
188 | with self.db_session() as s: | 198 | with self.db_session() as s: |
models.py
@@ -74,5 +74,5 @@ class Topic(Base): | @@ -74,5 +74,5 @@ class Topic(Base): | ||
74 | # --- | 74 | # --- |
75 | students = relationship('StudentTopic', back_populates='topic') | 75 | students = relationship('StudentTopic', back_populates='topic') |
76 | 76 | ||
77 | - def __init__(self, id): | ||
78 | - self.id = id | 77 | + # def __init__(self, id): |
78 | + # self.id = id |