Implement theoretical max
This commit is contained in:
parent
359f4e6fab
commit
f9ba5b9444
15 changed files with 194 additions and 29 deletions
2
Pipfile
2
Pipfile
|
@ -7,7 +7,7 @@ name = "pypi"
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
|
|
||||||
django = "*"
|
Django = "*"
|
||||||
djangorestframework = "*"
|
djangorestframework = "*"
|
||||||
"django-bootstrap4" = "*"
|
"django-bootstrap4" = "*"
|
||||||
|
|
||||||
|
|
2
Pipfile.lock
generated
2
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "c3ee9bacf90669123493994e4f194606cd953134dd819c73684629335c5a7ee6"
|
"sha256": "236f27f0ee84bf5dfc608ea235c7edb929fd32228bc5e98b7f269cc52d0fc312"
|
||||||
},
|
},
|
||||||
"host-environment-markers": {
|
"host-environment-markers": {
|
||||||
"implementation_name": "cpython",
|
"implementation_name": "cpython",
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Equipment(models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_theoretical_max(self):
|
def last_theoretical_max(self):
|
||||||
return self.theoretical_maxs.order_by('-date').first()
|
return self.theoretical_maxs.order_by('-date', '-pk').first()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.name} ({self.room.name})'
|
return f'{self.name} ({self.room.name})'
|
||||||
|
@ -70,7 +70,7 @@ class TheoreticalMax(models.Model):
|
||||||
value = models.FloatField('valeur')
|
value = models.FloatField('valeur')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.value}kg le {self.date}'
|
return f'{self.value} le {self.date}'
|
||||||
|
|
||||||
|
|
||||||
class Session(models.Model):
|
class Session(models.Model):
|
||||||
|
@ -88,6 +88,9 @@ class Session(models.Model):
|
||||||
)
|
)
|
||||||
notes = models.TextField('notes', blank=True)
|
notes = models.TextField('notes', blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.room} {self.start:%d/%m/%Y %H:%M}'
|
||||||
|
|
||||||
|
|
||||||
class Round(models.Model):
|
class Round(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
8
gym/static/gym/round.js
Normal file
8
gym/static/gym/round.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
$(document).ready(function () {
|
||||||
|
console.log(max_theorique);
|
||||||
|
$('#id_theoretical_max_percentage').change(function(event) {
|
||||||
|
console.log(event);
|
||||||
|
var proposed_weight = max_theorique / 100 * Number($('#id_theoretical_max_percentage').val());
|
||||||
|
$('#id_chosen_weight').val(proposed_weight);
|
||||||
|
})
|
||||||
|
});
|
|
@ -33,5 +33,8 @@
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
|
||||||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,4 +1,5 @@
|
||||||
{% extends 'gym/base.html' %}
|
{% extends 'gym/base.html' %}
|
||||||
|
{% load humanize %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -8,25 +9,51 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<a href="{% url 'room-detail' equipment.room.pk %}"
|
|
||||||
class="btn btn-secondary">Retourner à la salle</a>
|
|
||||||
<a href="{% url 'setting-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-success">Ajouter un réglage</a>
|
|
||||||
{% if session %}
|
{% if session %}
|
||||||
<a href="{% url 'round-create' %}?equipment={{ equipment.pk }}&session={{ session.pk }}"
|
<a href="{% url 'session-detail' session %}"
|
||||||
class="btn btn-success">Commencer une série</a>
|
class="btn btn-secondary">Retour à la séance</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'room-detail' equipment.room.pk %}"
|
||||||
|
class="btn btn-secondary">Retourner à la salle</a>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{% url 'setting-create' %}?equipment={{ equipment.pk }}{% if session %}&session={{ session }}{% endif %}"
|
||||||
|
class="btn btn-success">Ajouter un réglage</a>
|
||||||
|
<a href="{% url 'theoretical-max-create' %}?equipment={{ equipment.pk }}{% if session %}&session={{ session }}{% endif %}"
|
||||||
|
class="btn btn-success">Ajouter un max théorique</a>
|
||||||
|
{% if session %}
|
||||||
|
<a href="{% url 'round-create' %}?equipment={{ equipment.pk }}&session={{ session }}"
|
||||||
|
class="btn btn-primary">Commencer une série</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>Max théorique</h2>
|
||||||
|
{% if equipment.last_theoretical_max %}
|
||||||
|
<ul class="list-group">
|
||||||
|
<li class="list-group-item">
|
||||||
|
{{ equipment.last_theoretical_max }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>Pas de max théorique pour le moment.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<h2>Réglages</h2>
|
<h2>Réglages</h2>
|
||||||
<ul class="list-group">
|
{% if equipment.settings.all %}
|
||||||
{% for setting in equipment.settings.all %}
|
<ul class="list-group">
|
||||||
<a href="{% url 'setting-edit' setting.pk %}" class="list-group-item">{{ setting.name }}
|
{% for setting in equipment.settings.all %}
|
||||||
: {{ setting.value }}</a>
|
<a href="{% url 'setting-edit' setting.pk %}?session={{ session }}"
|
||||||
{% endfor %}
|
class="list-group-item">{{ setting.name }}
|
||||||
</ul>
|
: {{ setting.value }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>Pas de réglage pour le moment.</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -7,6 +7,11 @@
|
||||||
<h1>{% block title %}Ajouter une machine{% endblock %}</h1>
|
<h1>{% block title %}Ajouter une machine{% endblock %}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<a href="{% url 'room-detail' room.pk %}" class="btn btn-secondary">Retourner à la salle</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if room.sessions.all %}
|
{% if sessions %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<h2>Séances</h2>
|
<h2>Séances</h2>
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for session in room.sessions.all %}
|
{% for session in sessions %}
|
||||||
<a href="{% url 'session-detail' session.pk %}" class="list-group-item">{{ session.start }}</a>
|
<a href="{% url 'session-detail' session.pk %}" class="list-group-item">{{ session.start }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends 'gym/base.html' %}
|
{% extends 'gym/base.html' %}
|
||||||
{% load bootstrap4 %}
|
{% load bootstrap4 %}
|
||||||
|
{% load static %}
|
||||||
|
{% load l10n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -10,7 +12,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
{% if equipment %}
|
{% if equipment %}
|
||||||
<a href="{% url 'equipment-detail' equipment.pk %}" class="btn btn-secondary">Retourner à la machine</a>
|
<a href="{% url 'equipment-detail' equipment.pk %}?session={{ session.pk }}" class="btn btn-secondary">Retourner à la machine</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,3 +31,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>var max_theorique = {% localize off %}{{ equipment.last_theoretical_max.value }}{% endlocalize %};</script>
|
||||||
|
<script src="{% static 'gym/round.js' %}"></script>
|
||||||
|
{% endblock %}
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<a href="{% url 'room-detail' session.room.pk %}" class="btn btn-secondary">Retourner à la salle</a>
|
<a href="{% url 'room-detail' session.room.pk %}" class="btn btn-secondary">Retourner à la salle</a>
|
||||||
<a href="{% url 'equipment-create' %}?room={{ room.pk }}" class="btn btn-success">Ajouter une machine</a>
|
<a href="{% url 'equipment-create' %}?room={{ session.room.pk }}&session={{ session.pk }}" class="btn btn-success">Ajouter une machine</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -39,4 +39,14 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>Séries</h2>
|
||||||
|
<ul class="list-group">
|
||||||
|
{% for round in session.rounds.all %}
|
||||||
|
<a href="#" class="list-group-item">{{ round.equipment.name }} – {{ round.repetition_number }} répétitions × {{ round.chosen_weight }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
{% if equipment %}
|
{% if equipment %}
|
||||||
<a href="{% url 'equipment-detail' equipment.pk %}" class="btn btn-secondary">Retourner à la machine</a>
|
<a href="{% url 'equipment-detail' equipment.pk %}{% if session %}?session={{ session }}{% endif %}" class="btn btn-secondary">Retourner à la machine</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
31
gym/templates/gym/theoretical_max_edit.html
Normal file
31
gym/templates/gym/theoretical_max_edit.html
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{% extends 'gym/base.html' %}
|
||||||
|
{% load bootstrap4 %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1>{% block title %}{{ title }} un max théorique{% endblock %}</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
{% if equipment %}
|
||||||
|
<a href="{% url 'equipment-detail' equipment.pk %}{% if session %}?session={{ session }}{% endif %}" class="btn btn-secondary">Retourner à la machine</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
{% buttons %}
|
||||||
|
<button type="submit" class="btn btn-success">Valider</button>
|
||||||
|
{% if edit %}
|
||||||
|
<a href="{% url 'theoretical-max-delete' setting.pk %}" class="btn btn-danger">Supprimer</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endbuttons %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -15,6 +15,7 @@ urlpatterns = [
|
||||||
path('session/start/', views.SessionCreateView.as_view(), name='session-start'),
|
path('session/start/', views.SessionCreateView.as_view(), name='session-start'),
|
||||||
path('session/<int:pk>/', views.SessionDetailView.as_view(), name='session-detail'),
|
path('session/<int:pk>/', views.SessionDetailView.as_view(), name='session-detail'),
|
||||||
path('round/add/', views.RoundCreateView.as_view(), name='round-create'),
|
path('round/add/', views.RoundCreateView.as_view(), name='round-create'),
|
||||||
|
path('theoretical-max/add/', views.TheoreticalMaxCreateView.as_view(), name='theoretical-max-create'),
|
||||||
# path('session/<int:pk>/delete', views.SessionDeleteView.as_view(), name='session-delete'),
|
# path('session/<int:pk>/delete', views.SessionDeleteView.as_view(), name='session-delete'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
84
gym/views.py
84
gym/views.py
|
@ -4,7 +4,7 @@ from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
from gym.models import Room, Equipment, Setting, Session, Round
|
from gym.models import Room, Equipment, Setting, Session, Round, TheoreticalMax
|
||||||
|
|
||||||
|
|
||||||
class RoomListView(generic.ListView):
|
class RoomListView(generic.ListView):
|
||||||
|
@ -18,6 +18,11 @@ class RoomDetailView(generic.DetailView):
|
||||||
context_object_name = 'room'
|
context_object_name = 'room'
|
||||||
template_name = 'gym/room.html'
|
template_name = 'gym/room.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['sessions'] = self.object.sessions.all().order_by('-start')
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class EquipmentDetailView(generic.DetailView):
|
class EquipmentDetailView(generic.DetailView):
|
||||||
model = Equipment
|
model = Equipment
|
||||||
|
@ -26,9 +31,7 @@ class EquipmentDetailView(generic.DetailView):
|
||||||
session = None
|
session = None
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
default_session_id = self.request.GET.get('session')
|
self.session = self.request.GET.get('session')
|
||||||
if default_session_id:
|
|
||||||
self.session = get_object_or_404(Room, pk=default_session_id)
|
|
||||||
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -43,15 +46,26 @@ class EquipmentCreateView(generic.CreateView):
|
||||||
fields = ['room', 'name']
|
fields = ['room', 'name']
|
||||||
template_name = 'gym/equipment_edit.html'
|
template_name = 'gym/equipment_edit.html'
|
||||||
room = None
|
room = None
|
||||||
|
session = None
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['room'] = self.room
|
||||||
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('equipment-detail', kwargs={'pk': self.object.pk})
|
url = reverse('equipment-detail', kwargs={'pk': self.object.pk})
|
||||||
|
if self.session:
|
||||||
|
return "{}?session={}".format(url, self.session)
|
||||||
|
return url
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
default_room_id = self.request.GET.get('room')
|
default_room_id = self.request.GET.get('room')
|
||||||
if default_room_id:
|
if default_room_id:
|
||||||
self.room = get_object_or_404(Room, pk=default_room_id)
|
self.room = get_object_or_404(Room, pk=default_room_id)
|
||||||
|
|
||||||
|
self.session = self.request.GET.get('session')
|
||||||
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
@ -66,11 +80,13 @@ class SettingCreateView(generic.CreateView):
|
||||||
fields = ['equipment', 'name', 'value']
|
fields = ['equipment', 'name', 'value']
|
||||||
template_name = 'gym/setting_edit.html'
|
template_name = 'gym/setting_edit.html'
|
||||||
equipment = None
|
equipment = None
|
||||||
|
session = None
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['title'] = 'Ajouter'
|
context['title'] = 'Ajouter'
|
||||||
context['equipment'] = self.equipment
|
context['equipment'] = self.equipment
|
||||||
|
context['session'] = self.session
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
@ -78,6 +94,8 @@ class SettingCreateView(generic.CreateView):
|
||||||
if default_equipment_id:
|
if default_equipment_id:
|
||||||
self.equipment = get_object_or_404(Equipment, pk=default_equipment_id)
|
self.equipment = get_object_or_404(Equipment, pk=default_equipment_id)
|
||||||
|
|
||||||
|
self.session = self.request.GET.get('session')
|
||||||
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
@ -87,23 +105,36 @@ class SettingCreateView(generic.CreateView):
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
url = reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
||||||
|
if self.session:
|
||||||
|
return '{}?session={}'.format(url, self.session)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class SettingUpdateView(generic.UpdateView):
|
class SettingUpdateView(generic.UpdateView):
|
||||||
model = Setting
|
model = Setting
|
||||||
fields = ['equipment', 'name', 'value']
|
fields = ['equipment', 'name', 'value']
|
||||||
template_name = 'gym/setting_edit.html'
|
template_name = 'gym/setting_edit.html'
|
||||||
|
session = None
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
self.session = self.request.GET.get('session')
|
||||||
|
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['edit'] = True
|
context['edit'] = True
|
||||||
context['title'] = 'Modifier'
|
context['title'] = 'Modifier'
|
||||||
context['equipment'] = self.object.equipment
|
context['equipment'] = self.object.equipment
|
||||||
|
context['session'] = self.request.GET.get('session')
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
url = reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
||||||
|
if self.session:
|
||||||
|
return '{}?session={}'.format(url, self.session)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class SettingDeleteView(generic.DeleteView):
|
class SettingDeleteView(generic.DeleteView):
|
||||||
|
@ -115,6 +146,43 @@ class SettingDeleteView(generic.DeleteView):
|
||||||
return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
||||||
|
|
||||||
|
|
||||||
|
class TheoreticalMaxCreateView(generic.CreateView):
|
||||||
|
model = TheoreticalMax
|
||||||
|
fields = ['equipment', 'date', 'value']
|
||||||
|
template_name = 'gym/theoretical_max_edit.html'
|
||||||
|
equipment = None
|
||||||
|
session = None
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['title'] = 'Ajouter'
|
||||||
|
context['equipment'] = self.equipment
|
||||||
|
context['session'] = self.session
|
||||||
|
return context
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
default_equipment_id = self.request.GET.get('equipment')
|
||||||
|
if default_equipment_id:
|
||||||
|
self.equipment = get_object_or_404(Equipment, pk=default_equipment_id)
|
||||||
|
|
||||||
|
self.session = self.request.GET.get('session')
|
||||||
|
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
initial = super().get_initial()
|
||||||
|
initial['equipment'] = self.equipment
|
||||||
|
initial['date'] = datetime.date.today()
|
||||||
|
|
||||||
|
return initial
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
url = reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
|
||||||
|
if self.session:
|
||||||
|
return '{}?session={}'.format(url, self.session)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class SessionCreateView(generic.CreateView):
|
class SessionCreateView(generic.CreateView):
|
||||||
model = Session
|
model = Session
|
||||||
fields = ['room', 'start']
|
fields = ['room', 'start']
|
||||||
|
@ -150,7 +218,7 @@ class SessionDetailView(generic.DetailView):
|
||||||
|
|
||||||
class RoundCreateView(generic.CreateView):
|
class RoundCreateView(generic.CreateView):
|
||||||
model = Round
|
model = Round
|
||||||
fields = ['equipment', 'session', 'theoretical_max_percentage', 'chosen_weight', 'notes']
|
fields = ['equipment', 'session', 'theoretical_max_percentage', 'chosen_weight', 'repetition_number', 'notes']
|
||||||
template_name = 'gym/round_edit.html'
|
template_name = 'gym/round_edit.html'
|
||||||
equipment = None
|
equipment = None
|
||||||
session = None
|
session = None
|
||||||
|
|
|
@ -35,6 +35,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'django.contrib.humanize',
|
||||||
'gym',
|
'gym',
|
||||||
'bootstrap4',
|
'bootstrap4',
|
||||||
]
|
]
|
||||||
|
@ -114,3 +115,4 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/2.0/howto/static-files/
|
# https://docs.djangoproject.com/en/2.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
|
|
Loading…
Reference in a new issue