For your course project, you will be responsible for developing a small web application, using the knowledge you gained from the course so far. You can choose one of the following options, with more...

1 answer below »
For your course project, you will be responsible for developing a small web application, using the knowledge you gained from the course so far. You can choose one of the following options, with more details below on each option: 1. Book Catalogue ­ A web application that helps a user record details about the books they own. The application allows a user to login and type in an ISBN, which will instigate a search using the Google Books API. The server will save some of the information to a database, which will be used to show the user their list of books. 2. A Blogging Application ­ A web application that allows a user to manage their own blog. A blog is simply a collection of "posts" (textual content), typically displayed in reverse chronological order. 3. Custom ­ If you have an idea for your own project, thats great! As long as it meets the criteria listed below, there should be no problem. However, you will need to pass this idea by me, and have my approval before starting. Useful Reminders 1. Read the project descriptions over a few times. At least twice. It always helps to have a clear picture of the overall assignment when understanding how to build a solution. 2. Think about the problem for a while, and even try writing or drawing a solution using pencil and paper or a whiteboard. 3. Make sure to put in a lot of effort to think about the ‘model’, or the database schema, before you start working on the code. What is it that you are trying to model? What relationships and properties do you need to model?Project Option 1: Book Catalogue Details: The purpose of this web application is to provide the end user with a fuctional interface that will allow the user to keep track of the books they own. The primary screen, after logging in, will show the user the books they have saved so far. Initially, this list will be blank. Users are also presented a form to search for books by ISBN. Once filled out, the application will use the Google Book API to search for the book via ISBN. To do this, let us take a look at an example. To search for a given ISBN, like 9781449372620 , you can navigate to https://www.googleapis.com/books/v1/volumes?q=isbn:9781449372620 and receive a JSON response that includes all sorts of metadata on the book. For now, we only need to show and store for the user the title, the author, page count and average rating. If there is any error in processing the JSON, you should return an appropriate error to the user. Sometimes, the API will come back with multiple results. For now, you can use the first result that comes back. The application should also allow the deletion of books. This will allow the user to delete a book from their list (either because they made a mistake, or they sold the book, etc).
Extra Credit: 1. Extend the application to support multiple users: You do not have to worry about supporting a full registration workflow. Use a table in the database to store users and their credentials, and use this table to support logins from many accounts. Please note: storing passwords that are unencrypted is a bad idea, security wise. However, there is no need for us to delve into that. 2. Save links to thumbnails: Use the JSON data to save the URL of a thumbnail, and show this thumbnail when listing out a user’s set of books 3. Handling multiple responses from Google: If the Google API gives you many responses for a single ISBN number, show the user the list of results and allow them to choose which one is the one they want to add to their list 4. Allow searching by title: Figure out how to use the Google API to search by title. Project Option 2: Blog Application Details The purpose of this web application is to give a user the ability to run their own blog. A blog is just a series of posts made by an author. Each post has a title, a published date, an author, and textual (HTML) content. When first loading the application at the root URL, the user should be presented with a list of available posts listed in reverse chronological order (newest posts first). The application should allow a user to login via the ‘/login’ URL, which gives that user the ability to make changes to the blog. After logging in, the user should be sent to the ‘/dashboard’ page, which presents the user with an interface that: 1. Shows a list of their posts in a table. This list just shows the title of the post, with buttons labeled ‘Edit’ and ‘Delete’. This edit button will take the user to a page that allows them to update the post. The delete button will simply delete that post. 2. Allows the user to add a new post (This can be done either directly on the dashboard page or on a new page)
Answered 27 days AfterMar 23, 2021

Answer To: For your course project, you will be responsible for developing a small web application, using the...

Sandeep Kumar answered on Apr 20 2021
162 Votes
book.db
bookcatalogueapp.py
import functools
import sqlite3
from sqlite3 import Error
import requests
from flask import Flask, render_template, request, redirect, session, flash, url_for, g, jsonify
import os
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
book_db = os.path.join(THIS_FOLDER, 'book.db')
app = Flask(__name__)
@app.route('/', methods= ['GET', 'POST'])
@app.route
('/login', methods= ['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
error = None

conn = sqlite3.connect(book_db)
with conn:
cur = conn.cursor()
cur.execute("SELECT * FROM accounts")
accounts = dict(cur.fetchall())
if username not in accounts.keys():
error = 'Incorrect username.'
elif password != accounts[username]:
error = 'Incorrect password.'
if error is None:
session.clear()
session['account_id'] = username
return redirect('/dashboard')
flash(error)
return render_template('login.html')
def login_required(view):
@functools.wraps(view)
def wrapped_view(**kwargs):
if session.get('account_id') is None:
return redirect('/login')
return view(**kwargs)
return wrapped_view
@app.route('/register', methods= ['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
error = None

conn = sqlite3.connect(book_db)
with conn:
cur = conn.cursor()
cur.execute("SELECT * FROM accounts")
accounts = dict(cur.fetchall())
if username in accounts.keys():
error = 'Username Taken!'
if error is None:
try:
cur.execute("INSERT INTO accounts VALUES(?,?)", [username, password])
session.clear()
session['account_id'] = username
return redirect('/dashboard')
except Error as e:
flash(e)
return redirect('/register')
flash(error)
return render_template('register.html')
@app.route('/logout')
def logout():
session.pop('account_id', None)
return redirect('/login')
@app.route('/dashboard')
@login_required
def dashboard():
conn = sqlite3.connect(book_db)
user = session.get('account_id')
with conn:
cur = conn.cursor()
try:
cur.execute("""
SELECT books.book_title, books.book_author, books.book_pages, books.book_rating, books.book_thumbnail, books.book_id
FROM books
INNER JOIN books_accounts ON books.book_id = books_accounts.book_id
WHERE books_accounts.account_id=?""", (user,))
books = cur.fetchall()
return render_template('dashboard.html', book_list = books, username = user)
except Error as e:
flash(e)
return render_template('dashboard.html', book_list = None, username = user)
@app.route('/remove_book', methods = ['POST'])
@login_required
def remove_book():
if request.method == 'POST':
book_del = request.form['book_id']
user = session.get('account_id')
conn = sqlite3.connect(book_db)
cur = conn.cursor()
with conn:
try:
cur.execute("DELETE FROM books_accounts WHERE book_id = ? AND account_id = ?", (book_del, user))
return redirect('/dashboard')
except Error as e:
flash(e)
return redirect('/dashboard')
@app.route('/add_book', methods = ['GET', 'POST'])
@login_required
def add_book():
if request.method ==...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here