diff --git a/__pycache__/app.cpython-311.pyc b/__pycache__/app.cpython-311.pyc index 98f75ca..dc26c20 100644 Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ diff --git a/__pycache__/models.cpython-311.pyc b/__pycache__/models.cpython-311.pyc index 36fe5b5..b221bcb 100644 Binary files a/__pycache__/models.cpython-311.pyc and b/__pycache__/models.cpython-311.pyc differ diff --git a/app.py b/app.py index 76fda66..5093145 100644 --- a/app.py +++ b/app.py @@ -6,7 +6,7 @@ import subprocess from werkzeug.utils import secure_filename from functools import wraps from extensions import db, bcrypt, login_manager -from models import User, Player, Content # Import the models from models.py +from models import User, Player, Content, Group # Add Group to the imports from flask_login import login_user, logout_user, login_required, current_user app = Flask(__name__, instance_relative_config=True) @@ -59,8 +59,9 @@ def convert_ppt_to_pdf(input_file, output_file): @login_required def dashboard(): players = Player.query.all() + groups = Group.query.all() logo_exists = os.path.exists(os.path.join(app.config['UPLOAD_FOLDERLOGO'], 'logo.png')) - return render_template('dashboard.html', players=players, logo_exists=logo_exists) + return render_template('dashboard.html', players=players, groups=groups, logo_exists=logo_exists) @app.route('/register', methods=['GET', 'POST']) def register(): @@ -112,33 +113,13 @@ def upload_content(): file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(file_path) - if media_type == 'pdf': - # Convert PDF to PNG - images = convert_from_path(file_path) - for i, image in enumerate(images): - image_filename = f"{os.path.splitext(filename)[0]}_page_{i + 1}.png" - image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename) - image.save(image_path, 'PNG') - new_content = Content(file_name=image_filename, duration=duration, player_id=target_id if target_type == 'player' else None) + 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) - os.remove(file_path) # Remove the original PDF file - elif media_type == 'ppt': - # Convert PPT/PPTX to PDF - pdf_filename = f"{os.path.splitext(filename)[0]}.pdf" - pdf_path = os.path.join(app.config['UPLOAD_FOLDER'], pdf_filename) - convert_ppt_to_pdf(file_path, pdf_path) - # Convert PDF to PNG - images = convert_from_path(pdf_path) - for i, image in enumerate(images): - image_filename = f"{os.path.splitext(filename)[0]}_page_{i + 1}.png" - image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename) - image.save(image_path, 'PNG') - new_content = Content(file_name=image_filename, duration=duration, player_id=target_id if target_type == 'player' else None) - db.session.add(new_content) - os.remove(file_path) # Remove the original PPT/PPTX file - os.remove(pdf_path) # Remove the intermediate PDF file - else: - new_content = Content(file_name=filename, duration=duration, player_id=target_id if target_type == 'player' else None) + elif target_type == 'player': + new_content = Content(file_name=filename, duration=duration, player_id=target_id) db.session.add(new_content) db.session.commit() @@ -147,8 +128,12 @@ def upload_content(): target_type = request.args.get('target_type') target_id = request.args.get('target_id') return_url = request.args.get('return_url', url_for('dashboard')) - players = Player.query.all() - return render_template('upload_content.html', target_type=target_type, target_id=target_id, players=players, return_url=return_url) + + # Serialize players and groups into JSON-serializable dictionaries + players = [{'id': player.id, 'username': player.username} for player in Player.query.filter(~Player.groups.any()).all()] + groups = [{'id': group.id, 'name': group.name} for group in Group.query.all()] + + return render_template('upload_content.html', target_type=target_type, target_id=target_id, players=players, groups=groups, return_url=return_url) @app.route('/admin') @login_required @@ -417,6 +402,62 @@ def inject_theme(): theme = 'light' return dict(theme=theme) +@app.route('/group/create', methods=['GET', 'POST']) +@login_required +@admin_required +def create_group(): + if request.method == 'POST': + group_name = request.form['name'] + player_ids = request.form.getlist('players') + new_group = Group(name=group_name) + for player_id in player_ids: + player = Player.query.get(player_id) + if player: + new_group.players.append(player) + db.session.add(new_group) + db.session.commit() + return redirect(url_for('dashboard')) + players = Player.query.all() + return render_template('create_group.html', players=players) + +@app.route('/group//manage') +@login_required +@admin_required +def manage_group(group_id): + group = Group.query.get_or_404(group_id) + content = Content.query.filter(Content.player_id.in_([player.id for player in group.players])).all() + return render_template('manage_group.html', group=group, content=content) + +@app.route('/group//edit', methods=['GET', 'POST']) +@login_required +@admin_required +def edit_group(group_id): + group = Group.query.get_or_404(group_id) + if request.method == 'POST': + group.name = request.form['name'] + player_ids = request.form.getlist('players') + group.players = [Player.query.get(player_id) for player_id in player_ids if Player.query.get(player_id)] + db.session.commit() + return redirect(url_for('dashboard')) + players = Player.query.all() + return render_template('edit_group.html', group=group, players=players) + +@app.route('/group//delete', methods=['POST']) +@login_required +@admin_required +def delete_group(group_id): + group = Group.query.get_or_404(group_id) + db.session.delete(group) + db.session.commit() + return redirect(url_for('dashboard')) + +@app.route('/group//fullscreen', methods=['GET']) +@login_required +def group_fullscreen(group_id): + group = Group.query.get_or_404(group_id) + content = Content.query.filter(Content.player_id.in_([player.id for player in group.players])).all() + return render_template('group_fullscreen.html', group=group, content=content) + if __name__ == '__main__': with app.app_context(): db.create_all() # Creează toate tabelele diff --git a/instance/dashboard.db b/instance/dashboard.db index 155d7e9..7ddf48b 100644 Binary files a/instance/dashboard.db and b/instance/dashboard.db differ diff --git a/models.py b/models.py index 823ccf4..db15864 100644 --- a/models.py +++ b/models.py @@ -48,4 +48,15 @@ class User(db.Model, UserMixin): def get_id(self): return str(self.id) +class Group(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(100), nullable=False, unique=True) + players = db.relationship('Player', secondary='group_player', backref='groups') + +# Association table for many-to-many relationship between Group and Player +group_player = db.Table('group_player', + db.Column('group_id', db.Integer, db.ForeignKey('group.id'), primary_key=True), + db.Column('player_id', db.Integer, db.ForeignKey('player.id'), primary_key=True) +) + # other models... \ No newline at end of file diff --git a/static/uploads/Ibex_450.jpg b/static/uploads/Ibex_450.jpg deleted file mode 100644 index 5f3b4b8..0000000 Binary files a/static/uploads/Ibex_450.jpg and /dev/null differ diff --git a/static/uploads/SampleVideo_1280x720_30mb.mp4 b/static/uploads/SampleVideo_1280x720_30mb.mp4 deleted file mode 100644 index f29424e..0000000 Binary files a/static/uploads/SampleVideo_1280x720_30mb.mp4 and /dev/null differ diff --git a/static/uploads/big_buck_bunny_720p_1mb.mp4 b/static/uploads/big_buck_bunny_720p_1mb.mp4 deleted file mode 100644 index ed139d6..0000000 Binary files a/static/uploads/big_buck_bunny_720p_1mb.mp4 and /dev/null differ diff --git a/static/uploads/car_modular.jpg b/static/uploads/car_modular.jpg deleted file mode 100644 index c129b85..0000000 Binary files a/static/uploads/car_modular.jpg and /dev/null differ diff --git a/static/uploads/cover-1685882567.png b/static/uploads/cover-1685882567.png new file mode 100644 index 0000000..01b62fd Binary files /dev/null and b/static/uploads/cover-1685882567.png differ diff --git a/static/uploads/harting_contact_2.jpg b/static/uploads/harting_contact_2.jpg deleted file mode 100644 index efc69e4..0000000 Binary files a/static/uploads/harting_contact_2.jpg and /dev/null differ diff --git a/static/uploads/harting_contactor.jpg b/static/uploads/harting_contactor.jpg deleted file mode 100644 index d188777..0000000 Binary files a/static/uploads/harting_contactor.jpg and /dev/null differ diff --git a/static/uploads/track.png b/static/uploads/track.png new file mode 100644 index 0000000..eb097c1 Binary files /dev/null and b/static/uploads/track.png differ diff --git a/templates/create_group.html b/templates/create_group.html new file mode 100644 index 0000000..122bdf0 --- /dev/null +++ b/templates/create_group.html @@ -0,0 +1,15 @@ +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/templates/dashboard.html b/templates/dashboard.html index 3cb7186..8552cc1 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -69,6 +69,35 @@ + +
+
+

