Skip to content

Commit a56bd8d

Browse files
31.03.2025_upgrade documentation + fix bug
1 parent c874673 commit a56bd8d

43 files changed

Lines changed: 1202 additions & 615 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chrono_des_vignes/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
from_addr= os.getenv('from_addr')
8484
mail_token= os.getenv('mail_token')
8585
to_addrs= json.loads(os.getenv('to_addrs'))
86-
ic(mail_host, from_addr, mail_token, to_addrs)
86+
#ic(mail_host, from_addr, mail_token, to_addrs)
8787

8888
class MailFormatter(logging.Formatter):
8989
def format(self, record):
@@ -142,6 +142,7 @@ def format(self, record):
142142
@babel.localeselector
143143
def get_locale():
144144
# if a user is logged in, use the locale from the user settings
145+
#ic(session.get('lang'), request.accept_languages.best_match(LANGAGES))
145146
if session.get('lang') :
146147
return session['lang']
147148
# otherwise try to guess the language from the user accept
@@ -190,8 +191,10 @@ def decorator(func):
190191
@blueprint.route(path, **options)
191192
@wraps(func)
192193
def wrap(*args, **kwargs):
193-
lang = kwargs.pop('lang', 'fr')
194+
lang = kwargs.pop('lang', None)
194195
#ic('hey', lang, path, func.__name__)
196+
if lang == None:
197+
lang = request.accept_languages.best_match(LANGAGES)
195198
if lang not in LANGAGES:
196199
return abort(404)
197200
session['lang'] = lang

chrono_des_vignes/admin/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ def new_event():
5252

5353
user = current_user
5454
form = NewEventForm()
55-
ic('coucou')
55+
#ic('coucou')
5656

5757
if form.validate_on_submit():
5858
name=form.name.data
59-
ic(name)
59+
#ic(name)
6060

6161
event = Event(name=name, createur_id=user.id)
6262
db.session.add(event)
6363
db.session.commit()
6464

6565
return redirect(url_for('admin.home_event', event_name=event.name))
6666
else:
67-
ic(form.errors)
67+
#ic(form.errors)
6868
for error in form.name.errors:
6969
flash(error, 'danger')
7070
return redirect(url_for('home'))

chrono_des_vignes/admin/coureurs/templates/coureurs.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
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+
121
{% extends 'layout.html' %}
222
{% block content %}
323
<h3>{{ _('admin.view.coureurs') }}</h3>

chrono_des_vignes/admin/coureurs/templates/view_coureur.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
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+
121
{% extends 'layout.html' %} {% block content %}
222
<div>
323
<h3>{{ _('admin.view.info') }}</h3>
@@ -68,7 +88,7 @@ <h3>{{ _('admin.view.info') }}</h3>
6888
</div>
6989
<div>
7090
<h3>{{ _('admin.view.participation') }}</h3>
71-
<table class="table">
91+
<table class="table clickable-table">
7292
<thead>
7393
<tr>
7494
<th scope="col">{{ _('admin.view.parcours') }}</th>
@@ -80,16 +100,21 @@ <h3>{{ _('admin.view.participation') }}</h3>
80100
</thead>
81101
<tbody>
82102
{% for inscription in inscriptions %}
83-
<tr>
103+
<tr data-href="{{ url_for('livetrack.livetrack_page', inscription_id=inscription.id) }}">
84104
<th>{{inscription.parcours.name}}</th>
85105
<th>{{inscription.edition.name}}</th>
86106
<th>{{inscription.edition.edition_date.strftime('%d.%m.%Y')}}</th>
87107
<th>{% if inscription.dossard %}{{inscription.dossard}}{% endif %}</th>
88-
<th>{% if inscription.end=='finish' %}{{inscription.rank}}{% endif %}</th>
108+
<th>{{inscription.rank if inscription.end=='finish' else inscription.status}}</th>
89109
</tr>
90110
{% endfor %}
91111
</tbody>
92112
</table>
113+
<script>
114+
$('table tbody tr').on('click', function() {
115+
window.location.href = $(this).data('href');
116+
});
117+
</script>
93118
</div>
94119
</div>
95120
{% endblock content %}

chrono_des_vignes/admin/editions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def modify_edition_page(event_name, edition_name):
122122
#? fin desactivation des champs
123123

