From 4a0aa0eafa931cf69f5ceaf845054061b0e7f213 Mon Sep 17 00:00:00 2001 From: Chris Bay Date: Sat, 6 Aug 2016 08:55:11 -0500 Subject: [PATCH 01/19] Finished studio3 / start of walkthrough4 --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index a5f0298..b8667c0 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,17 @@ import webapp2 +import random class Index(webapp2.RequestHandler): def getRandomMovie(self): - # TODO: make a list with at least 5 movie titles + # list of movies to select from + movies = ["The Big Lebowski", "Blue Velvet", "Toy Story", "Star Wars", "Amelie"] - # TODO: randomly choose one of the movies, and return it + # randomly choose one of the movies + randomIdx = random.randrange(len(movies)) - return "The Big Lebowski" + return movies[randomIdx] def get(self): movie = self.getRandomMovie() From 3dfa95d4a5c0c922073cb1ef63a7d7b62b281cc2 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Tue, 9 Aug 2016 17:50:07 -0500 Subject: [PATCH 02/19] add implementation for Tomorrow's Movie --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index ac086fb..c8d2f1a 100644 --- a/main.py +++ b/main.py @@ -16,12 +16,14 @@ def getRandomMovie(self): def get(self): movie = self.getRandomMovie() - # build the response string + # add Movie of the Day to the response string response = "

Movie of the Day

" response += "

" + movie + "

" - # TODO: pick a different random movie, and display it under - # the heading "

Tommorrow's Movie

" + # add Tomorrow's Movie to the response string + tomorrow_movie = self.getRandomMovie() + response += "

Tomorrow's Movie

" + response += "

" + tomorrow_movie + "

" self.response.write(response) From 77dbb6202dd56d6a0e609301afc11a559ac05d09 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Tue, 9 Aug 2016 17:51:01 -0500 Subject: [PATCH 03/19] shuffle comment around --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index c8d2f1a..804b783 100644 --- a/main.py +++ b/main.py @@ -14,9 +14,8 @@ def getRandomMovie(self): return movies[randomIdx] def get(self): - movie = self.getRandomMovie() - # add Movie of the Day to the response string + movie = self.getRandomMovie() response = "

Movie of the Day

" response += "

" + movie + "

" From d0d902c017c055404bddf7ccdfedaec4b7a2cb00 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Fri, 12 Aug 2016 14:00:29 -0500 Subject: [PATCH 04/19] add TODOs for studio --- main.py | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 804b783..996ad93 100644 --- a/main.py +++ b/main.py @@ -3,29 +3,54 @@ class Index(webapp2.RequestHandler): - def getRandomMovie(self): + def get(self): + response = "

FlickList

" + response += "

Add a new movie to your Watchlist:

" - # list of movies to select from - movies = ["The Big Lebowski", "Blue Velvet", "Toy Story", "Star Wars", "Amelie"] + # create a form for user to add a new movie + response += """ +
+ + +
+ """ - # randomly choose one of the movies - randomIdx = random.randrange(len(movies)) + # TODO 1 + # Add another form so the user can delete a movie from their list. - return movies[randomIdx] - def get(self): - # add Movie of the Day to the response string - movie = self.getRandomMovie() - response = "

Movie of the Day

" - response += "

" + movie + "

" + # TODO 4 + # Once you have the basic version working, modify the form so that it uses + # a dropdown . + + + self.response.write(response) + - # add Tomorrow's Movie to the response string - tomorrow_movie = self.getRandomMovie() - response += "

Tomorrow's Movie

" - response += "

" + tomorrow_movie + "

" +class AddMovie(webapp2.RequestHandler): + + def post(self): + # look inside the request to figure out what the user typed + new_movie = self.request.get("new_movie") + + # build response content + new_movie_element = "" + new_movie + "" + sentence = new_movie_element + " has been added to your Watchlist!" + header = "

Thanks!

" + response = header + "

" + sentence + "

" self.response.write(response) + +# TODO 2 +# Add a new handler class called DeleteMovie, to receive and handle the delete request. +# The user should see a message like "Thanks! ___ has been deleted from you watchlist". + + + +# TODO 3 +# Add your delete route to the app, by adding another tuple to the list below. app = webapp2.WSGIApplication([ - ('/', Index) + ('/', Index), + ('/addmovie', AddMovie) ], debug=True) From 50e0f97f07deacf9ba8a31b8c75d72dcf1a27adf Mon Sep 17 00:00:00 2001 From: jesseilev Date: Fri, 12 Aug 2016 14:18:48 -0500 Subject: [PATCH 05/19] fix bug of new-movie query param typo --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 996ad93..7b1a1fc 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,7 @@ class AddMovie(webapp2.RequestHandler): def post(self): # look inside the request to figure out what the user typed - new_movie = self.request.get("new_movie") + new_movie = self.request.get("new-movie") # build response content new_movie_element = "" + new_movie + "" From 23fb252339582c25a0b1e3aa2c16da0f5d4b8d30 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Fri, 12 Aug 2016 16:04:37 -0500 Subject: [PATCH 06/19] doc strings on handlers --- main.py | 66 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 7b1a1fc..33965e5 100644 --- a/main.py +++ b/main.py @@ -1,33 +1,61 @@ import webapp2 -import random + + +# html boilerplate for the top of every page +page_header = """ + + + + FlickList + + +

