Update height/weight email and Wellbeing JS

This commit is contained in:
Gregory Trullemans 2023-10-17 10:26:19 +02:00
parent ed9579bf45
commit 3a94fe636f
2 changed files with 65 additions and 11 deletions

View File

@ -98,12 +98,16 @@
<p class="text-muted">(1: Very Low - 10: Very High)</p>
</div>
</div>
<div class="form-group row">
<label class="col-12 text-center text-danger" id="note_info"><b>Merci de mettre une information complémentaire.</b></label>
</div>
<div class="form-group row ">
<label for="id_information" class="col-4 col-sm-2 col-md-4 col-lg-4 col-xl-3 col-form-label">Informations</label>
<label for="id_information" class="col-4 col-sm-2 col-md-4 col-lg-4 col-xl-3 col-form-label">Informations <span class="text-danger" id="span_info_required"><b>*</b></span></label>
<div class="col-8 col-sm-8 col-md-8 col-lg-8 col-xl-9 {% if form.id_information.errors %}has-danger{% endif %}">
{{ form.informations }}
</div>
</div>
<div class="form-group text-center">
<input type="submit" value="{% if mindstate_id %}Save{% else %}Add{% endif %}" class="btn btn-warning" />
</div>
@ -116,15 +120,64 @@
{% block footerscript %}
<script type="text/javascript" >
$(function(){
blackDashboard.initDateTimePicker();
});
$().ready(function(){
// blackDashboard.init.DateTimePicker();
const csrf_token = "{{ csrf_token|escapejs }}";
const gymnast_lookup = "{% url 'gymnast_lookup' %}";
const event_lookup = "{% url 'event_lookup' %}";
$('#id_mindstate').on('change', function(){
if($(this).val() <= 5) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
});
$('#id_sleep').on('change', function(){
if($(this).val() <= 5) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
});
$('#id_stress').on('change', function(){
if($(this).val() >= 5) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
});
$('#id_fatigue').on('change', function(){
if($(this).val() >= 5) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
});
$('#id_muscle_soreness').on('change', function(){
if($(this).val() >= 5) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
});
const csrf_token = "{{ csrf_token|escapejs }}";
const gymnast_lookup = "{% url 'gymnast_lookup' %}";
const event_lookup = "{% url 'event_lookup' %}";
});
</script>
<script src="{% static "js/template_users/datepicker_maxdate_today.js" %}"></script>
{% if request.session.template == 0 %}
<script src="{% static "js/template_users/gymnast_autocomplete_black.js" %}"></script>
<script src="{% static "js/template_users/event_autocomplete_black.js" %}"></script>

View File

@ -1059,9 +1059,10 @@ def heightweight_create_or_update(request, heightweight_id=None, gymnast_id=None
# notification
receiver = []
height = form.cleaned_data["height"]
height = form.cleaned_data["height"] / 100
weight = form.cleaned_data["weight"]
bmi = weight / (height * height)
bmi = format(bmi, ".1f")
gymnast = Gymnast.objects.get(pk=form.cleaned_data["gymnast"].id)
functionality = ContentType.objects.get(model="heightweight")
for notification in gymnast.notifications.filter(
@ -1071,12 +1072,12 @@ def heightweight_create_or_update(request, heightweight_id=None, gymnast_id=None
send_mail(
f"{gymnast} : Nouveau poids/taille enregistré",
f"Un nouveau poids/taille enregistré pour {gymnast} : {height} / {weight} ({bmi}).",
f"Un nouveau poids/taille enregistré pour {gymnast} : {height}cm / {weight}kg ({bmi}).",
settings.EMAIL_HOST_USER,
receiver,
fail_silently=False,
html_message=f"""<p>Bonjour,</p>
<p>Un nouveau poids/taille enregistré pour {gymnast} : {height} / {weight} ({bmi}).</p><br />
<p>Un nouveau poids/taille enregistré pour {gymnast} : {height}cm / {weight}kg ({bmi}).</p><br />
<p>Excellente journée</p><p>Jarvis</p>""",
)