124124
if form.validate_on_submit():
125-
ic(edition.rdv_lat, form.rdv_lat.data, edition.rdv_lng, form.rdv_lng.data)
125+
#ic(edition.rdv_lat, form.rdv_lat.data, edition.rdv_lng, form.rdv_lng.data)
126126
if form.name.data == edition.name or not event.editions.filter_by(name=form.name.data).first():
127127
edition.name = form.name.data
128128
edition.edition_date = form.edition_date.data

chrono_des_vignes/admin/editions/dossard/__init__.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
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+
121
from flask import Blueprint, flash, render_template, redirect, url_for, request, session, send_file
222
from chrono_des_vignes import admin_required, db, set_route, socketio
323
from 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)

chrono_des_vignes/admin/editions/dossard/templates/dossard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<script>
6464
var socket = io('/dossard', {auth:{'event_id': {{ event_data.id }}, 'edition_id': {{ edition_data.id }} } })
6565
function change_dossard(inscription_id){
66-
console.log(inscription_id)
66+
//console.log(inscription_id)
6767
let new_dossard = parseInt(window.prompt('enter the new dossard number'))
6868
if (new_dossard){
6969
socket.emit('change_dossard', {'inscription_id':inscription_id, 'new_dossard':new_dossard},

chrono_des_vignes/admin/editions/parcours/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def parcours_connect(auth):
4343
join_room(session['room'], request.sid)
4444
else:
4545
return False # connection not allowed
46+
4647
@socketio.on('disconnect', namespace='/edition/parcours')
4748
def parcours_disconnect():
4849
leave_room(session['room'], request.sid)
@@ -66,6 +67,7 @@ def get_parcours_passages(parcours_id):
6667
for stand, dist in zip(coureur.parcours.iter_chrono_list(), coureur.parcours.get_chrono_dists()):
6768
pass_data['parcours'].append({'stand':{'name':stand.name}, 'dist':round(dist, 3), 'delta':'', 'success':None})
6869
data.append(pass_data)
70+
#print(data)
6971
return data
7072

7173
@socketio.on('launch_parcours', namespace='/edition/parcours')
@@ -74,12 +76,12 @@ def launch_parcours(data):
7476
edition = Edition.query.get(session['room'].split('-')[3])
7577
if parcours is not None and data.get('start_time'):
7678
start_time =datetime.fromtimestamp(data['start_time']/1000)
77-
ic('start', start_time)
79+
#ic('start', start_time)
7880
inscription:Inscription
7981
for inscription in edition.inscriptions.filter(Inscription.parcours==parcours).all():
80-
ic(inscription, inscription.has_started(), inscription.present)
82+
#ic(inscription, inscription.has_started(), inscription.present, inscription.end)
8183
if not inscription.has_started() and inscription.present:
82-
ic('to start')
84+
#ic('to start')
8385
passage = Passage(time_stamp=start_time, inscription_id = inscription.id)
8486
db.session.add(passage)
8587
db.session.commit()
@@ -130,6 +132,7 @@ def stop_parcours(data):
130132
def disqualify(data):
131133
if data.get('inscription_id'):
132134
inscription = Inscription.query.get(data.get('inscription_id'))
135+
#ic('disqualify', inscription)
133136
if inscription.end is None:
134137
inscription.end = 'disqual'
135138
db.session.commit()
@@ -139,16 +142,18 @@ def disqualify(data):
139142
def abandon(data):
140143
if data.get('inscription_id'):
141144
inscription = Inscription.query.get(data['inscription_id'])
145+
#ic('abandon', inscription)
142146
if inscription.end is None:
143147
inscription.end = 'abandon'
144148
db.session.commit()
145149
emit('stop', {'type':'abandon', 'inscription_id':inscription.id}, namespace='/edition/parcours', to=f'edition-parcours-{inscription.event.id}-{inscription.edition.id}')
146150

147151
@socketio.on('finish', namespace='/edition/parcours')
148152
def finish(data):
149-
ic('finish', data)
153+
#ic('finish', data)
150154
if data.get('inscription_id'):
151155
inscription:Inscription = Inscription.query.get(data['inscription_id'])
156+
#ic('finish', inscription)
152157
if inscription.end is None:
153158
inscription.end = 'finish'
154159
db.session.commit()

0 commit comments

Comments
 (0)