FlickList

+""" + +# html boilerplate for the bottom of every page +page_footer = """ + + +""" class Index(webapp2.RequestHandler): + """ Handles requests coming in to '/' (the root of our site) + e.g. www.flicklist.com/ + """ def get(self): - response = "

FlickList

" - response += "

Add a new movie to your Watchlist:

" - - # create a form for user to add a new movie - response += """ -
- - + + edit_header = "

Edit My Watchlist

" + + # a form for adding new movies + add_form = """ + + +
""" # TODO 1 - # Add another form so the user can delete a movie from their list. + # Include another form so the user can "cross off" a movie from their list. - # TODO 4 - # Once you have the basic version working, modify the form so that it uses - # a dropdown . + # TODO 4 (Extra Credit) + # modify your form to use a dropdown () + response = page_header + edit_header + add_form + page_footer self.response.write(response) class AddMovie(webapp2.RequestHandler): + """ Handles requests coming in to '/add' + e.g. www.flicklist.com/add + """ def post(self): # look inside the request to figure out what the user typed @@ -36,21 +64,21 @@ def post(self): # build response content new_movie_element = "" + new_movie + "" sentence = new_movie_element + " has been added to your Watchlist!" - header = "

Thanks!

" - response = header + "

" + sentence + "

" + response = page_header + "

" + sentence + "

" + page_footer self.response.write(response) # TODO 2 -# Add a new handler class called DeleteMovie, to receive and handle the delete request. -# The user should see a message like "Thanks! ___ has been deleted from you watchlist". +# Create a new RequestHandler class called CrossOffMovie, to receive and +# handle the request from your 'cross-off' form. The user should see a message like: +# "Star Wars has been crossed off your watchlist". # TODO 3 -# Add your delete route to the app, by adding another tuple to the list below. +# Include a route for your cross-off handler, by adding another tuple to the list below. app = webapp2.WSGIApplication([ ('/', Index), - ('/addmovie', AddMovie) + ('/add', AddMovie) ], debug=True) From 38f4ee46050f61a4f5e41817edb081d7f1186374 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Mon, 15 Aug 2016 17:45:07 -0500 Subject: [PATCH 07/19] almost full solution to studio4, but something is wrong with dropdown not sending data over --- main.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 33965e5..8dad332 100644 --- a/main.py +++ b/main.py @@ -39,16 +39,24 @@ def get(self): """ - # TODO 1 - # Include another form so the user can "cross off" a movie from their list. - - - # TODO 4 (Extra Credit) - # modify your form to use a dropdown () - + # a form for crossing off movies + crossoff_form = """ +
+ + +
+ """ - response = page_header + edit_header + add_form + page_footer + response = page_header + edit_header + add_form + crossoff_form + page_footer self.response.write(response) @@ -73,12 +81,20 @@ def post(self): # Create a new RequestHandler class called CrossOffMovie, to receive and # handle the request from your 'cross-off' form. The user should see a message like: # "Star Wars has been crossed off your watchlist". +class CrossOffMovie(webapp2.RequestHandler): + def post(self): + crossed_off_movie = self.request.get("crossed-off-movie") + crossed_off_movie_element = "" + crossed_off_movie + "" + confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." + response = page_header + "

" + confirmation + "

" + page_footer + self.response.write(response) # TODO 3 # Include a route for your cross-off handler, by adding another tuple to the list below. app = webapp2.WSGIApplication([ ('/', Index), - ('/add', AddMovie) + ('/add', AddMovie), + ('/cross-off', CrossOffMovie) ], debug=True) From 81fcb2da7437c08e91400ec7addf0a536520b07d Mon Sep 17 00:00:00 2001 From: jesseilev Date: Mon, 15 Aug 2016 17:48:30 -0500 Subject: [PATCH 08/19] studio4 is solved; add docstring to CrossOffMovie class --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index 8dad332..6cdbdb2 100644 --- a/main.py +++ b/main.py @@ -82,6 +82,9 @@ def post(self): # handle the request from your 'cross-off' form. The user should see a message like: # "Star Wars has been crossed off your watchlist". class CrossOffMovie(webapp2.RequestHandler): + """ Handles requests coming in to '/cross-off' + e.g. www.flicklist.com/cross-off + """ def post(self): crossed_off_movie = self.request.get("crossed-off-movie") From f315b796052435a742796ac80e7f5b7f955c5109 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Mon, 15 Aug 2016 17:54:52 -0500 Subject: [PATCH 09/19] remove TODOs, add a few comments --- main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 6cdbdb2..57ed49f 100644 --- a/main.py +++ b/main.py @@ -77,25 +77,24 @@ def post(self): self.response.write(response) -# TODO 2 -# Create a new RequestHandler class called CrossOffMovie, to receive and -# handle the request from your 'cross-off' form. The user should see a message like: -# "Star Wars has been crossed off your watchlist". + class CrossOffMovie(webapp2.RequestHandler): """ Handles requests coming in to '/cross-off' e.g. www.flicklist.com/cross-off """ def post(self): + # look inside the request to figure out what the user typed crossed_off_movie = self.request.get("crossed-off-movie") + + # build response content crossed_off_movie_element = "" + crossed_off_movie + "" confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." + response = page_header + "

" + confirmation + "

" + page_footer self.response.write(response) -# TODO 3 -# Include a route for your cross-off handler, by adding another tuple to the list below. app = webapp2.WSGIApplication([ ('/', Index), ('/add', AddMovie), From add5b642a6701b610f218333f75f217911be79c0 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Tue, 16 Aug 2016 15:48:02 -0500 Subject: [PATCH 10/19] validate crossoff; display error messages on homepage; don't hardcode movies directly into html; other small stuff --- main.py | 61 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 57ed49f..baaf96e 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import webapp2 - +import cgi # html boilerplate for the top of every page page_header = """ @@ -7,9 +7,16 @@ FlickList + -

