1+ '''
2+ # Chrono Des Vignes
3+ # a timing system for sports events
4+ #
5+ # Copyright © 2024-2025 Romain Maurer
6+ # This file is part of Chrono Des Vignes
7+ #
8+ # Chrono Des Vignes is free software: you can redistribute it and/or modify it under
9+ # the terms of the GNU General Public License as published by the Free Software Foundation,
10+ # either version 3 of the License, or (at your option) any later version.
11+ #
12+ # Chrono Des Vignes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13+ # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+ # See the GNU General Public License for more details.
15+ # You should have received a copy of the GNU General Public License along with Foobar.
16+ # If not, see <https://www.gnu.org/licenses/>.
17+ #
18+ # You may contact me at chrono-des-vignes@ikmail.com
19+ '''
20+
121from flask import Blueprint , flash , render_template , redirect , url_for , request , session , send_file
222from chrono_des_vignes import admin_required , db , set_route , socketio
323from chrono_des_vignes .admin .editions .form import Edition_form
@@ -42,7 +62,7 @@ def edition_dossards(event_name, edition_name):
4262 'username' :[DataRequired (), DbLength (User , 'username' )],
4363 'email' :[Optional (), DbLength (User , 'email' ), Email ()]
4464 }
45- ic ('first validation' , form .validate (extra_validators = supp_validators ), form .parcours .data )
65+ # ic('first validation', form.validate(extra_validators=supp_validators), form.parcours.data)
4666 if form .validate (extra_validators = supp_validators ):
4767 # create a new user with the form data and add it to all the parcours
4868 if form .username .data :
@@ -90,7 +110,7 @@ def validate_new_user(event_name, edition_name):
90110 edition : Edition = event .editions .filter_by (name = edition_name ).first_or_404 ()
91111 form = ValidateNewCoureurForm ()
92112 form .parcours .choices = [str ((p .name , p .description )) for p in edition .parcours ]
93- ic (form .parcours .data )
113+ # ic(form.parcours.data)
94114 if form .validate_on_submit ():
95115 user = User .query .get_or_404 (form .user_id .data )
96116
@@ -185,7 +205,7 @@ def export_dossard(event_name, edition_name):
185205
186206 buffer = BytesIO ()
187207
188- workbook = Workbook (buffer )
208+ workbook = Workbook (buffer , { 'default_date_format' : 'dd/mm/yy' } )
189209 worksheet = workbook .add_worksheet ()
190210
191211 headers = [_ ('admin.editions.dossard.dossard' ),
@@ -199,24 +219,32 @@ def export_dossard(event_name, edition_name):
199219 _ ('admin.editions.dossard.edition_date' ),
200220 _ ('admin.editions.dossard.edition_name' ),
201221 _ ('admin.editions.dossard.event_name' )]
222+ col_width = [len (h ) for h in headers ]
223+ get_data = lambda inscription :(inscription .dossard ,
224+ inscription .inscrit .name ,
225+ inscription .inscrit .lastname ,
226+ inscription .inscrit .email ,
227+ inscription .inscrit .phone ,
228+ inscription .inscrit .datenaiss ,
229+ inscription .inscrit .username ,
230+ inscription .parcours .name ,
231+ inscription .edition .edition_date ,
232+ inscription .edition .name ,
233+ inscription .event .name )
202234
203235 row :int
204236 for row , inscription in enumerate (edition .inscriptions .all (), 1 ):
205237 # dossard, name, lastname, email, phone, datenaiss, username, parcours, edition_date, edition_name, event_name
206- worksheet .write (row , 0 , inscription .dossard )
207- worksheet .write (row , 1 , inscription .inscrit .name )
208- worksheet .write (row , 2 , inscription .inscrit .lastname )
209- worksheet .write (row , 3 , inscription .inscrit .email )
210- worksheet .write (row , 4 , inscription .inscrit .phone )
211- worksheet .write (row , 5 , inscription .inscrit .datenaiss )
212- worksheet .write (row , 6 , inscription .inscrit .username )
213- worksheet .write (row , 7 , inscription .parcours .name )
214- worksheet .write (row , 8 , inscription .edition .edition_date )
215- worksheet .write (row , 9 , inscription .edition .name )
216- worksheet .write (row , 10 , inscription .event .name )
238+ line = get_data (inscription )
239+ for col , cell in enumerate (line ):
240+ worksheet .write (row , col , cell )
241+ col_width [col ] = max (col_width [col ], len (str (cell )))
217242
218243 worksheet .add_table (0 ,0 ,max (edition .inscriptions .count (), 1 ),len (headers )- 1 , {'columns' : [{'header' : h } for h in headers ], 'autofilter' : False })
219- worksheet .autofit ()
244+
245+ for col_num , max_length in enumerate (col_width ):
246+ worksheet .set_column (col_num , col_num , max_length + 2 )
247+
220248 workbook .close ()
221249
222250 buffer .seek (0 )
0 commit comments