added management options for media
This commit is contained in:
217
app.py
217
app.py
@@ -53,6 +53,7 @@ class Group(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(80), unique=True, nullable=False)
|
||||
players = db.relationship('Player', secondary='group_players', backref='groups')
|
||||
content = db.relationship('Content', backref='group', lazy=True)
|
||||
|
||||
group_players = db.Table('group_players',
|
||||
db.Column('group_id', db.Integer, db.ForeignKey('group.id'), primary_key=True),
|
||||
@@ -110,43 +111,6 @@ def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@app.route('/add_player', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def add_player():
|
||||
if request.method == 'POST':
|
||||
username = request.form['username']
|
||||
hostname = request.form['hostname']
|
||||
ip = request.form['ip']
|
||||
password = request.form['password']
|
||||
|
||||
new_player = Player(username=username, hostname=hostname, ip=ip, password=password)
|
||||
db.session.add(new_player)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
return render_template('add_player.html')
|
||||
|
||||
@app.route('/add_group', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def add_group():
|
||||
if request.method == 'POST':
|
||||
group_name = request.form['group_name']
|
||||
selected_players = request.form.getlist('players')
|
||||
|
||||
new_group = Group(name=group_name)
|
||||
for player_id in selected_players:
|
||||
player = Player.query.get(int(player_id))
|
||||
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('add_group.html', players=players)
|
||||
|
||||
@app.route('/upload_content', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def upload_content():
|
||||
@@ -167,63 +131,6 @@ def upload_content():
|
||||
return redirect(url_for('dashboard'))
|
||||
return render_template('upload_content.html')
|
||||
|
||||
@app.route('/content/<int:content_id>/edit', methods=['POST'])
|
||||
@login_required
|
||||
def edit_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
new_duration = int(request.form['duration'])
|
||||
content.duration = new_duration
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=content.player_id))
|
||||
|
||||
@app.route('/content/<int:content_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
player_id = content.player_id
|
||||
db.session.delete(content)
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=player_id))
|
||||
|
||||
@app.route('/player/<int:player_id>/fullscreen')
|
||||
@login_required
|
||||
def player_fullscreen(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
content = Content.query.filter_by(player_id=player_id).all()
|
||||
return render_template('player_fullscreen.html', player=player, content=content)
|
||||
|
||||
@app.route('/player/<int:player_id>')
|
||||
@login_required
|
||||
def player_page(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
content = Content.query.filter_by(player_id=player_id).all()
|
||||
return render_template('player_page.html', player=player, content=content)
|
||||
|
||||
@app.route('/player/<int:player_id>/upload', methods=['POST'])
|
||||
@login_required
|
||||
def upload_content_to_player(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
files = request.files.getlist('files')
|
||||
duration = int(request.form['duration'])
|
||||
|
||||
for file in files:
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
file.save(file_path)
|
||||
new_content = Content(file_name=filename, duration=duration, player_id=player_id)
|
||||
db.session.add(new_content)
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=player_id))
|
||||
|
||||
@app.route('/player/<int:player_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_player(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
db.session.delete(player)
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
@app.route('/admin')
|
||||
@login_required
|
||||
@admin_required
|
||||
@@ -282,6 +189,16 @@ def add_player_to_group(group_id):
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=group_id))
|
||||
|
||||
@app.route('/group/<int:group_id>/remove_player/<int:player_id>', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def remove_player_from_group(group_id, player_id):
|
||||
group = Group.query.get_or_404(group_id)
|
||||
player = Player.query.get_or_404(player_id)
|
||||
group.players.remove(player)
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=group_id))
|
||||
|
||||
@app.route('/group/<int:group_id>/upload', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
@@ -300,6 +217,118 @@ def upload_content_to_group(group_id):
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=group_id))
|
||||
|
||||
@app.route('/group/content/<int:content_id>/edit', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def edit_group_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
new_duration = int(request.form['duration'])
|
||||
content.duration = new_duration
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=content.group_id))
|
||||
|
||||
@app.route('/group/content/<int:content_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def delete_group_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
group_id = content.group_id
|
||||
db.session.delete(content)
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=group_id))
|
||||
|
||||
@app.route('/player/<int:player_id>')
|
||||
@login_required
|
||||
def player_page(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
content = Content.query.filter_by(player_id=player_id).all()
|
||||
return render_template('player_page.html', player=player, content=content)
|
||||
|
||||
@app.route('/player/<int:player_id>/upload', methods=['POST'])
|
||||
@login_required
|
||||
def upload_content_to_player(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
files = request.files.getlist('files')
|
||||
duration = int(request.form['duration'])
|
||||
|
||||
for file in files:
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
file.save(file_path)
|
||||
new_content = Content(file_name=filename, duration=duration, player_id=player_id)
|
||||
db.session.add(new_content)
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=player_id))
|
||||
|
||||
@app.route('/content/<int:content_id>/edit', methods=['POST'])
|
||||
@login_required
|
||||
def edit_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
new_duration = int(request.form['duration'])
|
||||
content.duration = new_duration
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=content.player_id))
|
||||
|
||||
@app.route('/content/<int:content_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_content(content_id):
|
||||
content = Content.query.get_or_404(content_id)
|
||||
player_id = content.player_id
|
||||
db.session.delete(content)
|
||||
db.session.commit()
|
||||
return redirect(url_for('player_page', player_id=player_id))
|
||||
|
||||
@app.route('/player/<int:player_id>/fullscreen')
|
||||
@login_required
|
||||
def player_fullscreen(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
if player.groups:
|
||||
# If the player is part of a group, get the group's content
|
||||
group = player.groups[0] # Assuming a player can only be in one group
|
||||
content = Content.query.filter_by(group_id=group.id).all()
|
||||
else:
|
||||
# If the player is not part of a group, get the player's content
|
||||
content = Content.query.filter_by(player_id=player_id).all()
|
||||
return render_template('player_fullscreen.html', player=player, content=content)
|
||||
|
||||
@app.route('/player/<int:player_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def delete_player(player_id):
|
||||
player = Player.query.get_or_404(player_id)
|
||||
db.session.delete(player)
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
@app.route('/player/add', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def add_player():
|
||||
if request.method == 'POST':
|
||||
username = request.form['username']
|
||||
hostname = request.form['hostname']
|
||||
ip = request.form['ip']
|
||||
password = request.form['password']
|
||||
hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
|
||||
new_player = Player(username=username, hostname=hostname, ip=ip, password=hashed_password)
|
||||
db.session.add(new_player)
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
return render_template('add_player.html')
|
||||
|
||||
@app.route('/group/add', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def add_group():
|
||||
if request.method == 'POST':
|
||||
name = request.form['name']
|
||||
new_group = Group(name=name)
|
||||
db.session.add(new_group)
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
return render_template('add_group.html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
db.create_all() # Creează toate tabelele
|
||||
|
||||
Binary file not shown.
@@ -2,19 +2,31 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Group</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Add Group</h1>
|
||||
<form method="POST">
|
||||
<label>Group Name:</label>
|
||||
<input type="text" name="group_name" required><br>
|
||||
<label>Select Players:</label><br>
|
||||
{% for player in players %}
|
||||
<input type="checkbox" name="players" value="{{ player.id }}">
|
||||
{{ player.username }}<br>
|
||||
{% endfor %}
|
||||
<button type="submit">Create Group</button>
|
||||
</form>
|
||||
<a href="{{ url_for('dashboard') }}">Back to Dashboard</a>
|
||||
<div class="container py-5">
|
||||
<h1 class="text-center mb-4">Add Group</h1>
|
||||
<form action="{{ url_for('add_group') }}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Group Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="players" class="form-label">Select Players</label><br>
|
||||
{% for player in players %}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="players" value="{{ player.id }}" id="player{{ player.id }}">
|
||||
<label class="form-check-label" for="player{{ player.id }}">
|
||||
{{ player.username }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Create Group</button>
|
||||
</form>
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -2,20 +2,32 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Player</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Add Player</h1>
|
||||
<form method="POST">
|
||||
<label>Username:</label>
|
||||
<input type="text" name="username" required><br>
|
||||
<label>Hostname:</label>
|
||||
<input type="text" name="hostname" required><br>
|
||||
<label>IP:</label>
|
||||
<input type="text" name="ip" required><br>
|
||||
<label>Password:</label>
|
||||
<input type="password" name="password" required><br>
|
||||
<button type="submit">Add Player</button>
|
||||
</form>
|
||||
<a href="{{ url_for('dashboard') }}">Back to Dashboard</a>
|
||||
<div class="container py-5">
|
||||
<h1 class="text-center mb-4">Add Player</h1>
|
||||
<form action="{{ url_for('add_player') }}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="hostname" class="form-label">Hostname</label>
|
||||
<input type="text" class="form-control" id="hostname" name="hostname" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ip" class="form-label">IP Address</label>
|
||||
<input type="text" class="form-control" id="ip" name="ip" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add Player</button>
|
||||
</form>
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -28,6 +28,25 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Players in Group Section -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-secondary text-white">
|
||||
<h2>Players in Group</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-group">
|
||||
{% for player in group.players %}
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>{{ player.username }} ({{ player.ip }})</div>
|
||||
<form action="{{ url_for('remove_player_from_group', group_id=group.id, player_id=player.id) }}" method="post" class="d-inline">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to remove this player from the group?');">Remove</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Upload Content Section -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-success text-white">
|
||||
@@ -48,6 +67,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manage Group Content Section -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-warning text-dark">
|
||||
<h2>Manage Group Content</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-group">
|
||||
{% for content in group.content %}
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>{{ content.file_name }} - {{ content.duration }} seconds</div>
|
||||
<div>
|
||||
<!-- Edit Duration Form -->
|
||||
<form action="{{ url_for('edit_group_content', content_id=content.id) }}" method="post" class="d-inline">
|
||||
<input type="number" name="duration" value="{{ content.duration }}" class="form-control d-inline-block" style="width: 80px;" required>
|
||||
<button type="submit" class="btn btn-sm btn-warning">Edit</button>
|
||||
</form>
|
||||
<!-- Delete Content Form -->
|
||||
<form action="{{ url_for('delete_group_content', content_id=content.id) }}" method="post" class="d-inline">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this content?');">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary">Back to Dashboard</a>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
<h4 class="text-center">Member of Group(s):</h4>
|
||||
<ul class="list-group">
|
||||
{% for group in player.groups %}
|
||||
<li class="list-group-item">{{ group.name }}</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<div>{{ group.name }}</div>
|
||||
<form action="{{ url_for('remove_player_from_group', group_id=group.id, player_id=player.id) }}" method="post" class="d-inline">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to remove this player from the group?');">Remove</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
@@ -34,6 +39,7 @@
|
||||
<div>
|
||||
{{ item.file_name }} - {{ item.duration }} seconds
|
||||
</div>
|
||||
{% if not player.groups %}
|
||||
<div>
|
||||
<!-- Edit Duration Form -->
|
||||
<form action="{{ url_for('edit_content', content_id=item.id) }}" method="post" class="d-inline">
|
||||
@@ -45,6 +51,7 @@
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this resource?');">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
@@ -52,6 +59,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Upload Section -->
|
||||
{% if not player.groups %}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-success text-white">
|
||||
<h2>Upload Content</h2>
|
||||
@@ -70,8 +78,10 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary">Back to Dashboard</a>
|
||||
<a href="{{ url_for('player_fullscreen', player_id=player.id) }}" class="btn btn-primary">Full Screen</a>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user