From aab05e61179e895ad68fc4782fc65fe8a481c3f1 Mon Sep 17 00:00:00 2001 From: Scheianu Ionut Date: Mon, 19 May 2025 22:05:13 +0300 Subject: [PATCH] updated to upload pictures --- __pycache__/extensions.cpython-312.pyc | Bin 371 -> 371 bytes __pycache__/models.cpython-312.pyc | Bin 4887 -> 4887 bytes app.py | 30 ++++++++++--- instance/dashboard.db | Bin 45056 -> 45056 bytes templates/admin.html | 57 ++++++++++++++----------- templates/dashboard.html | 20 +++------ 6 files changed, 63 insertions(+), 44 deletions(-) diff --git a/__pycache__/extensions.cpython-312.pyc b/__pycache__/extensions.cpython-312.pyc index d9890331bdd81b2cdc51f36233f3eaac687fdac6..b6757c209679f2f6045fd60af574ac01f605090b 100644 GIT binary patch delta 21 bcmey&^qGn0G%qg~0}y0bYh`TYNoNEAL1+a) delta 21 bcmey&^qGn0G%qg~0}$+e{5^dmPdXz2O>qYa diff --git a/__pycache__/models.cpython-312.pyc b/__pycache__/models.cpython-312.pyc index 4dda5b050d6289c7afbb3af17a7e75aeec0590cc..d1819115dfa6e5d2af9ab8c7abad7776f43ccc49 100644 GIT binary patch delta 21 bcmbQPHeHS9G%qg~0}y0bYh`TY;T8q}H@XCd delta 21 bcmbQPHeHS9G%qg~0}$+e{5^dm54SJ?L&FA7 diff --git a/app.py b/app.py index 827ff00..8fceb5c 100644 --- a/app.py +++ b/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_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 os.makedirs(app.instance_path, exist_ok=True) @@ -56,9 +59,22 @@ def admin_required(f): return f(*args, **kwargs) return decorated_function -def convert_ppt_to_pdf(input_file, output_file): - command = ['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', os.path.dirname(output_file), input_file] - subprocess.run(command, check=True) +def add_image_to_playlist(file, filename, duration, target_type, target_id): + """ + 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): """ @@ -174,7 +190,8 @@ def upload_content(): filename = secure_filename(file.filename) file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(file_path) - + filename = secure_filename(file.filename) + file_ext = os.path.splitext(filename)[1].lower() # Handle PDF files if media_type == 'pdf': print(f"Processing PDF file: {file_path}") @@ -193,7 +210,10 @@ def upload_content(): 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) 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 elif media_type == 'video': # Add the video file to the playlist diff --git a/instance/dashboard.db b/instance/dashboard.db index 1b0f415a7c37dd3eb967b60c29a7ce5428d4bd4b..af2976776f58289f07580de50942fb91c95e98ca 100644 GIT binary patch delta 42 zcmV+_0M-A1-~xc)0+1U4mXRDo1(pCVc8RfMrGE#x53di74_UJifO8L#kbR<%AXr@x AFaQ7m delta 81 zcmZp8z|`=7X@WFk_e2?I)@}y9WX6ptOY7O+@So$~#lLK`KtnOVa03Gb$U$ia29b%5 T!i)$)Zla?sqsZnD{Q?RAyCxKU diff --git a/templates/admin.html b/templates/admin.html index c2b25c3..4a2bc0f 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -159,34 +159,39 @@ - -
-
-

Change Theme

-
-
-
-
- - +
+
+ +
+
+

Change Theme

- - +
+
+
+ + +
+ +
+
+
-
- - -
-
-

Clean Unused Files

-
-
-
- -
+
+ +
+
+

Clean Unused Files

+
+
+
+ +
+
+
diff --git a/templates/dashboard.html b/templates/dashboard.html index 2325cdb..29a4352 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -51,8 +51,9 @@
- -
+ +
+

Players

@@ -84,10 +85,7 @@ {% endif %}
-
- - -
+

Group of Players

@@ -115,10 +113,7 @@
-
- - -
+

Content Upload

@@ -128,10 +123,9 @@
- - + {% if current_user.role == 'admin' %} -
+

App Settings