diff --git a/TODO b/TODO index 071523d..24f2f01 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ TODO: * book.parent is an array, not a dict - should change it over * need to use ORM for all bal, bsl, etc. seems to be causing race conditions and or 'timeouts' + + - sorting books on shelf. Up to Dune books --> is there an overarching series needed, and do it :) diff --git a/series.py b/series.py index 3b55d65..fbac19e 100644 --- a/series.py +++ b/series.py @@ -48,11 +48,21 @@ def CalcAvgRating(sid): return rating def ListOfSeriesWithMissingBooks(): - with db.engine.connect() as conn: - res=conn.exec_driver_sql( "select id, title, num_books, count from ( select s.id, s.title, s.num_books, count(bsl.book_id) from series s left outer join book_series_link bsl on bsl.series_id=s.id where bsl.book_num is not null group by s.id) as foo where num_books > count") + from main import Book_Series_Link + + rows = Series.query.outerjoin(Book_Series_Link).add_columns(Series.id,Series.title,Series.num_books,Book_Series_Link.book_num).order_by(Series.id,Book_Series_Link.book_num).all() tmp=[] - for row in res: - tmp.append({'id': row[0], 'title': row[1]}) + tots={} + for row in rows: + if row.id not in tots: + tots[row.id]={ 'title': row.title, 'num_books': row.num_books, 'count': 0 } + if row.book_num is None: + continue + else: + tots[row.id]['count'] += 1 + for idx in tots: + if tots[idx]['num_books'] > tots[idx]['count']: + tmp.append( { 'id': idx, 'title': tots[idx]['title'] } ) return tmp ################################################################################