import robaccia import dbconfig from wsgicollection import Collection from config import log class Notes(Collection): def _raw_etag(self, cursor): e = [] for row in iter(cursor): e.append("%d-%d" % (row['id'], row['rev'])) return "-".join(e) def list(self, environ, start_response): c = dbconfig.connection.cursor() rows = list(c.execute("select id, note, rev from notes;")) return robaccia.render(environ, start_response, 'list.xhtml', {'rows': rows}, raw_etag=self._raw_etag(rows)) def get_edit_form(self, environ, start_response): c = dbconfig.connection.cursor() id = environ['wsgiorg.routing_args'][1]['id'] rows = list(c.execute("select id, note, rev from notes where id = ? ;", id)) return robaccia.render(environ, start_response, 'edit_form.xhtml', {'rows': rows}, raw_etag=self._raw_etag(rows)) def update(self, environ, start_response): c = dbconfig.connection.cursor() id = environ['wsgiorg.routing_args'][1]['id'] f = environ['formpostdata'] note = f.get('note', ['no note found'])[0] rev = f.get('rev', ['no rev found'])[0] c.execute('update notes set note=:note where id=:id;', locals()) dbconfig.connection.commit() start_response("303 See Other", [('Location', "../")]) return []