def reply_action(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) post = form['post'].value #username = '******' cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value user = meeplib.get_user(username) new_message = meeplib.Message(post, user) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) t.add_post(new_message) meeplib.save() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return ["reply added"]
def reply(self, environ, start_response): print "enter reply" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) print "exit reply" return ["".join(s)]
def reply(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] flag = 0 for m in t.get_all_posts(): s.append('<hr>') if flag == 0: s.append('<h2>%s</h2>' % (t.title)) flag = 1 s.append('<p>%s</p>' % (m.post)) s.append('<p>Posted by: %s</p>' % (m.author.username)) s.append('<hr>') s.append(""" <form action='reply_action' method='POST'> <input name='thread_id' type='hidden' value='%d' /> Message: <input type='text' name='post'><br> <input type='submit'> </form> """ % (t.id)) headers = [('Content-type', 'text/html')] start_response("200 OK", headers) return ["".join(s)]
def reply_action(self, environ, start_response): print environ["wsgi.input"] form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ) post = form["post"].value # username = '******' cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value user = meeplib.get_user(username) new_message = meeplib.Message(post, user) thread_id = int(form["thread_id"].value) t = meeplib.get_thread(thread_id) t.add_post(new_message) meeplib.save() headers = [("Content-type", "text/html")] headers.append(("Location", "/m/list")) start_response("302 Found", headers) return ["reply added"]
def delete_message_action(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) post = t.get_post(post_id) t.delete_post(post) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return["post deleted"]
def reply(self, environ, start_response): print "enter reply" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location', '/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) print "exit reply" return ["".join(s)]
def delete_message_action(self, environ, start_response): print "enter delete message action" form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['msg_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) p = t.get_post(post_id) t.delete_post(p) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) print "exit delete message action" return["post deleted"]
def delete_message_action(self, environ, start_response): print "enter delete message action" form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['msg_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) p = t.get_post(post_id) t.delete_post(p) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) print "exit delete message action" return ["post deleted"]
def delete_message_action(self, environ, start_response): print environ["wsgi.input"] form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ) thread_id = int(form["thread_id"].value) post_id = int(form["post_id"].value) t = meeplib.get_thread(thread_id) post = t.get_post(post_id) t.delete_post(post) meeplib.save() headers = [("Content-type", "text/html")] headers.append(("Location", "/m/list")) start_response("302 Found", headers) return ["post deleted"]
def reply(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' # post is non-empty if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) # doesn't get executed unless we had invalid input s.append(render_page("reply.html", thread=t)) return ["".join(s)]
def reply_action(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) post = form['post'].value username = '******' user = meeplib.get_user(username) new_message = meeplib.Message(post, user) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) t.add_post(new_message) headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return ["reply added"]
def reply(self, environ, start_response): # get cookie try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value except: username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' #check to make sure post is not empty if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) return ["".join(s)]