updated to receive player message
This commit is contained in:
63
app/app.py
63
app/app.py
@@ -1,25 +1,10 @@
|
||||
# ...existing code...
|
||||
|
||||
# Player feedback API
|
||||
from models.player_feedback import PlayerFeedback
|
||||
# --- API route to receive player feedback ---
|
||||
@app.route('/api/player-feedback', methods=['POST'])
|
||||
def api_player_feedback():
|
||||
data = request.get_json()
|
||||
required_fields = ['player_name', 'quickconnect_code', 'message', 'status', 'timestamp']
|
||||
if not all(field in data for field in required_fields):
|
||||
return jsonify({'error': 'Missing required fields'}), 400
|
||||
|
||||
feedback = PlayerFeedback(
|
||||
player_name=data['player_name'],
|
||||
quickconnect_code=data['quickconnect_code'],
|
||||
message=data['message'],
|
||||
status=data['status'],
|
||||
timestamp=data['timestamp'],
|
||||
playlist_version=data.get('playlist_version'),
|
||||
error_details=data.get('error_details')
|
||||
)
|
||||
db.session.add(feedback)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'feedback_id': feedback.id}), 200
|
||||
# --- API route to receive player feedback ---
|
||||
|
||||
import os
|
||||
import click
|
||||
import psutil
|
||||
@@ -121,6 +106,38 @@ login_manager.login_view = 'login'
|
||||
|
||||
migrate = Migrate(app, db)
|
||||
|
||||
@app.route('/api/player-feedback', methods=['POST'])
|
||||
def api_player_feedback():
|
||||
from datetime import datetime
|
||||
import dateutil.parser
|
||||
|
||||
data = request.get_json()
|
||||
required_fields = ['player_name', 'quickconnect_code', 'message', 'status', 'timestamp']
|
||||
if not all(field in data for field in required_fields):
|
||||
return jsonify({'error': 'Missing required fields'}), 400
|
||||
|
||||
# Convert timestamp string to datetime object
|
||||
try:
|
||||
if isinstance(data['timestamp'], str):
|
||||
timestamp = dateutil.parser.parse(data['timestamp'])
|
||||
else:
|
||||
timestamp = data['timestamp']
|
||||
except (ValueError, TypeError):
|
||||
return jsonify({'error': 'Invalid timestamp format'}), 400
|
||||
|
||||
feedback = PlayerFeedback(
|
||||
player_name=data['player_name'],
|
||||
quickconnect_code=data['quickconnect_code'],
|
||||
message=data['message'],
|
||||
status=data['status'],
|
||||
timestamp=timestamp,
|
||||
playlist_version=data.get('playlist_version'),
|
||||
error_details=data.get('error_details')
|
||||
)
|
||||
db.session.add(feedback)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'feedback_id': feedback.id}), 200
|
||||
|
||||
# Add error handlers for better user experience
|
||||
@app.errorhandler(413)
|
||||
def request_entity_too_large(error):
|
||||
@@ -352,7 +369,13 @@ def create_user():
|
||||
def player_page(player_id):
|
||||
player = db.session.get(Player, player_id)
|
||||
content = get_player_content(player_id)
|
||||
return render_template('player_page.html', player=player, content=content)
|
||||
|
||||
# Get last 5 feedback entries for this player
|
||||
player_feedback = PlayerFeedback.query.filter_by(
|
||||
player_name=player.username
|
||||
).order_by(PlayerFeedback.timestamp.desc()).limit(5).all()
|
||||
|
||||
return render_template('player_page.html', player=player, content=content, player_feedback=player_feedback)
|
||||
|
||||
@app.route('/player/<int:player_id>/upload', methods=['POST'])
|
||||
@login_required
|
||||
|
||||
1
app/migrations/README
Normal file
1
app/migrations/README
Normal file
@@ -0,0 +1 @@
|
||||
Single-database configuration for Flask.
|
||||
50
app/migrations/alembic.ini
Normal file
50
app/migrations/alembic.ini
Normal file
@@ -0,0 +1,50 @@
|
||||
# A generic, single database configuration.
|
||||
|
||||
[alembic]
|
||||
# template used to generate migration files
|
||||
# file_template = %%(rev)s_%%(slug)s
|
||||
|
||||
# set to 'true' to run the environment during
|
||||
# the 'revision' command, regardless of autogenerate
|
||||
# revision_environment = false
|
||||
|
||||
|
||||
# Logging configuration
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic,flask_migrate
|
||||
|
||||
[handlers]
|
||||
keys = console
|
||||
|
||||
[formatters]
|
||||
keys = generic
|
||||
|
||||
[logger_root]
|
||||
level = WARN
|
||||
handlers = console
|
||||
qualname =
|
||||
|
||||
[logger_sqlalchemy]
|
||||
level = WARN
|
||||
handlers =
|
||||
qualname = sqlalchemy.engine
|
||||
|
||||
[logger_alembic]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = alembic
|
||||
|
||||
[logger_flask_migrate]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = flask_migrate
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
level = NOTSET
|
||||
formatter = generic
|
||||
|
||||
[formatter_generic]
|
||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||
datefmt = %H:%M:%S
|
||||
113
app/migrations/env.py
Normal file
113
app/migrations/env.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import logging
|
||||
from logging.config import fileConfig
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from alembic import context
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
logger = logging.getLogger('alembic.env')
|
||||
|
||||
|
||||
def get_engine():
|
||||
try:
|
||||
# this works with Flask-SQLAlchemy<3 and Alchemical
|
||||
return current_app.extensions['migrate'].db.get_engine()
|
||||
except (TypeError, AttributeError):
|
||||
# this works with Flask-SQLAlchemy>=3
|
||||
return current_app.extensions['migrate'].db.engine
|
||||
|
||||
|
||||
def get_engine_url():
|
||||
try:
|
||||
return get_engine().url.render_as_string(hide_password=False).replace(
|
||||
'%', '%%')
|
||||
except AttributeError:
|
||||
return str(get_engine().url).replace('%', '%%')
|
||||
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
config.set_main_option('sqlalchemy.url', get_engine_url())
|
||||
target_db = current_app.extensions['migrate'].db
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
|
||||
def get_metadata():
|
||||
if hasattr(target_db, 'metadatas'):
|
||||
return target_db.metadatas[None]
|
||||
return target_db.metadata
|
||||
|
||||
|
||||
def run_migrations_offline():
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url, target_metadata=get_metadata(), literal_binds=True
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online():
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
|
||||
# this callback is used to prevent an auto-migration from being generated
|
||||
# when there are no changes to the schema
|
||||
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
|
||||
def process_revision_directives(context, revision, directives):
|
||||
if getattr(config.cmd_opts, 'autogenerate', False):
|
||||
script = directives[0]
|
||||
if script.upgrade_ops.is_empty():
|
||||
directives[:] = []
|
||||
logger.info('No changes in schema detected.')
|
||||
|
||||
conf_args = current_app.extensions['migrate'].configure_args
|
||||
if conf_args.get("process_revision_directives") is None:
|
||||
conf_args["process_revision_directives"] = process_revision_directives
|
||||
|
||||
connectable = get_engine()
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=get_metadata(),
|
||||
**conf_args
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
24
app/migrations/script.py.mako
Normal file
24
app/migrations/script.py.mako
Normal file
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade():
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Add PlayerFeedback table
|
||||
|
||||
Revision ID: 217eab16e4e4
|
||||
Revises:
|
||||
Create Date: 2025-09-08 11:30:26.742813
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '217eab16e4e4'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('player_feedback',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('player_name', sa.String(length=255), nullable=False),
|
||||
sa.Column('quickconnect_code', sa.String(length=255), nullable=False),
|
||||
sa.Column('message', sa.Text(), nullable=False),
|
||||
sa.Column('status', sa.String(length=50), nullable=False),
|
||||
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
||||
sa.Column('playlist_version', sa.Integer(), nullable=True),
|
||||
sa.Column('error_details', sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('player_feedback')
|
||||
# ### end Alembic commands ###
|
||||
@@ -18,6 +18,9 @@ alembic==1.14.1
|
||||
Mako==1.3.8
|
||||
greenlet==3.1.1
|
||||
|
||||
# Date parsing
|
||||
python-dateutil==2.9.0
|
||||
|
||||
# File Processing
|
||||
pdf2image==1.17.0
|
||||
PyPDF2==3.0.1
|
||||
|
||||
@@ -54,20 +54,77 @@
|
||||
<div class="container py-5">
|
||||
<h1 class="text-center mb-4">Player Schedule for {{ player.username }}</h1>
|
||||
|
||||
<!-- Player Info Section -->
|
||||
<div class="card mb-4 {% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h2>Player Info</h2>
|
||||
<div class="row">
|
||||
<!-- Player Info Section -->
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4 {% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h2>Player Info</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p><strong>Player Name:</strong> {{ player.username }}</p>
|
||||
<p><strong>Hostname:</strong> {{ player.hostname }}</p>
|
||||
{% if current_user.role == 'admin' %}
|
||||
<a href="{{ url_for('edit_player', player_id=player.id, return_url=url_for('player_page', player_id=player.id)) }}" class="btn btn-warning">Update</a>
|
||||
<form action="{{ url_for('delete_player', player_id=player.id) }}" method="post" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this player?');">Delete</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p><strong>Player Name:</strong> {{ player.username }}</p>
|
||||
<p><strong>Hostname:</strong> {{ player.hostname }}</p>
|
||||
{% if current_user.role == 'admin' %}
|
||||
<a href="{{ url_for('edit_player', player_id=player.id, return_url=url_for('player_page', player_id=player.id)) }}" class="btn btn-warning">Update</a>
|
||||
<form action="{{ url_for('delete_player', player_id=player.id) }}" method="post" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this player?');">Delete</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<!-- Player Status Section -->
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4 {% if theme == 'dark' %}dark-mode{% endif %}">
|
||||
<div class="card-header bg-success text-white">
|
||||
<h2>Player Status</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if player_feedback %}
|
||||
<div class="mb-3">
|
||||
<strong>Current Status:</strong>
|
||||
<span class="badge bg-{{ 'success' if player_feedback[0].status in ['active', 'playing'] else 'danger' }}">
|
||||
{{ player_feedback[0].status|title }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Last Activity:</strong> {{ player_feedback[0].timestamp.strftime('%Y-%m-%d %H:%M:%S') }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Latest Message:</strong> {{ player_feedback[0].message }}
|
||||
</div>
|
||||
|
||||
<!-- Recent Activity Log -->
|
||||
<details>
|
||||
<summary class="fw-bold mb-2">Recent Activity (Last 5)</summary>
|
||||
<div class="mt-2">
|
||||
{% for feedback in player_feedback %}
|
||||
<div class="border-bottom pb-2 mb-2">
|
||||
<div class="d-flex justify-content-between">
|
||||
<span class="badge bg-{{ 'success' if feedback.status in ['active', 'playing'] else 'danger' }}">
|
||||
{{ feedback.status|title }}
|
||||
</span>
|
||||
<small class="text-muted">{{ feedback.timestamp.strftime('%m-%d %H:%M') }}</small>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
<small>{{ feedback.message }}</small>
|
||||
{% if feedback.playlist_version %}
|
||||
<br><small class="text-muted">Playlist v{{ feedback.playlist_version }}</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</details>
|
||||
{% else %}
|
||||
<div class="text-center text-muted">
|
||||
<p>No status information available</p>
|
||||
<small>Player hasn't sent any feedback yet</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
import os
|
||||
import subprocess
|
||||
from flask import Flask
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
Reference in New Issue
Block a user