def get(self): rows = Row.all() logging.info('Found %d rows',rows.count()) template_vars = { 'rows': rows, 'rowcount': rows.count(), 'sep': cgi.escape(self.request.get("sep")) or ',' } path = os.path.join(os.path.dirname(__file__),"index.html") self.response.out.write(template.render(path,template_vars))
def get(self): rows = Row.all() logging.info('CSV requested. Found %d rows',rows.count()) if rows.count() > 0: self.response.headers['Content-Type'] = "application/csv" writer = encoding.UnicodeWriter(self.response.out,delimiter=cgi.escape(self.request.get("sep").__str__()),quotechar='"') for row in rows: writer.writerow(row.cols) else: print "Content-Type: text/html" print print "<h1>No data to display ...</h1>"
def post(self): text = self.request.get('lines') sep = self.request.get('sep') or ',' logging.info("line %s - sep %s",text,sep) rows = rows_from_string(text,sep) db.put(rows) all_rows = Row.all() template_vars = { 'rows': all_rows, 'rowcount': all_rows.count(), 'sep': cgi.escape(sep) } path = os.path.join(os.path.dirname(__file__),"index.html") self.response.out.write(template.render(path,template_vars))