Compare commits
3 Commits
9a54791ce6
...
0eb38b1b77
Author | SHA1 | Date |
---|---|---|
Gregory Trullemans | 0eb38b1b77 | |
Gregory Trullemans | 132a95bdec | |
Gregory Trullemans | 04b4d1e865 |
|
@ -214,14 +214,14 @@
|
|||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<h4>Next skills to learn</h4>
|
||||
<div class="col-6">
|
||||
<h4 class="mb-1">Objectives</h4>
|
||||
{% if plan_list %}
|
||||
<table class="table">
|
||||
{% for plan in plan_list %}
|
||||
<tr>
|
||||
<td class="pt-1 pb-0">{{ plan.educative.short_label }}</td>
|
||||
<td class="pt-1 pb-0">()</td>
|
||||
<td class="pt-1 pb-0">({{ plan.get_learning_step_display }})</td>
|
||||
<td class="pt-1 pb-0">{{ plan.skill.notation }}</td>
|
||||
<td class="pt-1 pb-0">{{ plan.date | date:"j M Y" }}</td>
|
||||
</tr>
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block page_title %}{{ gymnast.first_name }} {{ gymnast.last_name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card mb-0">
|
||||
<div class="card-header">
|
||||
<h3 class="mb-0"><a href="{% url 'gymnast_details_tab' gymnast.id 'scores' %}">{{ gymnast }}</a></h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
Generate report for
|
||||
<select id="select_season">
|
||||
{% for season in season_list %}
|
||||
<option value="{{ season }}" {% if selected_season|stringformat:"s" == season %}selected{% endif %}>{{ season }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span id="week_management"> week
|
||||
<select id="select_week_number">
|
||||
<option value="">---</option>
|
||||
{% for week_number in week_number_list %}
|
||||
<option value="{{ week_number }}">{{ week_number }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</span>
|
||||
|
||||
<span id="span_button_generate">
|
||||
<a href="" id="pdf_link">
|
||||
<button type="button" class="btn btn-icon btn-warning mr-2">
|
||||
<i class="far fa-download"></i>
|
||||
</button>
|
||||
</a>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block footerscript %}
|
||||
<script type="text/javascript">
|
||||
|
||||
$('#span_button_generate').hide();
|
||||
|
||||
$('#select_season').change(function(){
|
||||
var tmp_url = "{% url 'get_distinct_week_number_for_season_and_gymnast' gymnast.id '_season_label_' %}";
|
||||
var season_label = $(this).children("option:selected").val();
|
||||
target_url = tmp_url.replace('_season_label_', season_label);
|
||||
|
||||
$.getJSON(target_url, function(data) {
|
||||
if (!$.trim(data))
|
||||
$('#week_management').hide();
|
||||
else
|
||||
$('#week_management').show();
|
||||
|
||||
$("#select_week_number option").remove(); // Remove all <option> child tags.
|
||||
$.each(data, function(key, value) { // Iterates through a collection
|
||||
$("#select_week_number").append( // Append an object to the inside of the select box
|
||||
$("<option></option>").text(value).val(value)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#select_week_number').change(function(){
|
||||
if ($('#select_week_number').val() != "") {
|
||||
var tmp_url = "{% url 'gymnast_report_export_for_week_number' gymnast.id '_season_label_' 9999 %}";
|
||||
var season_label = $('#select_season').children("option:selected").val();
|
||||
var week_number = $('#select_week_number').children("option:selected").val();
|
||||
target_url = tmp_url.replace('_season_label_', season_label).replace('9999', week_number);
|
||||
$('#pdf_link').attr('href', target_url);
|
||||
$('#span_button_generate').show();
|
||||
} else
|
||||
$('#span_button_generate').hide();
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -52,15 +52,25 @@ gymnast_urlpatterns = [
|
|||
name="gymnast_display_physiological",
|
||||
),
|
||||
path(
|
||||
r"report/<int:gymnast_id>/",
|
||||
views.generate_report,
|
||||
name="gymnast_report_preview",
|
||||
r"report/choice/<int:gymnast_id>/",
|
||||
views.report_choice,
|
||||
name="report_choice",
|
||||
),
|
||||
path(
|
||||
r"pdf/<int:gymnast_id>/",
|
||||
views.generate_gymnast_report,
|
||||
r"report/choice/<int:gymnast_id>/get_distinct_week_number_for_season/<str:season>",
|
||||
views.get_distinct_week_number_for_season_and_gymnast,
|
||||
name="get_distinct_week_number_for_season_and_gymnast",
|
||||
),
|
||||
path(
|
||||
r"report/<int:gymnast_id>/",
|
||||
views.generate_report,
|
||||
name="gymnast_report_export",
|
||||
),
|
||||
path(
|
||||
r"report/<int:gymnast_id>/season/<str:season>/week_number/<int:week_number>/",
|
||||
views.generate_report,
|
||||
name="gymnast_report_export_for_week_number",
|
||||
),
|
||||
path(r"add/", views.gymnast_create_or_update, name="gymnast_create"),
|
||||
path(
|
||||
r"edit/<int:gymnast_id>/", views.gymnast_create_or_update, name="gymnast_update"
|
||||
|
|
|
@ -548,12 +548,148 @@ def analyse_score(value, value_list):
|
|||
return res
|
||||
|
||||
|
||||
def __get_distinct_followup_season_for_gymnast(gymnast_id):
|
||||
"""Recupère les saisons pour lesquelles le gymnastes à des followup."""
|
||||
gymnast = get_object_or_404(Gymnast, pk=gymnast_id)
|
||||
season_list = list(
|
||||
gymnast.chronos.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.accident.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.known_skills.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.todo.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.mindstate.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.number_of_routine_done.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.height_weight.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
season_list += list(
|
||||
gymnast.remarks.values_list("season", flat=True)
|
||||
.distinct("season")
|
||||
.order_by("season")
|
||||
)
|
||||
return list(dict.fromkeys(season_list))
|
||||
|
||||
|
||||
def __get_distinct_week_number_for_season_and_gymnast(gymnast_id, season):
|
||||
"""Récupère les numéro de semaines pour lesquelles le gymnaste à des followup."""
|
||||
gymnast = get_object_or_404(Gymnast, pk=gymnast_id)
|
||||
weeknumber_list = list(
|
||||
gymnast.chronos.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.accident.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.known_skills.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.todo.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.mindstate.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.number_of_routine_done.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.height_weight.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
weeknumber_list += list(
|
||||
gymnast.remarks.values_list("week_number", flat=True)
|
||||
.filter(season=season)
|
||||
.distinct("week_number")
|
||||
.order_by("week_number")
|
||||
)
|
||||
return list(dict.fromkeys(weeknumber_list))
|
||||
|
||||
|
||||
@login_required
|
||||
def get_distinct_week_number_for_season_and_gymnast(gymnast_id, season):
|
||||
""" """
|
||||
if not season:
|
||||
season = Season()
|
||||
|
||||
weeknumber_list = __get_distinct_week_number_for_season_and_gymnast(
|
||||
gymnast_id, season
|
||||
)
|
||||
return JsonResponse(weeknumber_list, safe=False)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET"])
|
||||
def report_choice(request, gymnast_id):
|
||||
"""Recupère les saisons pour lesquelles le gymnastes à des followup."""
|
||||
gymnast = get_object_or_404(Gymnast, pk=gymnast_id)
|
||||
|
||||
today = pendulum.now().date()
|
||||
season, week_number = from_date_to_week_number(today)
|
||||
|
||||
season_list = __get_distinct_followup_season_for_gymnast(gymnast_id)
|
||||
week_number_list = sorted(
|
||||
__get_distinct_week_number_for_season_and_gymnast(gymnast_id, season)
|
||||
)
|
||||
context = {
|
||||
"gymnast": gymnast,
|
||||
"season": season,
|
||||
"season_list": season_list,
|
||||
"week_number": week_number,
|
||||
"week_number_list": week_number_list,
|
||||
}
|
||||
return render(request, "people/gymnasts/report_choices.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET"])
|
||||
def generate_report(request, gymnast_id):
|
||||
gymnast = get_object_or_404(Gymnast, pk=gymnast_id)
|
||||
today = pendulum.now().date()
|
||||
season, week_number = from_date_to_week_number(today)
|
||||
# season = Season()
|
||||
|
||||
#
|
||||
# PHYSIOLOGICAL INFORMATIONS
|
||||
|
@ -712,6 +848,8 @@ def generate_report(request, gymnast_id):
|
|||
"notes": notes,
|
||||
}
|
||||
|
||||
# return render(request, "people/gymnasts/report.html", context)
|
||||
|
||||
response = HttpResponse(content_type="application/pdf")
|
||||
response[
|
||||
"Content-Disposition"
|
||||
|
@ -723,7 +861,7 @@ def generate_report(request, gymnast_id):
|
|||
html = render_to_string("people/gymnasts/report.html", context)
|
||||
|
||||
# font_config = FontConfiguration()
|
||||
HTML(string=html).write_pdf(
|
||||
HTML(string=html, base_url=request.build_absolute_uri()).write_pdf(
|
||||
response,
|
||||
stylesheets=[
|
||||
CSS(settings.STATICFILES_DIRS[0] + "/css/gymnast_report.css"),
|
||||
|
|
Loading…
Reference in New Issue