Raz 9 months ago
commit b9cc725e32
  1. 1
      tournaments/urls.py
  2. 37
      tournaments/views.py

@ -66,5 +66,6 @@ urlpatterns = [
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
path('profile/', views.ProfileUpdateView.as_view(), name='profile'),
path('admin/tournament-import/', views.tournament_import_view, name='tournament_import'),
path('admin/users-export/', views.UserListExportView.as_view(), name='users_export'),
]

@ -11,6 +11,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.contrib.admin.views.decorators import staff_member_required
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.views.generic import View
from tournaments.models.device_token import DeviceToken
@ -883,3 +884,39 @@ def team_details(request, tournament_id, team_id):
'matches': all_matches,
'debug': False # Set to False in production
})
class UserListExportView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
# Get users, excluding those with origin=UserOrigin.SITE, ordered by date_joined
users = CustomUser.objects.exclude(
origin=UserOrigin.SITE
).order_by('date_joined')
# Prepare the response
response = HttpResponse(content_type='text/plain; charset=utf-8')
# Write header
headers = [
'Prenom', 'Nom', 'Club', 'Email', 'Telephone',
'Login', 'Actif', 'Inscription', 'Tournois'
]
response.write('\t'.join(headers) + '\n')
# Write data rows
for user in users:
row = [
str(user.first_name or ''),
str(user.last_name or ''),
str(user.latest_event_club_name() or ''),
str(user.email or ''),
str(user.phone or ''),
str(user.username or ''),
'Oui' if user.is_active else 'Non',
user.date_joined.strftime('%Y-%m-%d %H:%M:%S'),
str(user.event_count())
]
# Replace any tabs or newlines in the data to prevent formatting issues
row = [field.replace('\t', ' ') for field in row]
response.write('\t'.join(row) + '\r\n')
return response

Loading…
Cancel
Save