From 318f783de370056216eb4fd0f84e3954411715cc Mon Sep 17 00:00:00 2001 From: ske087 Date: Fri, 1 Aug 2025 15:15:59 -0400 Subject: [PATCH] Fix orientation parameter handling and template URL endpoints - Add orientation parameter support to create_group and edit_group functions - Fix manage_group.html template URL endpoint from 'update_group_content_order' to 'update_group_content_order_route' - Add orientation field and filtering to edit_group.html template with JavaScript functionality - Update group_player_management.py to handle orientation validation in create and edit operations - Fix docker-compose.yml to include build directive and correct volume paths - Update entrypoint.sh to handle fresh deployments without migrations - Ensure orientation consistency across group and player management These changes resolve: - Internal Server Error on manage_group page - Missing orientation parameter in group creation/editing - Template URL endpoint mismatches - Docker deployment issues with fresh installations --- app.py | 6 ++-- docker-compose.yml | 3 +- entrypoint.sh | 18 ++++------- instance/dashboard.db | Bin 40960 -> 0 bytes templates/edit_group.html | 52 +++++++++++++++++++++++++++++++ templates/manage_group.html | 2 +- utils/group_player_management.py | 13 ++++++-- 7 files changed, 76 insertions(+), 18 deletions(-) delete mode 100644 instance/dashboard.db diff --git a/app.py b/app.py index 584e58b..8f886ea 100755 --- a/app.py +++ b/app.py @@ -488,7 +488,8 @@ def create_group(): if request.method == 'POST': group_name = request.form['name'] player_ids = request.form.getlist('players') - create_group_util(group_name, player_ids) + orientation = request.form.get('orientation', 'Landscape') + create_group_util(group_name, player_ids, orientation) flash(f'Group "{group_name}" created successfully.', 'success') return redirect(url_for('dashboard')) players = Player.query.all() @@ -514,7 +515,8 @@ def edit_group(group_id): if request.method == 'POST': name = request.form['name'] player_ids = request.form.getlist('players') - edit_group_util(group_id, name, player_ids) + orientation = request.form.get('orientation', group.orientation) + edit_group_util(group_id, name, player_ids, orientation) flash(f'Group "{name}" updated successfully.', 'success') return redirect(url_for('dashboard')) players = Player.query.all() diff --git a/docker-compose.yml b/docker-compose.yml index 7df0c97..f1ef723 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ #version: '"1.1.0"' services: web: + build: . image: digiserver:latest ports: - "8880:5000" @@ -12,5 +13,5 @@ services: - SECRET_KEY=Ma_Duc_Dupa_Merele_Lui_Ana volumes: - /opt/digi-s/instance:/app/instance - - /opt/digi-s/static/uploads:/app/static/uploads + - /opt/digi-s/uploads:/app/static/uploads restart: unless-stopped diff --git a/entrypoint.sh b/entrypoint.sh index cd6b7b1..9b71a32 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,16 +7,7 @@ mkdir -p instance # Check if database exists if [ ! -f instance/dashboard.db ]; then - echo "No database found, initializing..." - - # Remove and recreate migrations directory to ensure clean state - rm -rf migrations - mkdir -p migrations - - # Initialize the database - flask db init - flask db migrate -m "Initial migration" - flask db upgrade + echo "No database found, creating fresh database..." # Create admin user if environment variables are set if [ -n "$ADMIN_USER" ] && [ -n "$ADMIN_PASSWORD" ]; then @@ -26,8 +17,11 @@ if [ ! -f instance/dashboard.db ]; then echo "Warning: ADMIN_USER or ADMIN_PASSWORD not set, skipping admin creation" fi else - echo "Existing database found, applying migrations..." - flask db upgrade + echo "Existing database found, skipping initialization..." + echo "Creating admin user if needed..." + if [ -n "$ADMIN_USER" ] && [ -n "$ADMIN_PASSWORD" ]; then + flask create-admin --username "$ADMIN_USER" --password "$ADMIN_PASSWORD" 2>/dev/null || echo "Default user '$ADMIN_USER' already exists." + fi fi echo "Starting DigiServer..." diff --git a/instance/dashboard.db b/instance/dashboard.db deleted file mode 100644 index 67f6fdd6d9f7b78a9aa67e00bcef9a62fe0b9b2f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40960 zcmeI)PjA|090zbaArPntRi((Ps!dO;Mg*xa|A82oCXJU!vK;IrZVV>I zr0rpwl4`GF+F?8GvTKh!?Y_%ydl5Ts+G&sNP;dw+jS?wpzZM4b`0?{Rzt8hLCIs-4 zwN=wK$hPe?HJ3=tb%te`&k11|<_298bnPusx)JF;p^xmq_NdJpOs>HuQ~xsY_z%p? z->E;6|IPfK{QBBoi65{1Op~xc00Izz00bZa0SNR34!?`XxLdc_*Bh?3Wf={-I;qyyl_jN4YLC`QZDV!y9!bQvP0LVQTGJp;EA_=M zEA@G?P{@R`=v_y1O}lmK@oh_cWjN}H(%W{&96Z#k@o~NSuu|V7E6OIBH}#B{_TW)n zsV>#LwE4FsW=LImpwyMxqVj|Usr~_p%+W+F#?8&Kua|s*9mnpr)gZ^<_H@W%aE}KP zJRjBYv0;Tm=#_KtxQ*0eD5hSXP)K+D)H~-zkf)>E${fp>E!}w8*|+GQ>#EjuZU4C% z)Oc(u3_gn=eH)E&H*d1vf92~1d4l^`NGwPjGkCfk!x=wzcI}QkK1W;YbY9qwK6?D^ zcg@Bg9my@D;i{)*_lA(ySj+6V>Ve^O21cv5&$1hPhOWByF-yPGy}h<$()kk%@!lj5 z7Q%BN)Z?dg@Nf+yyE>6Myfqc$Zr^5)Sib`(B5kv3**pEMXs9Fl>0>%WYxpy*7s1dp zcFm^IakXZf+@~jq_3A^#3;twav~^39F^=Qdqh^0{`Qs-NYSY`%JMz>L>UV+X!=h(V zAJ?ZR8}0?OQLCB?$g;(6kbME@a`w+ z%gnU*Qj?@BoBEZZH!Ki<00bZa0SG_<0uX=z1Rwwb2wVk$H8#d@hg00FrZ>&jU2*HK zAl}`5(b}uEN(<|qgXgwX-B9%9rrmX9ZBw!gdo_PwFMT2%ytGwXH2p zOp_N{hv8$wCaw=}+(YqxgNq}#S^O*eG!`s}?+WA>Uc zSoK0#%$Io~mtPPT@}e81Rm+!AwU9ow)_g%0WoL@kDpeMP%aoocT21#tb?q}nDwYbx z{NqT3*$)LOh*Iu(+juuSsVs;&Q7V;+;>u)%*?E@|he(3L#D$VrtWHFjMqi}gwlhW= z6vY>*?o&3xd^0=}O?Q{Pz4m6>X`5O1U~rf=978)XObca+FXzQvUgir$x%d75l=?wU zYy=Ad2tWV=5P$##AOHafKmY;|xL|>wF1WmlEw1In( diff --git a/templates/edit_group.html b/templates/edit_group.html index 6e66e3a..55441a3 100644 --- a/templates/edit_group.html +++ b/templates/edit_group.html @@ -49,12 +49,24 @@ +
+
+ + +
+
+
Back to Dashboard @@ -62,5 +74,45 @@
+ \ No newline at end of file diff --git a/templates/manage_group.html b/templates/manage_group.html index 6535791..aaaf8a8 100644 --- a/templates/manage_group.html +++ b/templates/manage_group.html @@ -189,7 +189,7 @@ document.addEventListener('DOMContentLoaded', function() { }); // Send to server - fetch('{{ url_for("update_group_content_order", group_id=group.id) }}', { + fetch('{{ url_for("update_group_content_order_route", group_id=group.id) }}', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/utils/group_player_management.py b/utils/group_player_management.py index 2d4c960..b0e34b7 100644 --- a/utils/group_player_management.py +++ b/utils/group_player_management.py @@ -35,15 +35,24 @@ def create_group(name, player_ids, orientation='Landscape'): log_group_created(name) return new_group -def edit_group(group_id, name, player_ids): +def edit_group(group_id, name, player_ids, orientation=None): """ - Edit an existing group, updating its name and players. + Edit an existing group, updating its name, orientation, and players. Handles locking/unlocking players appropriately. """ group = Group.query.get_or_404(group_id) old_name = group.name # Store old name in case it changes group.name = name + # Update orientation if provided + if orientation: + group.orientation = orientation + # Validate that all selected players have the matching orientation + for player_id in player_ids: + player = Player.query.get(player_id) + if player and player.orientation != orientation: + raise ValueError(f"Player '{player.username}' has orientation '{player.orientation}', which does not match group orientation '{orientation}'.") + # Get current players in the group current_player_ids = [player.id for player in group.players]