30 lines
964 B
Python
30 lines
964 B
Python
"""
|
|
Main application routes
|
|
"""
|
|
|
|
from flask import Blueprint, render_template, request
|
|
from app.models.database import PetPicture
|
|
from app.utils.auth import is_authenticated
|
|
from app.utils.helpers import get_liked_pictures_from_cookie, add_liked_status_to_pictures
|
|
|
|
main_bp = Blueprint('main', __name__)
|
|
|
|
|
|
@main_bp.route('/')
|
|
def index():
|
|
"""Main gallery page - shows all pictures for admins, posted only for public"""
|
|
# Get liked pictures from cookie
|
|
liked_list = get_liked_pictures_from_cookie(request)
|
|
|
|
# Get pictures based on authentication status
|
|
if is_authenticated():
|
|
pictures = PetPicture.get_all()
|
|
public_view = False
|
|
else:
|
|
pictures = PetPicture.get_posted()
|
|
public_view = True
|
|
|
|
# Add liked status to pictures
|
|
pictures_with_likes = add_liked_status_to_pictures(pictures, liked_list)
|
|
|
|
return render_template("index.html", pictures=pictures_with_likes, public_view=public_view) |