diff options
author | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-29 20:48:38 -0500 |
---|---|---|
committer | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-29 20:48:38 -0500 |
commit | e673706ae52460507040e83a3428185eb53996bf (patch) | |
tree | e8c32c58dfd51dd6aebb7a3190e9cfb642d8ffe9 /src | |
parent | d5ae142a7f9dc382c06dca424973f4345b181c5b (diff) | |
download | bbj-e673706ae52460507040e83a3428185eb53996bf.tar.gz |
add option to include ops with index (or only ops with gets)
Diffstat (limited to 'src')
-rw-r--r-- | src/db.py | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -79,7 +79,7 @@ def message_feed(connection, time): ### THREADS ### -def thread_get(connection, thread_id, messages=True): +def thread_get(connection, thread_id, messages=True, op_only=False): """ Fetch the thread_id from the database. Formatting is be handled elsewhere. @@ -96,17 +96,18 @@ def thread_get(connection, thread_id, messages=True): raise BBJParameterError("Thread does not exist.") thread = schema.thread(*thread) - if messages: - c.execute(""" - SELECT * FROM messages WHERE thread_id = ? - ORDER BY post_id""", (thread_id,)) + if messages or op_only: + query = "SELECT * FROM messages WHERE thread_id = ? %s" + c.execute(query % ( + "AND post_id = 0" if op_only else "ORDER BY post_id" + ), (thread_id,)) # create a list where each post_id matches its list[index] thread["messages"] = [schema.message(*values) for values in c.fetchall()] return thread -def thread_index(connection): +def thread_index(connection, include_op=False): """ Return a list with each thread, ordered by the date they were last modifed (which could be when it was submitted @@ -119,7 +120,7 @@ def thread_index(connection): ORDER BY last_mod DESC""") threads = [ - thread_get(connection, obj[0], messages=False) + thread_get(connection, obj[0], False, include_op) for obj in c.fetchall() ] return threads |