Group of Players

+
+
+ + +
+
+
diff --git a/templates/edit_group.html b/templates/edit_group.html new file mode 100644 index 0000000..d619850 --- /dev/null +++ b/templates/edit_group.html @@ -0,0 +1,15 @@ +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/templates/manage_group.html b/templates/manage_group.html new file mode 100644 index 0000000..5808f01 --- /dev/null +++ b/templates/manage_group.html @@ -0,0 +1,85 @@ + + + + + + Manage Group + + + +
+

Manage Group: {{ group.name }}

+ + +
+
+

Group Info

+
+
+

Group Name: {{ group.name }}

+

Number of Players: {{ group.players|length }}

+
+
+ + +
+
+

Players in Group

+
+
+
    + {% for player in group.players %} +
  • +
    + {{ player.username }} ({{ player.hostname }}) +
    +
  • + {% endfor %} +
+
+
+ + +
+
+

Manage Media

+
+
+ {% if content %} +
    + {% for media in content %} +
  • +
    +

    Media Name: {{ media.file_name }}

    +
    +
    +
    + seconds + +
    + +
    +
    + +
    +
  • + {% endfor %} +
+ {% else %} +

No media uploaded for this group.

+ {% endif %} +
+
+ + + + + + Back to Dashboard +
+ + + + \ No newline at end of file diff --git a/templates/player_page.html b/templates/player_page.html index b8ec0dd..78c8ab2 100644 --- a/templates/player_page.html +++ b/templates/player_page.html @@ -69,12 +69,12 @@
seconds - +
- +
- +
{% endfor %} @@ -86,9 +86,14 @@
{% endif %} + Back to Dashboard Full Screen - Upload Media + + {% if player.groups %}Manage Media by Group{% else %}Upload Media{% endif %} +
diff --git a/templates/upload_content.html b/templates/upload_content.html index d2dfb15..3175770 100644 --- a/templates/upload_content.html +++ b/templates/upload_content.html @@ -45,7 +45,7 @@
- @@ -56,16 +56,19 @@
{% if target_id %} @@ -98,6 +101,36 @@