startup page seting
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
digiscreen/
|
||||
enviroment.txt
|
||||
|
||||
110
app.py
Normal file
110
app.py
Normal file
@@ -0,0 +1,110 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Configurare baza de date SQLite
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dashboard.db'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
# Modele pentru baza de date
|
||||
class Player(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(80), nullable=False)
|
||||
hostname = db.Column(db.String(120), nullable=False)
|
||||
ip = db.Column(db.String(15), nullable=False)
|
||||
password = db.Column(db.String(120), nullable=False)
|
||||
|
||||
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')
|
||||
|
||||
group_players = db.Table('group_players',
|
||||
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)
|
||||
)
|
||||
|
||||
class Content(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
file_name = db.Column(db.String(120), nullable=False)
|
||||
duration = db.Column(db.Integer, nullable=False)
|
||||
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), nullable=True)
|
||||
group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True)
|
||||
|
||||
@app.before_first_request
|
||||
def create_tables():
|
||||
db.create_all()
|
||||
|
||||
@app.route('/')
|
||||
def dashboard():
|
||||
players = Player.query.all()
|
||||
groups = Group.query.all()
|
||||
return render_template('dashboard.html', players=players, groups=groups)
|
||||
|
||||
@app.route('/add_player', methods=['GET', 'POST'])
|
||||
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'])
|
||||
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'])
|
||||
def upload_content():
|
||||
if request.method == 'POST':
|
||||
target_type = request.form['target_type']
|
||||
target_id = request.form['target_id']
|
||||
files = request.files.getlist('files')
|
||||
duration = int(request.form['duration'])
|
||||
|
||||
for file in files:
|
||||
if target_type == 'player':
|
||||
new_content = Content(file_name=file.filename, duration=duration, player_id=int(target_id))
|
||||
elif target_type == 'group':
|
||||
new_content = Content(file_name=file.filename, duration=duration, group_id=int(target_id))
|
||||
db.session.add(new_content)
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
players = Player.query.all()
|
||||
groups = Group.query.all()
|
||||
return render_template('upload_content.html', players=players, groups=groups)
|
||||
|
||||
@app.route('/player/<int:player_id>')
|
||||
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)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
20
templates/add_group.html
Normal file
20
templates/add_group.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Group</title>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
21
templates/add_player.html
Normal file
21
templates/add_player.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Player</title>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
33
templates/dashboard.html
Normal file
33
templates/dashboard.html
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
<h2>Players</h2>
|
||||
<ul>
|
||||
{% for player in players %}
|
||||
<li>
|
||||
{{ player.username }} ({{ player.ip }})
|
||||
<a href="{{ url_for('player_page', player_id=player.id) }}">View Schedule</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{{ url_for('add_player') }}">Add Player</a>
|
||||
|
||||
<h2>Groups</h2>
|
||||
<ul>
|
||||
{% for group_name, group in groups.items() %}
|
||||
<li>
|
||||
{{ group_name }} ({{ group.players | length }} players)
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{{ url_for('add_group') }}">Add Group</a>
|
||||
|
||||
<h2>Content Upload</h2>
|
||||
<a href="{{ url_for('upload_content') }}">Upload Content</a>
|
||||
</body>
|
||||
</html>
|
||||
15
templates/player_page.html
Normal file
15
templates/player_page.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Player Schedule</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Player Schedule</h1>
|
||||
<ul>
|
||||
{% for item in schedule %}
|
||||
<li>{{ item.file }} - {{ item.duration }} seconds</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{{ url_for('dashboard') }}">Back to Dashboard</a>
|
||||
</body>
|
||||
</html>
|
||||
37
templates/upload_content.html
Normal file
37
templates/upload_content.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Upload Content</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Upload Content</h1>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<label>Target Type:</label>
|
||||
<select name="target_type" required>
|
||||
<option value="player">Player</option>
|
||||
<option value="group">Group</option>
|
||||
</select><br>
|
||||
|
||||
<label>Target ID:</label>
|
||||
<select name="target_id" required>
|
||||
<optgroup label="Players">
|
||||
{% for player in players %}
|
||||
<option value="{{ player.id }}">{{ player.username }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
<optgroup label="Groups">
|
||||
{% for group_name in groups.keys() %}
|
||||
<option value="{{ group_name }}">{{ group_name }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
</select><br>
|
||||
|
||||
<label>Files:</label>
|
||||
<input type="file" name="files" multiple required><br>
|
||||
<label>Duration (seconds):</label>
|
||||
<input type="number" name="duration" required><br>
|
||||
<button type="submit">Upload</button>
|
||||
</form>
|
||||
<a href="{{ url_for('dashboard') }}">Back to Dashboard</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user