FlickList

+

+ FlickList +

""" # html boilerplate for the bottom of every page @@ -18,6 +25,14 @@ """ + +def getCurrentWatchlist(): + """ Returns the user's current watchlist + """ + + return [ "Star Wars 2", "Minions", "Freaky Friday", "My Favorite Martian" ] + + class Index(webapp2.RequestHandler): """ Handles requests coming in to '/' (the root of our site) e.g. www.flicklist.com/ @@ -39,24 +54,32 @@ def get(self): """ - # a form for crossing off movies + # a form from crossing off movies + crossoff_options = "" + for movie in getCurrentWatchlist(): + crossoff_options += ''.format(movie) + crossoff_form = """
- """ + """.format(crossoff_options) + + error = self.request.get("error") + if error: + error_element = "

" + error + "

" + else: + error_element = "" - response = page_header + edit_header + add_form + crossoff_form + page_footer + content = edit_header + add_form + crossoff_form + error_element + response = page_header + content + page_footer self.response.write(response) @@ -72,12 +95,10 @@ def post(self): # build response content new_movie_element = "" + new_movie + "" sentence = new_movie_element + " has been added to your Watchlist!" - response = page_header + "

" + sentence + "

" + page_footer self.response.write(response) - class CrossOffMovie(webapp2.RequestHandler): """ Handles requests coming in to '/cross-off' e.g. www.flicklist.com/cross-off @@ -87,12 +108,18 @@ def post(self): # look inside the request to figure out what the user typed crossed_off_movie = self.request.get("crossed-off-movie") - # build response content - crossed_off_movie_element = "" + crossed_off_movie + "" - confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." - - response = page_header + "

