@@ -210,10 +210,8 @@ def trle_page(offset, con, limit=20, sort_latest_first=False):
210210 """Get a trle page."""
211211 page = data_factory .make_trle_page_data ()
212212 page ['offset' ] = offset
213-
214- order_direction = 1 if sort_latest_first else 0
215-
216213 result = []
214+
217215 page ['records_total' ] = tombll_common .query_return_everything ("""
218216 SELECT COUNT(*)
219217 FROM Info
@@ -222,29 +220,50 @@ def trle_page(offset, con, limit=20, sort_latest_first=False):
222220 INNER JOIN Author ON Author.AuthorID = AuthorList.authorID
223221 """ , None , con )[0 ][0 ]
224222
225- result = tombll_common .query_return_everything ("""
226- SELECT
227- Info.trleID,
228- Author.value,
229- Info.title,
230- InfoDifficulty.value,
231- InfoDuration.value,
232- InfoClass.value,
233- InfoType.value,
234- Info.release
235- FROM Info
236- INNER JOIN Level ON (Info.InfoID = Level.infoID)
237- INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
238- INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
239- LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
240- LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
241- INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
242- LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
243- ORDER BY
244- CASE WHEN ? = 0 THEN Info.release END ASC,
245- CASE WHEN ? = 1 THEN Info.release END DESC
246- LIMIT ? OFFSET ?;
247- """ , (order_direction , order_direction , limit , offset ), con )
223+ if sort_latest_first :
224+ result = tombll_common .query_return_everything ("""
225+ SELECT
226+ Info.trleID,
227+ Author.value,
228+ Info.title,
229+ InfoDifficulty.value,
230+ InfoDuration.value,
231+ InfoClass.value,
232+ InfoType.value,
233+ Info.release
234+ FROM Info
235+ INNER JOIN Level ON (Info.InfoID = Level.infoID)
236+ INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
237+ INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
238+ LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
239+ LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
240+ INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
241+ LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
242+ ORDER BY Info.release DESC
243+ LIMIT ? OFFSET ?
244+ """ , (limit , offset ), con )
245+ else :
246+ result = tombll_common .query_return_everything ("""
247+ SELECT
248+ Info.trleID,
249+ Author.value,
250+ Info.title,
251+ InfoDifficulty.value,
252+ InfoDuration.value,
253+ InfoClass.value,
254+ InfoType.value,
255+ Info.release
256+ FROM Info
257+ INNER JOIN Level ON (Info.InfoID = Level.infoID)
258+ INNER JOIN AuthorList ON (Level.LevelID = AuthorList.levelID)
259+ INNER JOIN Author ON (Author.AuthorID = AuthorList.authorID)
260+ LEFT JOIN InfoDifficulty ON (InfoDifficulty.InfoDifficultyID = Info.difficulty)
261+ LEFT JOIN InfoDuration ON (InfoDuration.InfoDurationID = Info.duration)
262+ INNER JOIN InfoType ON (InfoType.InfoTypeID = Info.type)
263+ LEFT JOIN InfoClass ON (InfoClass.InfoClassID = Info.class)
264+ ORDER BY Info.release ASC
265+ LIMIT ? OFFSET ?
266+ """ , (limit , offset ), con )
248267
249268 for row in result :
250269 level = data_factory .make_trle_level_data ()
0 commit comments