Add form for stability
This commit is contained in:
parent
2bb2fb55eb
commit
175e1e42a1
|
@ -7,10 +7,10 @@
|
|||
<div class="col-12 col-sm-12 col-md-8 col-lg-8 col-xl-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="">{% if injury_id %}Edit{% else %}Add{% endif %} injury</h4>
|
||||
<h4 class="">{% if stability_id %}Edit{% else %}Add{% endif %} stability</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{% if injury_id %}{% url 'injury_update' injury_id %}{% else %}{% url 'injury_create' %}{% endif %}" method="post" class="form-horizontal" id="formulaire" name="formulaire">
|
||||
<form action="{% if stability_id %}{% url 'stability_update' stability_id %}{% else %}{% url 'stability_create' %}{% endif %}" method="post" class="form-horizontal" id="formulaire" name="formulaire">
|
||||
{% csrf_token %}
|
||||
<div class="form-group row ">
|
||||
<label for="id_date" class="col-4 col-sm-3 col-form-label">Gymnast <span class="text-danger"><b>*</b></span></label>
|
||||
|
@ -33,62 +33,47 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_skill" class="col-4 col-sm-3 col-form-label">Skill</label>
|
||||
<div class="col-sm-8 col-md-6 col-lg-6 col-xl-6 {% if form.skill.errors %}has-danger{% endif %}">
|
||||
{{ form.skill }}
|
||||
{{ form.skill_related }}
|
||||
{% if form.skill.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.skill.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
<label for="id_anterior_chain" class="col-4 col-sm-3 col-form-label">{{ form.anterior_chain.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-2 col-lg-2 col-xl-2 {% if form.anterior_chain.errors %}has-danger{% endif %}">
|
||||
{{ form.anterior_chain }}
|
||||
{% if form.anterior_chain.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.anterior_chain.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_injury_type" class="col-4 col-sm-3 col-form-label">{{ form.injury_type.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8 {% if form.injury_type.errors %}has-danger{% endif %}">
|
||||
{{ form.injury_type }}
|
||||
{% if form.injury_type.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.injury_type.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
<label for="id_posterior_chain_left" class="col-4 col-sm-3 col-form-label">{{ form.posterior_chain_left.label }} <span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-2 col-lg-2 col-xl-2 {% if form.posterior_chain_left.errors %}has-danger{% endif %}">
|
||||
{{ form.posterior_chain_left }}
|
||||
{% if form.posterior_chain_left.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.posterior_chain_left.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_mechanism" class="col-4 col-sm-3 col-form-label">{{ form.mechanism.label }} <span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-4 col-lg-4 col-xl-4 {% if form.mechanism.errors %}has-danger{% endif %}">
|
||||
{{ form.mechanism }}
|
||||
{% if form.mechanism.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.mechanism.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
<label for="id_posterior_chain_right" class="col-4 col-sm-3 col-form-label">{{ form.posterior_chain_right.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-2 col-lg-2 col-xl-2 {% if form.posterior_chain_right.errors %}has-danger{% endif %}">
|
||||
{{ form.posterior_chain_right }}
|
||||
{% if form.posterior_chain_right.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.posterior_chain_right.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_location" class="col-4 col-sm-3 col-form-label">{{ form.location.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-sm-8 col-md-6 col-lg-6 col-xl-6 {% if form.location.errors %}has-danger{% endif %}">
|
||||
{{ form.location }}
|
||||
{% if form.location.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.location.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
<label for="id_leg_lowering" class="col-4 col-sm-3 col-form-label">{{ form.leg_lowering.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-4 col-lg-4 col-xl-4 {% if form.leg_lowering.errors %}has-danger{% endif %}">
|
||||
{{ form.leg_lowering }}
|
||||
{% if form.leg_lowering.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.leg_lowering.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_body_side" class="col-4 col-sm-3 col-form-label">{{ form.body_side.label }}<span class="text-danger"><b>*</b></span></label>
|
||||
<div class="col-5 col-sm-3 col-md-4 col-lg-4 col-xl-4 {% if form.body_side.errors %}has-danger{% endif %}">
|
||||
{{ form.body_side }}
|
||||
{% if form.body_side.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.body_side.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
<label for="id_sl_bridge" class="col-4 col-sm-3 col-form-label">{{ form.sl_bridge.label }}</label>
|
||||
<div class="col-sm-9 col-md-9 col-lg-9 col-xl-9 {% if form.sl_bridge.errors %}has-danger{% endif %}">
|
||||
{{ form.sl_bridge }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_diagnosis" class="col-4 col-sm-3 col-form-label">{{ form.diagnosis.label }}</label>
|
||||
<div class="col-sm-9 col-md-9 col-lg-9 col-xl-9 {% if form.id_diagnosis.errors %}has-danger{% endif %}">
|
||||
{{ form.diagnosis }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_nb_week_off" class="col-4 col-sm-3 col-form-label"># Week off</label>
|
||||
<div class="col-sm-3 col-md-4 col-lg-2 {% if form.nb_week_off.errors %}has-danger{% endif %}">
|
||||
{{ form.nb_week_off }}
|
||||
{% if form.nb_week_off.errors %} <span class="btn btn-sm btn-danger-outline">{% for error in form.nb_week_off.errors %}{{ error }}{% endfor %}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row ">
|
||||
<label for="id_information" class="col-4 col-sm-3 col-form-label">Informations</label>
|
||||
<div class="col-sm-9 col-md-9 col-lg-9 col-xl-9 {% if form.id_informations.errors %}has-danger{% endif %}">
|
||||
{{ form.informations }}
|
||||
<label for="id_side_plank_leg_raise" class="col-4 col-sm-3 col-form-label">{{ form.side_plank_leg_raise.label }}</label>
|
||||
<div class="col-sm-9 col-md-9 col-lg-9 col-xl-9 {% if form.side_plank_leg_raise.errors %}has-danger{% endif %}">
|
||||
{{ form.side_plank_leg_raise }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group text-center">
|
||||
<input type="submit" value="{% if injury_id %}Save{% else %}Add{% endif %}" class="btn btn-warning" />
|
||||
<input type="submit" value="{% if stability_id %}Save{% else %}Add{% endif %}" class="btn btn-warning" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -50,6 +50,11 @@
|
|||
<i class="tim-icons icon-double-left"></i>
|
||||
</button>
|
||||
</a>
|
||||
<a href="{% url 'stability_create_for_gymnast' stability.gymnast.id %}">
|
||||
<button type="submit" value="add" class="btn btn-icon btn-warning ">
|
||||
+
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
</div>
|
||||
<div class="col-1 ml-auto">
|
||||
<div class="text-right">
|
||||
<a href="{% url 'injury_create' %}">
|
||||
<button type="submit" value="add" class="btn btn-icon btn-warning ">
|
||||
<a href="{% url 'stability_create' %}">
|
||||
<button type="submit" value="add" class="btn btn-icon btn-warning">
|
||||
<i class="fas fa-plus"></i>
|
||||
</button>
|
||||
</a>
|
||||
|
|
|
@ -294,6 +294,7 @@ class StabilityAdmin(admin.ModelAdmin):
|
|||
model = Stability
|
||||
|
||||
list_display = (
|
||||
"date",
|
||||
"gymnast",
|
||||
"anterior_chain",
|
||||
"posterior_chain_left",
|
||||
|
|
|
@ -9,6 +9,7 @@ from .models import (
|
|||
Chrono,
|
||||
Injury,
|
||||
WellBeing,
|
||||
Stability,
|
||||
HeightWeight,
|
||||
LearnedSkill,
|
||||
GymnastHasRoutine,
|
||||
|
@ -248,6 +249,69 @@ class InjuryForm(forms.ModelForm):
|
|||
)
|
||||
|
||||
|
||||
class StabilityForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Stability
|
||||
fields = (
|
||||
"gymnast",
|
||||
"date",
|
||||
"anterior_chain",
|
||||
"posterior_chain_left",
|
||||
"posterior_chain_right",
|
||||
"leg_lowering",
|
||||
"sl_bridge",
|
||||
"side_plank_leg_raise",
|
||||
)
|
||||
widgets = {
|
||||
"date": forms.DateInput(
|
||||
attrs={
|
||||
"class": "form-control datepicker",
|
||||
"placeholder": date.today().strftime("%Y-%m-%d"),
|
||||
"value": date.today().strftime("%Y-%m-%d"),
|
||||
}
|
||||
),
|
||||
"gymnast": forms.HiddenInput(),
|
||||
"anterior_chain": forms.NumberInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
"placeholder": "x",
|
||||
"min": "0",
|
||||
"max": "3",
|
||||
}
|
||||
),
|
||||
"posterior_chain_left": forms.NumberInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
"placeholder": "x",
|
||||
"min": "0",
|
||||
"max": "3",
|
||||
}
|
||||
),
|
||||
"posterior_chain_right": forms.NumberInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
"placeholder": "x",
|
||||
"min": "0",
|
||||
"max": "3",
|
||||
}
|
||||
),
|
||||
"leg_lowering": forms.Select(attrs={"class": "selectpicker"}),
|
||||
"sl_bridge": forms.SelectMultiple(attrs={"class": "selectpicker"}),
|
||||
"side_plank_leg_raise": forms.SelectMultiple(attrs={"class": "selectpicker"}),
|
||||
}
|
||||
|
||||
gymnast_related = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
"placeholder": "Searching gymnast…",
|
||||
"data-ref": "#id_gymnast",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class WellBeingForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = WellBeing
|
||||
|
|
|
@ -95,12 +95,12 @@ urlpatterns = [
|
|||
path(r"stability/", views.stability_listing, name="stability_list"),
|
||||
path(r"stability/gymnast/<int:gymnast_id>/", views.stability_listing, name="stability_list"),
|
||||
# path(r"stability/search/", views.injury_listing, name="stability_search"),
|
||||
# path(r"stability/add/", views.injury_create_or_update, name="stability_create"),
|
||||
# path(
|
||||
# r"stability/add/<int:gymnast_id>/",
|
||||
# views.injury_create_or_update,
|
||||
# name="injury_create_for_gymnast",
|
||||
# ),
|
||||
path(r"stability/add/", views.stability_create_or_update, name="stability_create"),
|
||||
path(
|
||||
r"stability/add/<int:gymnast_id>/",
|
||||
views.stability_create_or_update,
|
||||
name="stability_create_for_gymnast",
|
||||
),
|
||||
# path(
|
||||
# r"stability/edit/<int:injury_id>/",
|
||||
# views.injury_create_or_update,
|
||||
|
|
|
@ -31,6 +31,7 @@ from .forms import (
|
|||
ScoreForm,
|
||||
ChronoForm,
|
||||
InjuryForm,
|
||||
StabilityForm,
|
||||
WellBeingForm,
|
||||
HeightWeightForm,
|
||||
LearnedSkillForm,
|
||||
|
@ -778,3 +779,37 @@ def stability_detail(request, stability_id):
|
|||
"stability_side_plank_leg_raise": stability_side_plank_leg_raise
|
||||
}
|
||||
return render(request, "followup/stabilities/details.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def stability_create_or_update(request, stability_id=None, gymnast_id=None):
|
||||
"""
|
||||
Récupère toutes les informations d'une stability.
|
||||
"""
|
||||
if stability_id:
|
||||
stability = get_object_or_404(Stability, pk=stability_id)
|
||||
data = {
|
||||
"gymnast_related": stability.gymnast,
|
||||
}
|
||||
else:
|
||||
stability = None
|
||||
data = None
|
||||
if gymnast_id is not None:
|
||||
gymnast = get_object_or_404(Gymnast, pk=gymnast_id)
|
||||
data = {"gymnast": gymnast_id, "gymnast_related": str(gymnast)}
|
||||
|
||||
if request.method == "POST":
|
||||
form = StabilityForm(request.POST, instance=stability)
|
||||
|
||||
if form.is_valid():
|
||||
stability = form.save()
|
||||
return HttpResponseRedirect(
|
||||
reverse("stability_details", args=(stability.pk,))
|
||||
)
|
||||
else:
|
||||
return render(request, "followup/stabilities/create.html", {"form": form})
|
||||
|
||||
form = StabilityForm(instance=stability, initial=data)
|
||||
context = {"form": form, "stability_id": stability_id}
|
||||
return render(request, "followup/stabilities/create.html", context)
|
||||
|
|
Loading…
Reference in New Issue