kinda working safe point
This commit is contained in:
parent
b9a82af12f
commit
6dda02141e
31 changed files with 4302 additions and 2937 deletions
|
@ -1,59 +1,46 @@
|
|||
from flask import Blueprint, render_template
|
||||
from flask import Blueprint, render_template, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from datetime import datetime, timedelta
|
||||
from app.models import File, Share, Download
|
||||
from ..models import File, Folder
|
||||
import os
|
||||
|
||||
dashboard_bp = Blueprint('dashboard', __name__)
|
||||
# Create blueprint with the name expected by __init__.py
|
||||
bp = Blueprint('dashboard', __name__)
|
||||
|
||||
@dashboard_bp.route('/')
|
||||
@bp.route('/')
|
||||
@bp.route('/index')
|
||||
@login_required
|
||||
def index():
|
||||
# Get some stats for the dashboard
|
||||
total_files = File.query.filter_by(user_id=current_user.id, is_folder=False).count()
|
||||
total_folders = File.query.filter_by(user_id=current_user.id, is_folder=True).count()
|
||||
"""Dashboard index page"""
|
||||
# Count user's files and folders
|
||||
file_count = File.query.filter_by(user_id=current_user.id).count()
|
||||
folder_count = Folder.query.filter_by(user_id=current_user.id).count()
|
||||
|
||||
# Recent files for quick access
|
||||
recent_files = File.query.filter_by(user_id=current_user.id, is_folder=False)\
|
||||
.order_by(File.updated_at.desc())\
|
||||
.limit(8).all()
|
||||
# Get storage usage
|
||||
storage_used = sum(file.size for file in File.query.filter_by(user_id=current_user.id).all())
|
||||
|
||||
# Root folders for quick navigation
|
||||
root_folders = File.query.filter_by(user_id=current_user.id, is_folder=True, parent_id=None)\
|
||||
.order_by(File.name)\
|
||||
.limit(8).all()
|
||||
# Format size for display
|
||||
if storage_used < 1024:
|
||||
storage_used_formatted = f"{storage_used} bytes"
|
||||
elif storage_used < 1024 * 1024:
|
||||
storage_used_formatted = f"{storage_used / 1024:.2f} KB"
|
||||
elif storage_used < 1024 * 1024 * 1024:
|
||||
storage_used_formatted = f"{storage_used / (1024 * 1024):.2f} MB"
|
||||
else:
|
||||
storage_used_formatted = f"{storage_used / (1024 * 1024 * 1024):.2f} GB"
|
||||
|
||||
# Count active shares (if Share model exists)
|
||||
active_shares = 0
|
||||
recent_activities = 0
|
||||
# Get recent files
|
||||
recent_files = File.query.filter_by(user_id=current_user.id).order_by(File.created_at.desc()).limit(5).all()
|
||||
|
||||
# Check if Share and Download models exist/are imported
|
||||
try:
|
||||
# Count active shares
|
||||
active_shares = Share.query.filter_by(user_id=current_user.id).filter(
|
||||
(Share.expires_at > datetime.now()) | (Share.expires_at.is_(None))
|
||||
).count()
|
||||
|
||||
# Recent activities count (downloads, shares, etc.)
|
||||
recent_activities = Download.query.join(Share)\
|
||||
.filter(Share.user_id == current_user.id)\
|
||||
.filter(Download.timestamp > (datetime.now() - timedelta(days=7)))\
|
||||
.count()
|
||||
except:
|
||||
# Models not ready yet, using default values
|
||||
pass
|
||||
# Create stats object that the template is expecting
|
||||
stats = {
|
||||
'file_count': file_count,
|
||||
'folder_count': folder_count,
|
||||
'storage_used': storage_used_formatted
|
||||
}
|
||||
|
||||
return render_template('dashboard.html',
|
||||
title='Dashboard',
|
||||
total_files=total_files,
|
||||
total_folders=total_folders,
|
||||
recent_files=recent_files,
|
||||
root_folders=root_folders,
|
||||
active_shares=active_shares,
|
||||
recent_activities=recent_activities,
|
||||
now=datetime.now(),
|
||||
file_icon=get_file_icon,
|
||||
format_size=format_file_size)
|
||||
return render_template('dashboard/index.html',
|
||||
stats=stats, # Pass as stats object
|
||||
recent_files=recent_files)
|
||||
|
||||
def get_file_icon(mime_type, filename):
|
||||
"""Return Font Awesome icon class based on file type"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue