init
This commit is contained in:
38
app/main/routes.py
Normal file
38
app/main/routes.py
Normal 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)
|
||||
Reference in New Issue
Block a user