1 Project Files Overview
Candifloss edited this page 2025-03-08 07:23:06 +00:00

Project Files Overview

This page provides a detailed description of the files and directories in this application. The project is organized into several directories, each containing files that handle specific functionality. The directories, files, filenames, etc., may be subject to change in future versions in accordance with additional features or code refactoring.


Directory Structure

.
├── app.py
├── config.py
├── definitions
│   ├── attribute.py
│   └── models.py
├── functions
│   ├── auth.py
│   ├── process_csv.py
│   ├── validate_config.py
│   └── validate_values.py
├── routes
│   ├── confirm_save.py
│   ├── create.py
│   ├── delete.py
│   ├── export_csv.py
│   ├── homepage.py
│   ├── update.py
│   ├── upload.py
│   └── viewall.py
├── templates
│   ├── header.html
│   ├── csv_preview.html
│   ├── delete.html
│   ├── item_form.html
│   ├── login.html
│   ├── upload.html
│   └── viewList.html
└── static
    └── edited_csv.js

Core Files

app.py

  • The main application file.
  • Initializes the Flask app and registers blueprints.
  • Validates the configuration before starting the app.
  • Creates database tables if they don't exist.

config.py

  • Contains the application configuration:
    • MySQL connection details (sql_conf class).
    • List of item attributes (item_attributes).
    • Secret key for Flask sessions.

Templates

header.html

  • A reusable header component included in other templates.
  • Contains the title, "Inventory Manager," and buttons for navigation (e.g., "Logout," "Add New Item," "Import from CSV").

csv_preview.html

  • Displays a preview of CSV data in two tables:
    • New Items: Editable table for new entries.
    • Existing Items: Non-editable table for existing entries.
  • Includes JavaScript (edited_csv.js) to handle editing and submission of CSV data.

delete.html

  • Displays a confirmation page before deleting an item.
  • Shows the item details and asks for user confirmation.

item_form.html

  • A reusable form template for adding or editing items.
  • Dynamically generates form fields based on the item_attributes configuration.

login.html

  • Displays the login form for user authentication.
  • Includes fields for username and password.

upload.html

  • Provides a form for uploading CSV files.
  • Includes a file input and a submit button.

viewList.html

  • Displays all items in the database as an HTML table.
  • Includes buttons for adding, editing, deleting, and exporting items.

Definitions

attribute.py

  • Defines the types of data used in the app.
  • Classes:
    • Attribute: Base class for all attribute types.
    • textAttribute: For string/text data.
    • intAttribute: For integer data.
    • floatAttribute: For floating-point data.
    • dateAttribute: For date data.
    • selectAttribute: For dropdown selection menus.

models.py

  • Uses SQLAlchemy to handle database operations.
  • Dynamically creates the database table based on the item_attributes configuration.
  • Defines the Asset model for interacting with the database.

Functions

auth.py

  • Defines the login_required decorator.
  • Ensures that routes are accessible only to logged-in users.

process_csv.py

  • Extracts and processes data from uploaded CSV files.
  • Validates the CSV format and separates entries into new and existing items.

validate_config.py

  • Validates the item_attributes configuration.
  • Ensures that all attributes are properly defined and consistent.

validate_values.py

  • Validates user-submitted data.
  • Ensures that data adheres to the constraints defined in item_attributes.

Routes

confirm_save.py

  • Handles the submission of validated CSV data.
  • Inserts new items into the database or updates existing items.

create.py

  • Provides a form to add a new item to the database.
  • Validates data before insertion and displays validation errors.

delete.py

  • Handles the deletion of an item.
  • Displays a confirmation page before deletion.

export_csv.py

  • Exports all data from the database as a CSV file.

homepage.py

  • Handles user authentication:
    • /login: Displays the login form and authenticates users.
    • /logout: Logs out the user by clearing the session.
    • /: Redirects to /viewall if the user is logged in, or to /login if not.

update.py

  • Provides a form to edit an existing item in the database.
  • Validates data before updating and displays validation errors.

upload.py

  • Handles CSV file uploads.
  • Validates the file format and data, then redirects to the preview page.

viewall.py

  • Fetches and displays all items in the database as an HTML table.

Static Files

edited_csv.js

  • JavaScript for handling editable tables in csv_preview.html.
  • Ensures that edited data is submitted instead of the original CSV data.