summaryrefslogtreecommitdiff
path: root/cgi-bin/page.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi-bin/page.py')
-rw-r--r--cgi-bin/page.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/cgi-bin/page.py b/cgi-bin/page.py
index 2200390..b776d8e 100644
--- a/cgi-bin/page.py
+++ b/cgi-bin/page.py
@@ -17,6 +17,7 @@ sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
_url = Config.get("route", "url")
_static = Config.get("route", "static")
+_whiperperpage = int(Config.get("config", "whisper_count"))
page_file = open(Path.template("page.html"), 'r', encoding="utf8")
page_templ = page_file.read()
@@ -25,10 +26,12 @@ page_file.close()
pagen = cgi.FieldStorage().getvalue('p')
if pagen == None:
pagen = 0
-pageprev = int(pagen) - 1
+else:
+ pagen = int(pagen)
+pageprev = pagen - 1
if pageprev < 0:
pageprev = 0
-pagenext = int(pagen) + 1
+pagenext = pagen + 1
# class PageBuilder(object):
# def build(pagen):
@@ -37,16 +40,26 @@ print("Content-type:text/html\n")
db = Connect.produce()
cursor = db.cursor()
-query_allwhisper = "select * from whisper"
+query_count = "select COUNT(*) from whisper"
+cursor.execute(query_count)
+whispercount = cursor.fetchone()
+whispercount = whispercount[0]
+
+query_allwhisper = "select * from whisper ORDER BY id DESC LIMIT {0}, {1}".format(pagen * _whiperperpage, _whiperperpage)
cursor.execute(query_allwhisper)
-_whispers=""
+_whispers = ""
whispersdata = cursor.fetchall()
odd = True
+count = 0
for whisper in whispersdata:
- _whispers += Whisper.build(whisper[0], whisper[1], odd)
+ count = count + 1
+ _whispers += Whisper.build(whisper[0], whisper[1], whisper[2], odd, _url)
odd = not odd
+if pagen * _whiperperpage + count >= whispercount:
+ pagenext = pagen
+
page = page_templ.format(\
url = _url,
static = _static,