import sqlite3
from bottle import route, run, debug
from bottle import redirect, request, template, validate
 
#----------------------------------------------------------------------
@route("/")
@route("/todo")
def todo_list():
    """
    Show the main page which is the current TODO list
    """
    conn = sqlite3.connect("todo.db")
    c = conn.cursor()
    c.execute("SELECT id, task FROM todo WHERE status LIKE '1'")
    result = c.fetchall()
    print result
    c.close()
 
    return'''
        <form action="/login" method="post">
	<p><h3>Your TODO Items:</h3></p>
	<table border="1">
	%for row in rows:
	  %id, title = row
	  <tr>
	  %for col in row:
	    <td>{{col}}</td>
	  %end
	  <td><a href="/edit/{{id}}"> Edit</a></td>
	  </tr>
	%end
	</table>
	<p>Create <a href="/new">New</a> item</p>
	<p>Show <a href="/done">Done Items</a></p>
        </form>
    '''
 
if __name__ == "__main__":
    debug(True)
    run(host='docbox.flint.com', port=8083)

