out = StringIO() print >>out, '<div id="user">Welcome, %s!' % user.username print >>out, '<ul class="actions"><li><a href="session.py/logout">log out</a></li></ul>' return out.getvalue() if __name__ == '__main__': argv = session.argv() if len(argv) < 3: print """Status: 400 Bad Request Content-type: text/html The request was nonsensical.""" sys.exit() try: form = session.form() if argv[1] == 't': thread = Conversation.get(Conversation.user == user and Conversation.id == int(argv[2])) buf = renderThread(thread) elif argv[1] == 'e': event = Event.get(Event.inbox.user == user and Event.id == int(argv[2])) buf = renderEvent(event) else: raise UnknownRequest print "Content-type: text/html;charset=utf-8\n\n" print buf except (Conversation.DoesNotExist, Event.DoesNotExist): print """Status: 404 Not Found Content-type: text/html
def updatedThreads(since): ref = timeutil.fromStamp(since) updThreads = user.threads.where(Conversation.last_update > ref) return [{'tid' : t.id, 'events' : [ {'eid' : e.id, 'html' : render.renderEvent(e) } for e in t.events.where(Event.last_update > ref)]} for t in updThreads] return updates if __name__ == '__main__': response = None form = session.form() if len(argv) == 1: response = { 'lastitem': lastitem() } if form.getfirst('since'): response['threads'] = updatedThreads(form.getfirst('since')) or None elif argv[1] == 'mark': if len(argv) != 3: print "Status: 400 Bad Request\nContent-type: text/html\n\nMissing thread id" sys.exit() count=0 for thread in user.threads.where(Conversation.id == int(argv[2])): if thread.unread: count += 1 thread.unread = False thread.save()