From 4a0aa0eafa931cf69f5ceaf845054061b0e7f213 Mon Sep 17 00:00:00 2001 From: Chris Bay Date: Sat, 6 Aug 2016 08:55:11 -0500 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 ae83a81695a09d8305eec7e637d24b60f4404323 Mon Sep 17 00:00:00 2001 From: jesseilev Date: Thu, 29 Dec 2016 12:40:30 -0600 Subject: [PATCH 7/7] change variable name from response to content --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 33965e5..3bb4c71 100644 --- a/main.py +++ b/main.py @@ -48,8 +48,8 @@ def get(self): # text box () - response = page_header + edit_header + add_form + page_footer - self.response.write(response) + content = page_header + edit_header + add_form + page_footer + self.response.write(content) class AddMovie(webapp2.RequestHandler): @@ -65,8 +65,8 @@ def post(self): 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) # TODO 2