/Python_SQLAlchemy_Project

Lab 4c for COMP 353 to create dynamic web content based off database values

Primary LanguagePython

Python_SQLAlchemy_Project

Lab 4c for COMP 353 to create dynamic web content based off database values

How to

Prerequisites

  • Your system must have MySQL or Mariadb running as a system process (and you must know the credentials to log in to it)
  • Your system must have Python installed with the following pip packages:
    • Flask
    • Flask-WTF
    • Flask-MySQLdb
    • Flask-SQLAlchemy
    • mysql
    • mysql-connector-python

Setup

  • Clone this repository: git clone https://github.com/Jkotheimer/Python_SQLAlchemy_Project
  • Move into the project directory: cd Python_SQLAlchemy_Project
  • Create the database: ./exec_sql.sh (this script also takes .sql files as a parameter to execute)
    • (Optional) Add test values into the database: ./exec_sql.sh sql/test_insertions.sql
  • Start the server: python run.py
  • Visit the webpage at http://localhost:5000

Developer info

  • flask_app/routes.py

    • / & /home: The home page of the site - displays all projects and employees who work on them
    • /about: A general info page (not implemented)
    • /assign: A form to select an employee and a project from drop down boxes, assigning the employee to the given project
    • /employees: Display all employees and present a form to add a new employee
    • /employees/<ssn>: Get all info about the employee with the specified social security number
    • /projects: Display all projects and who is working on them
    • /projects/<ID>: Get all info about the project with the specified ID number
  • flask_app/models.py

    • A Flask Pythonic class representation of the database created at sql/create_db.sql
  • flask_app/forms.py

    • AssignForm: Grabs all Employees and projects and places them into drop boxes
    • RemovalForm: Grabs all info from a specified SSN or ProjectID and puts them into radio boxes
    • EmployeeForm: String fields to create a new employee with a SSN and a name
    • ProjectForm: String field to create a new project with a name
  • flask_app/_init_.py

    • Connects the credentials imported from sql_config.py (which is generated by exec_sql.sh) to your local MySQL database
    • Glues together all of the above peices into the main app and serves it with Flask