def initialize(): print "enter initialize" meeplib.load_state() u = meeplib.User('test', 'foo') t = meeplib.Thread('Greetings Earthlings') m = meeplib.Message('The meep message board is open.', u) t.add_post(m)
def initialize(): # create a default user u = meeplib.User('aLlama', 'box') # create a thread (i.e. title for message) t = meeplib.Thread('This Is A Test Thread') # create a single message m = meeplib.Message('This is a lame test message.', u) # save the message in the thread t.add_post(m)
def initialize(): # create a default user u = meeplib.User('test', 'foo') # create a thread t = meeplib.Thread('Test Thread') # create a single message m = meeplib.Message('This is my message!', u) # save the message in the thread t.add_post(m)
def add_thread(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) try: title = form['title'].value except KeyError: title = '' try: message = form ['message'].value except KeyError: message = '' s = [] # title and message are non-empty if title == '' and message == '': pass elif title == '' and message != '': s.append("Title was empty.<p>") elif title != '' and message == '': s.append("Message was empty. <p>") elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) # doesn't get executed if we had valid input and created a thread s.append(render_page("add_thread.html", title=title, message=message)) return ["".join(s)]
def add_message(self, environ, start_response): #get cookie try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value print "Username is %s" % username 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 ["Dude, login first if you want to use this feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: title = form['title'].value except KeyError: title = '' try: message = form ['message'].value except KeyError: message = '' s = [] #check to see if title and message are not empty if title == '' and message == '': pass elif title == '' and message != '': s.append("The title is empty.<p>") elif title != '' and message == '': s.append("The message is empty. <p>") elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("add_message.html", title=title, message=message)) return ["".join(s)]
def add_message_action(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) title = form['title'].value message = form['message'].value username = meeplib.get_curr_user() user = meeplib.get_user(username) new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return ["message added"]
def add_thread(self, environ, start_response): print "enter add thread" 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 in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: title = form['title'].value except KeyError: title = '' try: message = form['message'].value except KeyError: message = '' s = [] if title == '' and message == '': pass elif title == '' and message != '': s.append('''''title' cannot be empty<p>''') elif title != '' and message == '': s.append('''''message' cannot be empty<p>''') elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save_state() headers.append(('Location', '/m/list')) start_response("302 Found", headers) s.append(render_page("add_message.html", title=title, message=message)) print "exit add thread" return ["".join(s)]
def setUp(self): meeplib._reset() u = meeplib.User('foo', 'bar') t = meeplib.Thread('the title') m = meeplib.Message('the content', u) t.add_post(m)
def setUp(self): u = meeplib.User('a Llama', 'box') m = meeplib.Message('not', u) l = meeplib.Thread('What a great title!') l.add_post(m)