" + confirmation + "

" + page_footer - self.response.write(response) + if crossed_off_movie in getCurrentWatchlist(): + # build response content + crossed_off_movie_element = "" + crossed_off_movie + "" + confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." + response = page_header + "

" + confirmation + "

" + page_footer + self.response.write(response) + else: + # if user tried to cross off a movie that wasn't in their list, + # then we redirect back to the front page and yell at thme + error_message = crossed_off_movie + " is not in your Watchlist, so you can't cross it off!" + escaped_messsage = cgi.escape(error_message, quote=True) + self.redirect("/?error=" + escaped_messsage) app = webapp2.WSGIApplication([ From 3f49ccced6c2472b19f9dd3a42f381a1ac3be3ae Mon Sep 17 00:00:00 2001 From: jesseilev Date: Tue, 16 Aug 2016 16:50:33 -0500 Subject: [PATCH 11/19] better comments; ternary for error message --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index baaf96e..df20593 100644 --- a/main.py +++ b/main.py @@ -27,9 +27,9 @@ def getCurrentWatchlist(): - """ Returns the user's current watchlist - """ + """ Returns the user's current watchlist """ + # for now, we are just pretending return [ "Star Wars 2", "Minions", "Freaky Friday", "My Favorite Martian" ] @@ -54,7 +54,8 @@ def get(self): """ - # a form from crossing off movies + # a form for crossing off movies + # (first we build a dropdown from the current watchlist items) crossoff_options = "" for movie in getCurrentWatchlist(): crossoff_options += ''.format(movie) @@ -72,11 +73,9 @@ def get(self): """.format(crossoff_options) + # if we have an error, make a

to display it error = self.request.get("error") - if error: - error_element = "

" + error + "

" - else: - error_element = "" + error_element = "

" + error + "

" if error else "" content = edit_header + add_form + crossoff_form + error_element response = page_header + content + page_footer From 67868f057c10578954eebcc70d72f7568edb1169 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Tue, 16 Aug 2016 17:12:21 -0500 Subject: [PATCH 12/19] add TODOs; fix crossoff validation bug -- needed parens --- main.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index df20593..98aa0f8 100644 --- a/main.py +++ b/main.py @@ -77,8 +77,9 @@ def get(self): error = self.request.get("error") error_element = "

" + error + "

" if error else "" - content = edit_header + add_form + crossoff_form + error_element - response = page_header + content + page_footer + # combine all the pieces to build the content of our response + main_content = edit_header + add_form + crossoff_form + error_element + response = page_header + main_content + page_footer self.response.write(response) @@ -91,6 +92,19 @@ def post(self): # look inside the request to figure out what the user typed new_movie = self.request.get("new-movie") + + # TODO 1 + # 'escape' the user's input so that if they type HMTL, it doesn't mess up our site + + + # TODO 2 + # if the user typed nothing at all, redirect and yell at them + + + # TODO 3 + # if the user wants to add a terrible movie, redirect and yell at them + + # build response content new_movie_element = "" + new_movie + "" sentence = new_movie_element + " has been added to your Watchlist!" @@ -107,19 +121,21 @@ def post(self): # look inside the request to figure out what the user typed crossed_off_movie = self.request.get("crossed-off-movie") - if crossed_off_movie in getCurrentWatchlist(): - # build response content - crossed_off_movie_element = "" + crossed_off_movie + "" - confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." - response = page_header + "

