gcp-hockey-results/motm_app/tables.py

47 lines
2.3 KiB
Python

from markupsafe import Markup
class matchSquadTable:
def __init__(self, items):
self.items = items
self.border = True
self.classes = []
def __html__(self):
"""Generate HTML table from items"""
if not self.items:
return Markup('<div class="alert alert-info text-center"><i class="fas fa-info-circle me-2"></i>No players in squad</div>')
# Start table with Bootstrap 5 classes
classes_str = ' '.join(self.classes) if self.classes else 'table table-striped table-hover'
html = f'<div class="table-responsive"><table class="{classes_str} mb-0">\n'
# Table header with modern styling
html += ' <thead class="table-dark">\n <tr>\n'
html += ' <th><i class="fas fa-hashtag me-1"></i>Player Number</th>\n'
html += ' <th><i class="fas fa-user me-1"></i>Nickname</th>\n'
html += ' <th><i class="fas fa-id-card me-1"></i>Surname</th>\n'
html += ' <th><i class="fas fa-id-card me-1"></i>Forenames</th>\n'
html += ' <th class="text-center"><i class="fas fa-cog me-1"></i>Actions</th>\n'
html += ' </tr>\n </thead>\n'
# Table body with enhanced styling
html += ' <tbody>\n'
for item in self.items:
html += ' <tr>\n'
html += f' <td><span class="badge bg-primary fs-6">#{item.get("playernumber", "")}</span></td>\n'
html += f' <td><strong>{item.get("playernickname", "")}</strong></td>\n'
html += f' <td>{item.get("playersurname", "")}</td>\n'
html += f' <td>{item.get("playerforenames", "")}</td>\n'
html += f' <td class="text-center">'
html += f'<form method="post" action="/admin/squad/remove?playerNumber={item.get("playernumber", "")}" class="d-inline">'
html += f'<button type="submit" class="btn btn-danger btn-sm" data-confirm="Are you sure you want to remove player #{item.get("playernumber", "")} from the squad?">'
html += f'<i class="fas fa-trash me-1"></i>Remove</button></form></td>\n'
html += ' </tr>\n'
html += ' </tbody>\n'
# End table
html += '</table></div>\n'
return Markup(html)