add some data in dashboards

sync3
Razmig Sarkissian 5 months ago
parent 621f37791c
commit acdc1a270c
  1. 52
      tournaments/admin.py
  2. 157
      tournaments/templates/admin/tournaments/dashboard.html

@ -179,6 +179,41 @@ class TournamentAdmin(SyncedObjectAdmin):
avg_fee=Avg('entry_fee')
)['avg_fee'] or 0
# User Account Statistics
total_users = CustomUser.objects.count()
users_admin = CustomUser.objects.filter(origin=0).count() # ADMIN
users_site = CustomUser.objects.filter(origin=1).count() # SITE
users_app = CustomUser.objects.filter(origin=2).count() # APP
# Recent User Registrations
recent_users = CustomUser.objects.all().order_by('-date_joined')[:10]
# New users by period
users_today = CustomUser.objects.filter(date_joined__date=today).count()
users_this_week = CustomUser.objects.filter(
date_joined__date__gte=week_start,
date_joined__date__lte=week_end
).count()
users_this_month = CustomUser.objects.filter(
date_joined__date__gte=month_start,
date_joined__date__lte=today + timedelta(days=31 - today.day)
).count()
# Purchase Statistics
total_purchases = Purchase.objects.count()
recent_purchases = Purchase.objects.all().order_by('-purchase_date')[:10]
# Purchases by period
purchases_today = Purchase.objects.filter(purchase_date__date=today).count()
purchases_this_week = Purchase.objects.filter(
purchase_date__date__gte=week_start,
purchase_date__date__lte=week_end
).count()
purchases_this_month = Purchase.objects.filter(
purchase_date__date__gte=month_start,
purchase_date__date__lte=today + timedelta(days=31 - today.day)
).count()
context = {
'title': 'Tournament Dashboard',
'app_label': 'tournaments',
@ -224,6 +259,23 @@ class TournamentAdmin(SyncedObjectAdmin):
'tournaments_with_payment': tournaments_with_payment,
'avg_teams_per_tournament': round(avg_teams_per_tournament, 1),
'avg_entry_fee': round(avg_entry_fee, 2),
# User statistics
'total_users': total_users,
'users_admin': users_admin,
'users_site': users_site,
'users_app': users_app,
'users_today': users_today,
'users_this_week': users_this_week,
'users_this_month': users_this_month,
'recent_users': recent_users,
# Purchase statistics
'total_purchases': total_purchases,
'recent_purchases': recent_purchases,
'purchases_today': purchases_today,
'purchases_this_week': purchases_this_week,
'purchases_this_month': purchases_this_month,
}
return render(request, 'admin/tournaments/dashboard.html', context)