" + confirmation + "

" + page_footer - self.response.write(response) - else: - # if user tried to cross off a movie that wasn't in their list, - # then we redirect back to the front page and yell at thme + if (crossed_off_movie in getCurrentWatchlist()) == False: + # the user tried to cross off a movie that isn't in their list, + # so we redirect back to the front page and yell at them error_message = crossed_off_movie + " is not in your Watchlist, so you can't cross it off!" escaped_messsage = cgi.escape(error_message, quote=True) + + # redirect to homepage, and include error as a query parameter in the URL self.redirect("/?error=" + escaped_messsage) + # if we didn't redirect by now, then all is well + crossed_off_movie_element = "" + crossed_off_movie + "" + confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." + response = page_header + "

" + confirmation + "

" + page_footer + self.response.write(response) + app = webapp2.WSGIApplication([ ('/', Index), From 00b272b278bf65ac1ff8fefa2ab636212b450806 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Wed, 17 Aug 2016 12:32:16 -0500 Subject: [PATCH 13/19] include terrible_movies list, fix comment typo --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 98aa0f8..dc5aa14 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,15 @@ """ +# a list of movies that nobody should be allowed to watch +terrible_movies = [ + "Gigli", + "Star Wars Episode 1: Attack of the Clones", + "Paul Blart: Mall Cop 2", + "Nine Lives" +] + + def getCurrentWatchlist(): """ Returns the user's current watchlist """ @@ -94,7 +103,7 @@ def post(self): # TODO 1 - # 'escape' the user's input so that if they type HMTL, it doesn't mess up our site + # 'escape' the user's input so that if they typed HTML, it doesn't mess up our site # TODO 2 From 80bb13b999d6b571522f7f62852968bddab10057 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Wed, 17 Aug 2016 12:34:43 -0500 Subject: [PATCH 14/19] fix Star Wars 2 typo --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index dc5aa14..0c293d3 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,7 @@ def getCurrentWatchlist(): """ Returns the user's current watchlist """ # for now, we are just pretending - return [ "Star Wars 2", "Minions", "Freaky Friday", "My Favorite Martian" ] + return [ "Star Wars", "Minions", "Freaky Friday", "My Favorite Martian" ] class Index(webapp2.RequestHandler): From 74bcc3a1217f8d0f65136b675eeb9dfc1702cb6c Mon Sep 17 00:00:00 2001 From: jesseilev Date: Wed, 17 Aug 2016 13:26:46 -0500 Subject: [PATCH 15/19] quotation marks around movie title in error message --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0c293d3..6f62110 100644 --- a/main.py +++ b/main.py @@ -133,7 +133,9 @@ def post(self): if (crossed_off_movie in getCurrentWatchlist()) == False: # the user tried to cross off a movie that isn't in their list, # so we redirect back to the front page and yell at them - error_message = crossed_off_movie + " is not in your Watchlist, so you can't cross it off!" + + # make a helpful error message + error_message = "'{0}' is not in your Watchlist, so you can't cross it off!".format(crossed_off_movie) escaped_messsage = cgi.escape(error_message, quote=True) # redirect to homepage, and include error as a query parameter in the URL From 015dee7e0e5a54beb24e9e4f8788b4ee240ef53e Mon Sep 17 00:00:00 2001 From: jesseilev Date: Wed, 17 Aug 2016 16:04:52 -0500 Subject: [PATCH 16/19] in control flow, don't escape user input until after the other validation --- main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 6f62110..c09b597 100644 --- a/main.py +++ b/main.py @@ -101,11 +101,6 @@ def post(self): # look inside the request to figure out what the user typed new_movie = self.request.get("new-movie") - - # TODO 1 - # 'escape' the user's input so that if they typed HTML, it doesn't mess up our site - - # TODO 2 # if the user typed nothing at all, redirect and yell at them @@ -114,6 +109,9 @@ def post(self): # if the user wants to add a terrible movie, redirect and yell at them + # TODO 1 + # 'escape' the user's input so that if they typed HTML, it doesn't mess up our site + # build response content new_movie_element = "" + new_movie + "" sentence = new_movie_element + " has been added to your Watchlist!" @@ -135,11 +133,11 @@ def post(self): # so we redirect back to the front page and yell at them # make a helpful error message - error_message = "'{0}' is not in your Watchlist, so you can't cross it off!".format(crossed_off_movie) - escaped_messsage = cgi.escape(error_message, quote=True) + error = "'{0}' is not in your Watchlist, so you can't cross it off!".format(crossed_off_movie) + error_escaped = cgi.escape(error, quote=True) # redirect to homepage, and include error as a query parameter in the URL - self.redirect("/?error=" + escaped_messsage) + self.redirect("/?error=" + error_escaped) # if we didn't redirect by now, then all is well crossed_off_movie_element = "" + crossed_off_movie + "" From b63043b9eeedf5374e1d149628fb34497006bcb1 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Thu, 29 Dec 2016 14:23:09 -0600 Subject: [PATCH 17/19] change variable name from response to content --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index c09b597..7fc594e 100644 --- a/main.py +++ b/main.py @@ -88,8 +88,8 @@ def get(self): # combine all the pieces to build the content of our response main_content = edit_header + add_form + crossoff_form + error_element - response = page_header + main_content + page_footer - self.response.write(response) + content = page_header + main_content + page_footer + self.response.write(content) class AddMovie(webapp2.RequestHandler): @@ -115,8 +115,8 @@ def post(self): # build response content new_movie_element = "" + new_movie + "" sentence = new_movie_element + " has been added to your Watchlist!" - response = page_header + "

