proj2.Flask_app

app = <Flask 'proj2.Flask_app'>
db_file = '/home/runner/work/SE25Fall/SE25Fall/proj2/CSC510_DB.db'
def parse_generated_menu(gen_str):

Parse a serialized generated-menu string into a date-indexed structure. Args: gen_str (str): A string like "[YYYY-MM-DD,ID,(meal)]..." where meal is 1|2|3 (optional). Returns: dict: Mapping 'YYYY-MM-DD' -> [{'itm_id': int, 'meal': int}, ...].

def palette_for_item_ids(item_ids):

Generate a deterministic, pleasant color palette for item IDs. Args: item_ids (Iterable[int]): The menu item IDs to colorize. Returns: dict: Mapping itm_id -> hex color string (e.g., '#a1b2c3').

def fetch_menu_items_by_ids(ids):

Load menu items (and their restaurant metadata) for given item IDs. Args: ids (Iterable[int]): The item IDs to fetch. Returns: dict: Mapping itm_id -> dict with fields like name, price, calories, allergens, and restaurant info (name, address, hours, phone).

def build_calendar_cells(gen_map, year, month, items_by_id):

Build month-view calendar cells enriched with menu items per day. Args: gen_map (dict): Mapping 'YYYY-MM-DD' -> [{'itm_id': int, 'meal': 1|2|3}, ...]. year (int): The calendar year. month (int): The calendar month (1–12). items_by_id (dict): Mapping itm_id -> item detail dict from DB. Returns: list: A flat list of calendar cell dicts with day number and a 'meals' list.

@app.route('/', defaults={'year': None, 'month': None})
@app.route('/<int:year>/<int:month>')
def index(year, month):

Render the calendar home view for the current or specified month. Args: year (int | None): Optional year path parameter. month (int | None): Optional month path parameter (1–12). Returns: Response: HTML page showing the monthly plan and today's meals (requires login).

@app.route('/login', methods=['GET', 'POST'])
def login():

Display the login form (GET) and authenticate user credentials (POST). Args: None Returns: Response: Renders login page, or redirects to home on successful login.

@app.route('/logout')
def logout():

Clear the user session and redirect to the login page. Args: None Returns: Response: Redirect to the login route.

@app.route('/register', methods=['GET', 'POST'])
def register():

Display the registration form (GET) and create a new user (POST). Args: None Returns: Response: Renders registration page or redirects to login on success.

@app.route('/profile')
def profile():

Show the logged-in user's profile, including recent orders. Args: None Returns: Response: HTML profile page (requires login).

@app.route('/profile/edit', methods=['GET', 'POST'])
def edit_profile():

Display and process the profile edit form (phone, preferences, allergies). Args: None Returns: Response: Renders form (GET) or updates and redirects to profile (POST).

@app.route('/profile/change-password', methods=['POST'])
def change_password():

Change the current user's password after validating the current password. Args: None Returns: Response: Redirect back to profile with success or error flags.

@app.route('/order', methods=['GET', 'POST'])
def order():

Place an order via JSON (POST) or handle legacy single-item GET flow. Args: None Returns: Response: JSON with {'ok', 'ord_id'} on POST; redirects/HTML for legacy GET.

@app.route('/orders')
def orders():

List restaurants and in-stock menu items for browsing. Args: None Returns: Response: HTML page showing restaurants and items (requires login).

@app.route('/restaurants')
def restaurants():

Browse restaurants with details and currently in-stock items. Args: None Returns: Response: HTML page listing restaurants and their items (requires login).

@app.route('/orders/<int:ord_id>/receipt.pdf')
def order_receipt(ord_id: int):

Stream a PDF receipt for an order owned by the logged-in user. Args: ord_id (int): The order identifier in the path. Returns: Response: PDF file download or an error status (404/403) if inaccessible.

@app.route('/db')
def db_view():

Display a simple, paginated database table viewer. Args: None Returns: Response: HTML page showing rows/columns for a selected table (requires login).

def parse_args() -> argparse.Namespace: