Skip to content

Commit

Permalink
finalized the project
Browse files Browse the repository at this point in the history
  • Loading branch information
lucobaco committed Feb 9, 2023
1 parent a6ffe0a commit e10d28e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
33 changes: 23 additions & 10 deletions movie_library/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid
import datetime
from dataclasses import asdict
from flask import Blueprint, current_app, flash, redirect, render_template, session, url_for, request
from flask import Blueprint, current_app, flash, redirect, render_template, session, url_for, request, app
# Importing form and model classes from the movie_library module
from movie_library.forms import LoginForm, RegisterForm, MovieForm, ExtendedMovieForm
from movie_library.models import User, Movie
Expand All @@ -30,7 +30,9 @@ def route_wrapper(*args, **kwargs):
# If there is no email in the session, redirect to the login page
return redirect(url_for(".login"))
# If the email is in the session, call the original route
return route(*args, **kwargs)
# elif # check if user is in database with email and if not session destroy and then redirect to login
else:
return route(*args, **kwargs)

return route_wrapper

Expand Down Expand Up @@ -166,7 +168,7 @@ def add_movie():

@pages.route("/logout/")
def logout():
# Save the current theme so it can be restored after the session is cleared
# Save the current theme, so it can be restored after the session is cleared
current_theme = session.get("theme")

# Clear the session data
Expand Down Expand Up @@ -220,14 +222,16 @@ def edit_movie(_id: str):
return redirect(url_for(".movie", _id=movie._id))

# Render the template for the movie form with the movie data and form
# If the form has not been submitted or is not valid, the function renders the "movie_form.html" template
# with the movie data and form, allowing the user to edit the movie details.
return render_template("movie_form.html", movie=movie, form=form)


# Route to set when you watched a movie
@pages.get("/movie/<string:_id>/watch")
@login_required # User must be logged in to access this route
def watch_today(_id):
# Update the movie document in the database to set the last_watched field to the current date and time
# Update the movie document in the database to set the last_watched field to the current date
current_app.db.movie.update_one(
{"_id": _id}, {"$set": {"last_watched": datetime.datetime.today()}}
)
Expand All @@ -237,15 +241,19 @@ def watch_today(_id):


# Route to rate a movie
@pages.get("/movie/<string:_id>/rate")
@login_required # User must be logged in to access this route
def rate_movie(_id):
# Get the rating from the query parameters
@pages.get("/movie/<string:_id>/rate") # This route is triggered on a GET request to the endpoint "/movie/<_id>/rate"
@login_required # Require that the user is logged in to access this route
def rate_movie(_id): # The view function takes a single argument, the movie _id
# Get the rating value from the query parameters of the GET request
# The view function, named rate_movie, takes a single argument _id, which is a string passed as a part of the URL.
# The <string:_id> syntax in the route is a template variable, and it tells Flask to capture the value of the string
# that appears in that position in the URL and pass it to the view function as an argument.
rating = int(request.args.get("rating"))
# Update the movie document in the database to set the rating field

# Update the movie document in the database with the matching _id
current_app.db.movie.update_one({"_id": _id}, {"$set": {"rating": rating}})

# Redirect to the movie page
# Redirect the user to the movie page for the movie with the given _id
return redirect(url_for(".movie", _id=_id))


Expand All @@ -263,3 +271,8 @@ def toggle_theme():

# Redirect to the current page
return redirect(request.args.get("current_page"))

# @app.errorhandler(404)
# def page_not_found(error):
# # Renders the 404.html template and returns a 404 status code
# return render_template("404.html"), 404
35 changes: 35 additions & 0 deletions movie_library/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>

</body>
<!DOCTYPE html>
<html lang="en">

<head>
<title>Luca Binder | Portfolio</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
</head>

<body>
<main class="main main--error">
<h1>404 - Page Not Found</h1>
<p>
Sorry, we couldn't find the page you're looking for.
It may have been misspelled, or it doesn't exist anymore.
</p>
<a href="{{ url_for('home') }}">Go to home</a>
</main>
</body>

</html>
2 changes: 1 addition & 1 deletion movie_library/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% endblock %}

{% block main_content %}
<!-- Check if there are any movies in the movies_data variable -->
<!-- Check if movies_data variable is set -->
{%- if movies_data %}
<!-- Create a table for movie information -->
<table class="table">
Expand Down

0 comments on commit e10d28e

Please sign in to comment.