Project 4: Movie Watchlist: Setting movie ratings (+41, -2)

routes.py (+8, -0)

From: curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/routes.py

To: curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/routes.py

            
            index 97db264..00b8478 100644
--- a/curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/routes.py
+++ b/curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/routes.py
@@ -58,6 +58,14 @@ def movie(_id: str):
     return render_template("movie_details.html", movie=movie)
 
 
+@pages.get("/movie/<string:_id>/rate")
+def rate_movie(_id):
+    rating = int(request.args.get("rating"))
+    current_app.db.movie.update_one({"_id": _id}, {"$set": {"rating": rating}})
+
+    return redirect(url_for(".movie", _id=_id))
+
+
 @pages.get("/toggle-theme")
 def toggle_theme():
     current_theme = session.get("theme")
        

movie_details.css (+27, -0)

From: curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/static/css/movie_details.css

To: curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/static/css/movie_details.css

            
            index 6d3469d..1345412 100644
--- a/curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/static/css/movie_details.css
+++ b/curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/static/css/movie_details.css
@@ -21,9 +21,36 @@
 }
 
 .movie__rating {
+  display: flex;
   margin-left: 1rem;
 }
 
+.rating__link {
+  display: flex;
+  align-items: center;
+  text-decoration: none;
+  color: unset;
+}
+
+.star {
+  width: 1.5em;
+  height: 1.5em;
+  fill: none;
+}
+
+.star:hover {
+  fill: #ffd02a;
+  stroke: #cca311;
+}
+
+.star--filled {
+  fill: #ffd02a;
+}
+
+.rating__link:not(:first-of-type) {
+  margin-left: 2px;
+}
+
 .movie__watched {
   display: flex;
 }
        

movie_details.html (+6, -2)

From: curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/templates/movie_details.html

To: curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/templates/movie_details.html

            
            index c1741f5..3138a1f 100644
--- a/curriculum/section14/lectures/11_setting_movie_rating/start/movie_library/templates/movie_details.html
+++ b/curriculum/section14/lectures/11_setting_movie_rating/end/movie_library/templates/movie_details.html
@@ -1,4 +1,4 @@
-{% from "macros/svgs.html" import pencil %}
+{% from "macros/svgs.html" import star, pencil %}
 
 {% extends "layout.html" %}
 
@@ -13,7 +13,11 @@
             <div class="movie__name">
                 <h1>{{ movie.title }}</h1>
                 <div class="movie__rating">
-                    {{ movie.rating }}
+                    {% for i in range(5) %}
+                        <a class="rating__link" href="{{ url_for('pages.rate_movie', _id=movie._id, rating=i+1) }}">
+                            {{ star("star " + ("star--filled" if movie.rating > i else "")) }}
+                        </a>
+                    {% endfor %}
                 </div>
             </div>
             <div class="movie__watched">