Implement theoretical max

This commit is contained in:
Gabriel Augendre 2018-03-04 09:23:35 +01:00
parent 359f4e6fab
commit f9ba5b9444
No known key found for this signature in database
GPG key ID: F360212F958357D4
15 changed files with 194 additions and 29 deletions

View file

@ -7,7 +7,7 @@ name = "pypi"
[packages]
django = "*"
Django = "*"
djangorestframework = "*"
"django-bootstrap4" = "*"

2
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "c3ee9bacf90669123493994e4f194606cd953134dd819c73684629335c5a7ee6"
"sha256": "236f27f0ee84bf5dfc608ea235c7edb929fd32228bc5e98b7f269cc52d0fc312"
},
"host-environment-markers": {
"implementation_name": "cpython",

View file

@ -31,7 +31,7 @@ class Equipment(models.Model):
@property
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):
return f'{self.name} ({self.room.name})'
@ -70,7 +70,7 @@ class TheoreticalMax(models.Model):
value = models.FloatField('valeur')
def __str__(self):
return f'{self.value}kg le {self.date}'
return f'{self.value} le {self.date}'
class Session(models.Model):
@ -88,6 +88,9 @@ class Session(models.Model):
)
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 Meta:

8
gym/static/gym/round.js Normal file
View 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);
})
});

View file

@ -33,5 +33,8 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
{% block js %}
{% endblock %}
</body>
</html>

View file

@ -1,4 +1,5 @@
{% extends 'gym/base.html' %}
{% load humanize %}
{% block content %}
<div class="row">
@ -8,25 +9,51 @@
</div>
<div class="row">
<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 %}
<a href="{% url 'round-create' %}?equipment={{ equipment.pk }}&session={{ session.pk }}"
class="btn btn-success">Commencer une série</a>
<a href="{% url 'session-detail' session %}"
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 %}
</div>
</div>
<div class="row">
<div class="col-12">
<h2>Réglages</h2>
<ul class="list-group">
{% for setting in equipment.settings.all %}
<a href="{% url 'setting-edit' setting.pk %}" class="list-group-item">{{ setting.name }}
: {{ setting.value }}</a>
{% endfor %}
</ul>
{% if equipment.settings.all %}
<ul class="list-group">
{% for setting in equipment.settings.all %}
<a href="{% url 'setting-edit' setting.pk %}?session={{ session }}"
class="list-group-item">{{ setting.name }}
: {{ setting.value }}</a>
{% endfor %}
</ul>
{% else %}
<p>Pas de réglage pour le moment.</p>
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -7,6 +7,11 @@
<h1>{% block title %}Ajouter une machine{% endblock %}</h1>
</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="col-12">
<form action="" method="post">

View file

@ -23,12 +23,12 @@
</ul>
</div>
</div>
{% if room.sessions.all %}
{% if sessions %}
<div class="row">
<div class="col-12">
<h2>Séances</h2>
<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>
{% endfor %}
</ul>

View file

@ -1,5 +1,7 @@
{% extends 'gym/base.html' %}
{% load bootstrap4 %}
{% load static %}
{% load l10n %}
{% block content %}
<div class="row">
@ -10,7 +12,7 @@
<div class="row">
<div class="col-12">
{% 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 %}
</div>
</div>
@ -28,4 +30,9 @@
</form>
</div>
</div>
{% endblock %}
{% block js %}
<script>var max_theorique = {% localize off %}{{ equipment.last_theoretical_max.value }}{% endlocalize %};</script>
<script src="{% static 'gym/round.js' %}"></script>
{% endblock %}

View file

@ -10,7 +10,7 @@
<div class="row">
<div class="col-12">
<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 class="row">
@ -39,4 +39,14 @@
</ul>
</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 }} &ndash; {{ round.repetition_number }} répétitions &times; {{ round.chosen_weight }}</a>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}

View file

@ -10,7 +10,7 @@
<div class="row">
<div class="col-12">
{% 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 %}
</div>
</div>

View 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 %}

View file

@ -15,6 +15,7 @@ urlpatterns = [
path('session/start/', views.SessionCreateView.as_view(), name='session-start'),
path('session/<int:pk>/', views.SessionDetailView.as_view(), name='session-detail'),
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'),
]

View file

@ -4,7 +4,7 @@ from django.shortcuts import get_object_or_404
from django.urls import reverse
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):
@ -18,6 +18,11 @@ class RoomDetailView(generic.DetailView):
context_object_name = 'room'
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):
model = Equipment
@ -26,9 +31,7 @@ class EquipmentDetailView(generic.DetailView):
session = None
def dispatch(self, request, *args, **kwargs):
default_session_id = self.request.GET.get('session')
if default_session_id:
self.session = get_object_or_404(Room, pk=default_session_id)
self.session = self.request.GET.get('session')
return super().dispatch(request, *args, **kwargs)
@ -43,15 +46,26 @@ class EquipmentCreateView(generic.CreateView):
fields = ['room', 'name']
template_name = 'gym/equipment_edit.html'
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):
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):
default_room_id = self.request.GET.get('room')
if 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)
def get_initial(self):
@ -66,11 +80,13 @@ class SettingCreateView(generic.CreateView):
fields = ['equipment', 'name', 'value']
template_name = 'gym/setting_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):
@ -78,6 +94,8 @@ class SettingCreateView(generic.CreateView):
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):
@ -87,23 +105,36 @@ class SettingCreateView(generic.CreateView):
return initial
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):
model = Setting
fields = ['equipment', 'name', 'value']
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):
context = super().get_context_data(**kwargs)
context['edit'] = True
context['title'] = 'Modifier'
context['equipment'] = self.object.equipment
context['session'] = self.request.GET.get('session')
return context
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):
@ -115,6 +146,43 @@ class SettingDeleteView(generic.DeleteView):
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):
model = Session
fields = ['room', 'start']
@ -150,7 +218,7 @@ class SessionDetailView(generic.DetailView):
class RoundCreateView(generic.CreateView):
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'
equipment = None
session = None

View file

@ -35,6 +35,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'gym',
'bootstrap4',
]
@ -114,3 +115,4 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')