Project 4: Movie Watchlist: Setting the last watched date (+12, -2)

routes.py (+10, -0)

From: curriculum/section14/lectures/12_setting_movie_watched_date/start/movie_library/routes.py

To: curriculum/section14/lectures/12_setting_movie_watched_date/end/movie_library/routes.py

            
            index 00b8478..110e26f 100644
--- a/curriculum/section14/lectures/12_setting_movie_watched_date/start/movie_library/routes.py
+++ b/curriculum/section14/lectures/12_setting_movie_watched_date/end/movie_library/routes.py
@@ -1,4 +1,5 @@
 import uuid
+import datetime
 from dataclasses import asdict
 
 from flask import (
@@ -58,6 +59,15 @@ def movie(_id: str):
     return render_template("movie_details.html", movie=movie)
 
 
+@pages.get("/movie/<string:_id>/watch")
+def watch_today(_id):
+    current_app.db.movie.update_one(
+        {"_id": _id}, {"$set": {"last_watched": datetime.datetime.today()}}
+    )
+
+    return redirect(url_for(".movie", _id=_id))
+
+
 @pages.get("/movie/<string:_id>/rate")
 def rate_movie(_id):
     rating = int(request.args.get("rating"))
        

movie_details.html (+2, -2)

From: curriculum/section14/lectures/12_setting_movie_watched_date/start/movie_library/templates/movie_details.html

To: curriculum/section14/lectures/12_setting_movie_watched_date/end/movie_library/templates/movie_details.html

            
            index 3138a1f..6edb906 100644
--- a/curriculum/section14/lectures/12_setting_movie_watched_date/start/movie_library/templates/movie_details.html
+++ b/curriculum/section14/lectures/12_setting_movie_watched_date/end/movie_library/templates/movie_details.html
@@ -23,12 +23,12 @@
             <div class="movie__watched">
                 {% if movie.last_watched %}
                     <p>
-                        Last watched: <a href="#" class="watched__link">
+                        Last watched: <a href="{{ url_for('pages.watch_today', _id=movie._id) }}" class="watched__link">
                             <time datetime="{{ movie.last_watched }}">{{movie.last_watched.strftime("%d %b %Y")}}</time>
                         </a>
                     </p>
                 {% else %}
-                    <p><a href="#" class="watched__link">Not watched yet</a></p>
+                    <p><a href="{{ url_for('pages.watch_today', _id=movie._id) }}" class="watched__link">Not watched yet</a></p>
                 {% endif %}
                 <a class="movie__edit" href="#">Edit {{ pencil("pencil") }}</a>
             </div>