updated to upload pictures
This commit is contained in:
Binary file not shown.
Binary file not shown.
28
app.py
28
app.py
@@ -23,6 +23,9 @@ app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'Ana_Are_Multe_Mere-Si_Nu_Are
|
|||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'dashboard.db')
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(app.instance_path, 'dashboard.db')
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
|
# Set maximum content length to 1GB
|
||||||
|
app.config['MAX_CONTENT_LENGTH'] = 2048 * 2048 * 2048 # 1GB, adjust as needed
|
||||||
|
|
||||||
# Ensure the instance folder exists
|
# Ensure the instance folder exists
|
||||||
os.makedirs(app.instance_path, exist_ok=True)
|
os.makedirs(app.instance_path, exist_ok=True)
|
||||||
|
|
||||||
@@ -56,9 +59,22 @@ def admin_required(f):
|
|||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
def convert_ppt_to_pdf(input_file, output_file):
|
def add_image_to_playlist(file, filename, duration, target_type, target_id):
|
||||||
command = ['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', os.path.dirname(output_file), input_file]
|
"""
|
||||||
subprocess.run(command, check=True)
|
Save the image file and add it to the playlist database.
|
||||||
|
"""
|
||||||
|
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||||
|
# Only save if file does not already exist (prevents double-saving)
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
file.save(file_path)
|
||||||
|
if target_type == 'group':
|
||||||
|
group = Group.query.get_or_404(target_id)
|
||||||
|
for player in group.players:
|
||||||
|
new_content = Content(file_name=filename, duration=duration, player_id=player.id)
|
||||||
|
db.session.add(new_content)
|
||||||
|
elif target_type == 'player':
|
||||||
|
new_content = Content(file_name=filename, duration=duration, player_id=target_id)
|
||||||
|
db.session.add(new_content)
|
||||||
|
|
||||||
def convert_ppt_to_images(input_file, output_folder):
|
def convert_ppt_to_images(input_file, output_folder):
|
||||||
"""
|
"""
|
||||||
@@ -174,7 +190,8 @@ def upload_content():
|
|||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||||
file.save(file_path)
|
file.save(file_path)
|
||||||
|
filename = secure_filename(file.filename)
|
||||||
|
file_ext = os.path.splitext(filename)[1].lower()
|
||||||
# Handle PDF files
|
# Handle PDF files
|
||||||
if media_type == 'pdf':
|
if media_type == 'pdf':
|
||||||
print(f"Processing PDF file: {file_path}")
|
print(f"Processing PDF file: {file_path}")
|
||||||
@@ -193,6 +210,9 @@ def upload_content():
|
|||||||
if image_file.startswith(os.path.splitext(filename)[0]) and image_file.endswith('.jpg'):
|
if image_file.startswith(os.path.splitext(filename)[0]) and image_file.endswith('.jpg'):
|
||||||
new_content = Content(file_name=image_file, duration=duration, player_id=target_id)
|
new_content = Content(file_name=image_file, duration=duration, player_id=target_id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
|
# --- Add this block for images ---
|
||||||
|
elif media_type in ['jpg', 'jpeg', 'png'] or (media_type == 'image' and file_ext in ['.jpg', '.jpeg', '.png']):
|
||||||
|
add_image_to_playlist(file, filename, duration, target_type, target_id)
|
||||||
|
|
||||||
# Handle video files
|
# Handle video files
|
||||||
elif media_type == 'video':
|
elif media_type == 'video':
|
||||||
|
|||||||
Binary file not shown.
@@ -159,34 +159,39 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Change Theme Card -->
|
<div class="row">
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="col-lg-6 col-12">
|
||||||
<div class="card-header">
|
<!-- Change Theme Card -->
|
||||||
<h2>Change Theme</h2>
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
</div>
|
<div class="card-header">
|
||||||
<div class="card-body">
|
<h2>Change Theme</h2>
|
||||||
<form action="{{ url_for('change_theme') }}" method="post" onsubmit="showPopupMessage('Theme changed successfully!')">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="theme" class="form-label">Select Theme</label>
|
|
||||||
<select class="form-select" id="theme" name="theme" required>
|
|
||||||
<option value="light" {% if theme == 'light' %}selected{% endif %}>Light</option>
|
|
||||||
<option value="dark" {% if theme == 'dark' %}selected{% endif %}>Dark</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Change Theme</button>
|
<div class="card-body">
|
||||||
</form>
|
<form action="{{ url_for('change_theme') }}" method="post" onsubmit="showPopupMessage('Theme changed successfully!')">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="theme" class="form-label">Select Theme</label>
|
||||||
|
<select class="form-select" id="theme" name="theme" required>
|
||||||
|
<option value="light" {% if theme == 'light' %}selected{% endif %}>Light</option>
|
||||||
|
<option value="dark" {% if theme == 'dark' %}selected{% endif %}>Dark</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Change Theme</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="col-lg-6 col-12">
|
||||||
|
<!-- Clean Unused Files Card -->
|
||||||
<!-- Clean Unused Files Card -->
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="card-header">
|
||||||
<div class="card-header">
|
<h2>Clean Unused Files</h2>
|
||||||
<h2>Clean Unused Files</h2>
|
</div>
|
||||||
</div>
|
<div class="card-body">
|
||||||
<div class="card-body">
|
<form action="{{ url_for('clean_unused_files') }}" method="post" onsubmit="showPopupMessage('Clean script executed successfully!')">
|
||||||
<form action="{{ url_for('clean_unused_files') }}" method="post" onsubmit="showPopupMessage('Clean script executed successfully!')">
|
<button type="submit" class="btn btn-danger">Run Clean Script</button>
|
||||||
<button type="submit" class="btn btn-danger">Run Clean Script</button>
|
</form>
|
||||||
</form>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Players Section -->
|
<!-- Main Content: Players, Groups, Upload -->
|
||||||
<div class="col-md-8 col-12">
|
<div class="col-lg-9 col-12">
|
||||||
|
<!-- Players Section -->
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
<div class="card-header bg-primary text-white">
|
<div class="card-header bg-primary text-white">
|
||||||
<h2>Players</h2>
|
<h2>Players</h2>
|
||||||
@@ -84,10 +85,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<!-- Group of Players Section -->
|
||||||
|
|
||||||
<!-- Group of Players Section -->
|
|
||||||
<div class="col-md-8 col-12">
|
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
<div class="card-header bg-secondary text-white">
|
<div class="card-header bg-secondary text-white">
|
||||||
<h2>Group of Players</h2>
|
<h2>Group of Players</h2>
|
||||||
@@ -115,10 +113,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<!-- Content Upload Section -->
|
||||||
|
|
||||||
<!-- Content Upload Section -->
|
|
||||||
<div class="col-md-8 col-12">
|
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
<div class="card-header bg-warning text-dark">
|
<div class="card-header bg-warning text-dark">
|
||||||
<h2>Content Upload</h2>
|
<h2>Content Upload</h2>
|
||||||
@@ -128,10 +123,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- App Settings Section: Top right on desktop -->
|
||||||
<!-- App Settings Section -->
|
|
||||||
{% if current_user.role == 'admin' %}
|
{% if current_user.role == 'admin' %}
|
||||||
<div class="col-md-4 col-12">
|
<div class="col-lg-3 col-12">
|
||||||
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
<div class="card mb-4 {{ 'dark-mode' if theme == 'dark' else '' }}">
|
||||||
<div class="card-header bg-info text-white">
|
<div class="card-header bg-info text-white">
|
||||||
<h2>App Settings</h2>
|
<h2>App Settings</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user