1. Luke Plant
  2. lukeplant_python

Commits

Luke Plant  committed 13fda23

write_page() can handle non-existent pages

  • Participants
  • Parent commits ee4c398
  • Branches default

Comments (0)

Files changed (1)

File bibleverses/writewiki.py

View file
  • Ignore whitespace
 #!/usr/bin/env python
 
-from config import DATABASE
+from config import DATABASE, AUTHOR
+import time
 import sqlite3
 
 
 def write_page(name, data, add_new_version=False):
     c = sqlite3.connect(DATABASE)
     latest_version = c.execute("SELECT MAX(version) FROM wiki WHERE name = ?;", [name]).fetchone()[0]
-    if not add_new_version:
-        c.execute("UPDATE wiki SET text = ? WHERE version = ? AND name = ?", [data, latest_version, name])
+    if latest_version is None:
+        c.execute("INSERT INTO wiki (name, version, time, author, ipnr, text, comment, readonly) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+                  [name, 1, int(time.time()), AUTHOR, '127.0.0.1', data, '', 0])
     else:
-        raise NotImplementedError("Haven't implemented 'add_new_version=True' yet.")
+        if not add_new_version:
+            c.execute("UPDATE wiki SET text = ? WHERE version = ? AND name = ?", [data, latest_version, name])
+        else:
+            raise NotImplementedError("Haven't implemented 'add_new_version=True' yet.")
     c.commit()
     c.close()