Skip to content

richardgreg/catalog-project

Repository files navigation

Item (Classical Book) Catalog

About

This is a RESTful web application, using the Python framework Flask, which provides a list of items (books) within a variety of categories (genres) as well as provides user registration and authentication system. Registered users will have the ability to post, edit and delete their own items.

'/' or '/categories' - Homepage displaying categories and successful login. Homepage

Why this project and specifically a book catalog?

Modern web applications perform a variety of functions and provide amazing features and utilities to their users; but deep down, it’s really all just creating, reading, updating and deleting data. I am a avid reader. I enjoyed reading classical books as a child. My favorite genre was Mythology.

'/category/<int:category_id>/item/' - Route displaying items relative to a category. Display Category Items

'/category/<int:category_id>/item/<int:category_item_id>/' - A single book item description. Category Item Description

'/category/<int:category_id>/item/new/' - Form to add a new book. User must be logged in. Add Form

'/category/<int:category_id>/item/<int:category_item_id>/edit' - Edit book item. Edit is restricted to owner of item. Edit Form

'/category/<int:category_id>/item/<int:category_item_id>/delete' - Delete item. Delete Item

What is needed:

You'll run these program using a Unix-style terminal on your computer; the point of it is to be able to offer the same software (Linux) regardless of what kind of computer you're running on. If you are using a Mac or Linux system, your regular terminal program will do just fine. On Windows, we recommend using the Git Bash terminal that comes with the Git software.

In order to make use of third party authentication and authorization (google OAuth) feature, one will require a google account.

Geting Started

Virtual machine
  • Download and install VirtualBox. Install the platform package for your operating system. You do not need the extension pack or the SDK. You do not need to launch VirtualBox after installing it; Vagrant will do that. Ubuntu users: If you are running Ubuntu 14.04, install VirtualBox using the Ubuntu Software Center instead. Due to a reported bug, installing VirtualBox from the site may uninstall other software you need.
  • Download and Install vagrant. You can check if vagrant is installed by running vagrant --version
  • Download the VM configuration. Unzip the file. Using the terminal, navigate into the vagrant subdirectory.
  • Clone the catalog-project and move it into the /FSND-Virtual-Machine/vagrant/ subdirectory. This particular step can actually be done at any point in time, but to avoid any confusion, do this.
  • From your terminal, inside the vagrant subdirectory, run the command vagrant up. This will cause Vagrant to download the Linux operating system and install it. This may take quite a while (many minutes) depending on how fast your Internet connection is. When vagrant up is finished running, you will get your shell prompt back. At this point, you can run vagrant ssh to log in to your newly installed Linux VM! Inside the VM, change directory to /vagrant and look around with ls.

The files you see here are the same as the ones in the /FSND-Virtual-Machine/vagrant/ subdirectory on your computer (where you started Vagrant from). Any file you create in one will be automatically shared to the other. This means that you can edit code in your favorite text editor, and run it inside the VM.

OAuth
  • Go to console.developers.google
  • Create a new project and name it Book-ish, just for the sake of consistency, but you can name it whatever you like
  • Go to the Credentials section. Go to the OAuth consent screen tab first of all. You only have to enter the application name. Then back to the credentials tab, create a new OAuth client ID. Make sure you select Web Application. The name can be whatever. Authorized JavaScript origin: should be: http://localhost:8000. Authorized redirect URIs: http://localhost:8000/login and http://localhost:8000/gconnect. Save and create. You'll be presented with a client ID and client secrets.
  • Now, download the JSON attached to the OAuth client ID you just created. Make sure you do this after the above steps have been completed. If you do it before, the origins and authorized uris may not appear in the JSON file.
  • Rename the JSON file as client_secrets.json. You can delete the dummy public_client_secrets.json file that comes with the catalog-project.

Open the login.html template in /template directory with your favorite text editor.

<!-- GOOGLE PLUS SIGN IN BUTTON-->

          
          <div id="signinButton">
          <span class="g-signin"
            data-scope="openid email"
            data-clientid="CLIENT-ID"
            data-redirecturi="postmessage"
            data-accesstype="offline"
            data-cookiepolicy="single_host_origin"
            data-callback="signInCallback"
            data-approvalprompt="force">
          </span>
        </div>

Copy your google OAuth cliend ID. and replace CLIENT-ID. And you're good to go for the authentication and authorization.

Files in the VM's /vagrant directory are shared with the vagrant folder on your computer. But other data inside the VM is not. For instance the project dependencies are not. You can cd into the /catalog-project directory (or whatever you named it when cloning).

How to run app

While in the the project directory, via your terminal:

  • First, enter the command python3 database_setup.py
  • Secondly, enter python3 install_categories.py
  • Finally, enter python3 application.py

😑

Possible Improvements

  • Structure the Flask app in a way that allows scalability.
  • Run software packages with Docker instead of Vagrant since the former is more light-weight.
  • Use the flask-restful library to build scalable API endpoints.
  • Give users an option to add/upload images for book items.
  • More OAuth providers to expand userbase.