def my_content(environ): # gets current logged in user current_user = users.user_from_cookie(db, environ) image_list = interface.list_images_for_user(db, current_user) result = [] for index in range(len(image_list)): comments = interface.list_comments(db, image_list[index][0]) new_row = image_list[index] + (comments,) result.append(new_row) image_list = result # html form for image upload item = ( """<div class="well uploadform"> <form id="uploadform" method="post" action="/upload" enctype="multipart/form-data"> <fieldset class="form-group"> <legend>Upload New Image</legend> <input class="form-control" type="file" name="file"> <input type="hidden" name="user" value=""" + current_user + """> <br><div class="text-center"><input class="btn btn-primary" type="submit" value="Upload File"></div> </fieldset> </form> </div> """ ) # constructs html for each image div for index in range(len(image_list)): comments = "<ul>" item += '<div class="flowtow">' item += '<span class="date"> ' + image_list[index][1] + "</span>" item += '<span class="name"> ' + image_list[index][2] + "</span>" item += '<img src="/static/images/' + image_list[index][0] + '">' for comment in range(len(image_list[index][3])): comments = comments + "<li>" + image_list[index][3][comment] + "</li>" item += '<div class="comments">' + comments + "</ul></div>" # creates a form for commenting item += ( """<form method="post" action="/add_comment"> <input type="hidden" name="image" value=""" + image_list[index][0] + """> <input type="text" class="form-control" name="comment" id="comment" placeholder="Enter your comment here"><br> <input type="submit" class="btn btn-primary" value="Submit"> </form></div>""" ) return item
def test_list_images_user(self): """Test that list_images_for_user returns the right list of images for a user""" for user in self.users: email = user[0] # get the four most recent image entries image_list = interface.list_images_for_user(self.db, email) # and all entries are three elements long self.assertTrue(all([len(i) == 3 for i in image_list])) refimages = [i for i in self.images if i[2] == email] # check that the images are in the right order self.assertListEqual([img[0] for img in refimages], [img[0] for img in image_list]) # and the dates are right self.assertListEqual([img[1] for img in refimages], [img[1] for img in image_list]) # and the owners self.assertListEqual([img[2] for img in refimages], [img[2] for img in image_list])
def page_my_images(environ, start_response): logged_user = user_from_cookie(db, environ) if logged_user: template_mapping = dict(image_list_for_user=render_image_list(list_images_for_user(db, logged_user))) return render_page(environ, 'my_images.html', 'Flowtow - My Images', template_mapping) return page_404(start_response)