Project 4: Movie Watchlist: Displaying a table of all movies (+113, -1)

routes.py (+4, -0)

From: curriculum/section14/lectures/09_display_table_of_all_movies/start/movie_library/routes.py

To: curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/routes.py

            
            index 6d3bf0c..41e967f 100644
--- a/curriculum/section14/lectures/09_display_table_of_all_movies/start/movie_library/routes.py
+++ b/curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/routes.py
@@ -21,9 +21,13 @@ pages = Blueprint(
 
 @pages.route("/")
 def index():
+    movie_data = current_app.db.movie.find({})
+    movies = [Movie(**movie) for movie in movie_data]
+
     return render_template(
         "index.html",
         title="Movies Watchlist",
+        movies_data=movies,
     )
        

movies.css (+74, -0)

From: curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/static/css/movies.css

To: curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/static/css/movies.css

            
            new file mode 100644
index 0000000..d659766
--- /dev/null
+++ b/curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/static/css/movies.css
@@ -0,0 +1,74 @@
+.button--add {
+  position: absolute;
+  bottom: 4rem;
+  right: 2rem;
+  display: flex;
+  height: 5rem;
+  width: 5rem;
+  border: var(--border);
+  border-radius: 50%;
+  color: var(--text-dark);
+  text-decoration: none;
+  font-weight: 600;
+  font-size: 1.75rem;
+  align-items: center;
+  justify-content: center;
+}
+
+@media screen and (min-width: 50em) {
+  .button--add {
+    right: 3rem;
+  }
+}
+
+@media screen and (min-width: 80em) {
+  .button--add {
+    right: 4rem;
+  }
+}
+
+.button--add:hover {
+  color: var(--text);
+  background-color: var(--accent-colour);
+}
+
+.table {
+  max-width: 50rem;
+  width: 100%;
+  margin: 0 auto;
+  border-spacing: 0;
+}
+
+.table__cell {
+  padding: 1.25rem 1rem;
+}
+
+.table__cell--header {
+  text-align: left;
+  padding: 0.5rem 1rem;
+  border-bottom: var(--border);
+}
+
+.table__link {
+  color: inherit;
+  text-decoration: none;
+}
+
+.table__link:hover {
+  text-decoration: underline;
+  text-decoration-color: var(--accent-colour);
+}
+
+.table__movieTitle {
+  font-weight: 600;
+}
+
+.table__movieDirector {
+  font-size: 0.85em;
+}
+
+.table__empty {
+  display: block;
+  text-align: center;
+  font-size: 1.2rem;
+}
        

index.html (+35, -1)

From: curriculum/section14/lectures/09_display_table_of_all_movies/start/movie_library/templates/index.html

To: curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/templates/index.html

            
            index 27eb611..ec65068 100644
--- a/curriculum/section14/lectures/09_display_table_of_all_movies/start/movie_library/templates/index.html
+++ b/curriculum/section14/lectures/09_display_table_of_all_movies/end/movie_library/templates/index.html
@@ -1,10 +1,44 @@
 {% extends "layout.html" %}
 
 {% block head_content %}
+    <link rel="stylesheet" href="{{ url_for('static', filename='css/movies.css') }}" />
 {% endblock %}
 
 {% block main_content %}
+    {% if movies_data %}
+        <table class="table">
+            <colgroup>
+                <col style="width: 60%">
+                <col style="width: 25%">
+                <col style="width: 15%">
+            </colgroup>
+            <thead>
+                <tr class="table__header">
+                    <th class="table__cell table__cell--header">Title</th>
+                    <th class="table__cell table__cell--header">Release Date</th>
+                    <th class="table__cell table__cell--header"></th>
+                </tr>
+            </thead>
+            <tbody>
+                {% for movie in movies_data %}
+                    <tr>
+                        <td class="table__cell">
+                            <p class="table__movieTitle">{{ movie.title }}</p>
+                            <p class="table__movieDirector">By {{ movie.director }}</p>
+                        </td>
+                        <td class="table__cell">{{ movie.year }}</td>
+                        <td class="table__cell"><a href="#" class="table__link">View</a></td>
+                    </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+        
+    {% else %}
+        <p class="table__empty">You haven't added any movies yet. <a href="{{ url_for('pages.add_movie') }}" class="link">Add one!</a></p>
+    {% endif %}
 
-    <h1>Movies</h1>
+    <a href="{{ url_for('pages.add_movie') }}" class="button button--add">
+        <span>+</span>
+    </a>
 
 {% endblock %}