" + sentence + "

" + page_footer - self.response.write(response) + content = page_header + "

" + sentence + "

" + page_footer + self.response.write(content) class CrossOffMovie(webapp2.RequestHandler): @@ -142,8 +142,8 @@ def post(self): # if we didn't redirect by now, then all is well crossed_off_movie_element = "" + crossed_off_movie + "" confirmation = crossed_off_movie_element + " has been crossed off your Watchlist." - response = page_header + "

" + confirmation + "

" + page_footer - self.response.write(response) + content = page_header + "

" + confirmation + "

" + page_footer + self.response.write(content) app = webapp2.WSGIApplication([ From a250dbe2a2a56cdd3f2b880ca46187b89c861a05 Mon Sep 17 00:00:00 2001 From: Jesse Levine Date: Fri, 27 Jan 2017 11:26:59 -0600 Subject: [PATCH 18/19] same changes as pull request #4 --- main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 7fc594e..4a70f46 100644 --- a/main.py +++ b/main.py @@ -84,7 +84,12 @@ def get(self): # if we have an error, make a

to display it error = self.request.get("error") - error_element = "

" + error + "

" if error else "" + if error: + error_esc = cgi.escape(error, quote=True) + error_element = ( + '

' + error_sec + '

' + else: + error_element = '' # combine all the pieces to build the content of our response main_content = edit_header + add_form + crossoff_form + error_element @@ -134,10 +139,9 @@ def post(self): # make a helpful error message error = "'{0}' is not in your Watchlist, so you can't cross it off!".format(crossed_off_movie) - error_escaped = cgi.escape(error, quote=True) # redirect to homepage, and include error as a query parameter in the URL - self.redirect("/?error=" + error_escaped) + self.redirect("/?error=" + error) # if we didn't redirect by now, then all is well crossed_off_movie_element = "" + crossed_off_movie + "" From 649eb82681a6cb715fcf8adf79dd18e682d174ff Mon Sep 17 00:00:00 2001 From: Jesse Levine Date: Fri, 27 Jan 2017 11:31:54 -0600 Subject: [PATCH 19/19] fix typos from previous commit --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index 4a70f46..ebfe90c 100644 --- a/main.py +++ b/main.py @@ -86,8 +86,7 @@ def get(self): error = self.request.get("error") if error: error_esc = cgi.escape(error, quote=True) - error_element = ( - '

' + error_sec + '

' + error_element = '

' + error_esc + '

' else: error_element = ''