This commit is contained in:
hex
2025-04-29 13:54:11 -07:00
commit 0c38bf894c
32 changed files with 1431 additions and 0 deletions

38
app/main/routes.py Normal file
View File

@@ -0,0 +1,38 @@
from flask import render_template, current_app, flash, redirect, url_for
from app.main import bp
from app.models import Item, Category, ContactInfo
from app import db
@bp.route('/')
@bp.route('/index')
def index():
categories = Category.query.all()
items = Item.query.order_by(Item.created_at.desc()).all()
contact_info = ContactInfo.query.first()
# Create default contact info if it doesn't exist
if not contact_info:
contact_info = ContactInfo(
email="example@example.com",
signal="Signal Username or Number",
donation_link="https://example.com/donate"
)
db.session.add(contact_info)
db.session.commit()
return render_template('index.html',
title='Digital Garage Sale',
categories=categories,
items=items,
contact_info=contact_info)
@bp.route('/category/<int:id>')
def category(id):
category = Category.query.get_or_404(id)
items = Item.query.filter_by(category_id=id).order_by(Item.created_at.desc()).all()
contact_info = ContactInfo.query.first()
return render_template('category.html',
title=f'Category: {category.name}',
category=category,
items=items,
contact_info=contact_info)