@ -21,7 +21,7 @@
<!-- Running Tournaments Card -->
<div class="stat-card" style="background: linear-gradient(135deg, #28a745, #20c997); color: white; border-radius: 12px; padding: 25px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);">
<h3 style="margin: 0 0 20px 0; display: flex; align-items: center; gap: 10px;">
🎾 Running Tournaments
🎾 Starting Tournaments
</h3>
<div class="tournament-stats">
<div style="display: flex; justify-content: space-between; margin-bottom: 15px;">
@ -125,6 +125,161 @@
</div>
</div>
<!-- New User Statistics -->
<div class="user-section" style="background: white; border: 1px solid #dee2e6; border-radius: 12px; padding: 25px; margin: 20px 0;">
<h3 style="margin: 0 0 20px 0; color: #495057; display: flex; align-items: center; gap: 10px;">
👤 User Statistics
</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;">
<!-- User Counts by Origin -->
<div style="background: #f8f9fa; border-radius: 8px; padding: 20px;">
<h4 style="margin: 0 0 15px 0;">Total Users: {{ total_users }}</h4>
<div style="display: flex; justify-content: space-between; margin-bottom: 10px;">
<span>Admin:</span>
<strong>{{ users_admin }}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 10px;">
<span>Site:</span>
<strong>{{ users_site }}</strong>
</div>
<div style="display: flex; justify-content: space-between;">
<span>App:</span>
<strong>{{ users_app }}</strong>
</div>
<div style="margin-top: 15px;">
<div style="height: 20px; background: #e9ecef; border-radius: 10px; overflow: hidden; display: flex;">
{% if total_users > 0 %}
<div style="width: {{ users_admin|floatformat:0 }}%; height: 100%; background: #6c757d;" title="Admin: {{ users_admin }}"></div>
<div style="width: {{ users_site|floatformat:0 }}%; height: 100%; background: #28a745;" title="Site: {{ users_site }}"></div>
<div style="width: {{ users_app|floatformat:0 }}%; height: 100%; background: #007bff;" title="App: {{ users_app }}"></div>
{% endif %}
</div>
<div style="display: flex; justify-content: space-between; margin-top: 5px; font-size: 12px;">
<span>Admin</span>
<span>Site</span>
<span>App</span>
</div>
</div>
</div>
<!-- New User Registrations -->
<div style="background: #f8f9fa; border-radius: 8px; padding: 20px;">
<h4 style="margin: 0 0 15px 0;">New Registrations</h4>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<span>Today:</span>
<div style="padding: 4px 12px; background: #007bff; color: white; border-radius: 15px; font-weight: bold;">{{ users_today }}</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<span>This Week:</span>
<div style="padding: 4px 12px; background: #28a745; color: white; border-radius: 15px; font-weight: bold;">{{ users_this_week }}</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<span>This Month:</span>
<div style="padding: 4px 12px; background: #fd7e14; color: white; border-radius: 15px; font-weight: bold;">{{ users_this_month }}</div>
</div>
</div>
<!-- Recent Users -->
<div style="background: #f8f9fa; border-radius: 8px; padding: 20px; grid-column: span 2;">
<h4 style="margin: 0 0 15px 0;">Recently Registered Users</h4>
<div style="overflow-x: auto;">
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="border-bottom: 2px solid #dee2e6;">
<th style="padding: 8px 12px; text-align: left;">Name</th>
<th style="padding: 8px 12px; text-align: left;">Email</th>
<th style="padding: 8px 12px; text-align: left;">Origin</th>
<th style="padding: 8px 12px; text-align: left;">Date Joined</th>
</tr>
</thead>
<tbody>
{% for user in recent_users %}
<tr style="border-bottom: 1px solid #dee2e6;">
<td style="padding: 8px 12px;">{{ user.first_name }} {{ user.last_name }}</td>
<td style="padding: 8px 12px;">{{ user.email }}</td>
<td style="padding: 8px 12px;">
{% if user.origin == 0 %}
<span style="padding: 2px 6px; background: #6c757d; color: white; border-radius: 4px; font-size: 12px;">Admin</span>
{% elif user.origin == 1 %}
<span style="padding: 2px 6px; background: #28a745; color: white; border-radius: 4px; font-size: 12px;">Site</span>
{% elif user.origin == 2 %}
<span style="padding: 2px 6px; background: #007bff; color: white; border-radius: 4px; font-size: 12px;">App</span>
{% else %}
<span style="padding: 2px 6px; background: #6c757d; color: white; border-radius: 4px; font-size: 12px;">Unknown</span>
{% endif %}
</td>
<td style="padding: 8px 12px;">{{ user.date_joined|date:"M d, Y H:i" }}</td>
</tr>
{% empty %}
<tr>
<td colspan="4" style="padding: 12px; text-align: center;">No recent users found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Purchase Statistics -->
<div class="purchase-section" style="background: white; border: 1px solid #dee2e6; border-radius: 12px; padding: 25px; margin: 20px 0;">
<h3 style="margin: 0 0 20px 0; color: #495057; display: flex; align-items: center; gap: 10px;">
💰 Purchase Statistics
</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;">
<!-- Purchase Counts -->
<div style="background: #f8f9fa; border-radius: 8px; padding: 20px;">
<h4 style="margin: 0 0 15px 0;">Total Purchases: {{ total_purchases }}</h4>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<span>Today:</span>
<div style="padding: 4px 12px; background: #007bff; color: white; border-radius: 15px; font-weight: bold;">{{ purchases_today }}</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<span>This Week:</span>
<div style="padding: 4px 12px; background: #28a745; color: white; border-radius: 15px; font-weight: bold;">{{ purchases_this_week }}</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<span>This Month:</span>
<div style="padding: 4px 12px; background: #fd7e14; color: white; border-radius: 15px; font-weight: bold;">{{ purchases_this_month }}</div>
</div>
</div>
<!-- Recent Purchases -->
<div style="background: #f8f9fa; border-radius: 8px; padding: 20px; grid-column: span 3;">
<h4 style="margin: 0 0 15px 0;">Recent Purchases</h4>
<div style="overflow-x: auto;">
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="border-bottom: 2px solid #dee2e6;">
<th style="padding: 8px 12px; text-align: left;">ID</th>
<th style="padding: 8px 12px; text-align: left;">User</th>
<th style="padding: 8px 12px; text-align: left;">Product</th>
<th style="padding: 8px 12px; text-align: left;">Quantity</th>
<th style="padding: 8px 12px; text-align: left;">Date</th>
</tr>
</thead>
<tbody>
{% for purchase in recent_purchases %}
<tr style="border-bottom: 1px solid #dee2e6;">
<td style="padding: 8px 12px;">{{ purchase.id }}</td>
<td style="padding: 8px 12px;">{{ purchase.user.email }}</td>
<td style="padding: 8px 12px;">{{ purchase.product_id }}</td>
<td style="padding: 8px 12px;">{{ purchase.quantity }}</td>
<td style="padding: 8px 12px;">{{ purchase.purchase_date|date:"M d, Y H:i" }}</td>
</tr>
{% empty %}
<tr>
<td colspan="5" style="padding: 12px; text-align: center;">No recent purchases found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- All Time Overview -->
<div class="all-time-section" style="background: white; border: 1px solid #dee2e6; border-radius: 12px; padding: 25px; margin: 20px 0;">
<h3 style="margin: 0 0 20px 0; color: #495057; display: flex; align-items: center; gap: 10px;">

Loading…
Cancel
Save