diff --git a/gym/templates/gym/equipment.html b/gym/templates/gym/equipment.html
index 8c18120..c4d5563 100644
--- a/gym/templates/gym/equipment.html
+++ b/gym/templates/gym/equipment.html
@@ -16,12 +16,12 @@
Retourner à la salle
{% endif %}
- Ajouter un réglage
- Ajouter un max théorique
{% if session %}
- Commencer une série
{% endif %}
@@ -46,7 +46,7 @@
{% if equipment.settings.all %}
{% for setting in equipment.settings.all %}
- {{ setting.name }}
: {{ setting.value }}
{% endfor %}
diff --git a/gym/templates/gym/round_edit.html b/gym/templates/gym/round_edit.html
index 271e5ec..ae46240 100644
--- a/gym/templates/gym/round_edit.html
+++ b/gym/templates/gym/round_edit.html
@@ -12,7 +12,7 @@
diff --git a/gym/templates/gym/session_detail.html b/gym/templates/gym/session_detail.html
index a94c4ce..56dfd6b 100644
--- a/gym/templates/gym/session_detail.html
+++ b/gym/templates/gym/session_detail.html
@@ -10,7 +10,7 @@
@@ -34,7 +34,7 @@
Machines
diff --git a/gym/templates/gym/setting_edit.html b/gym/templates/gym/setting_edit.html
index d27e666..cf80636 100644
--- a/gym/templates/gym/setting_edit.html
+++ b/gym/templates/gym/setting_edit.html
@@ -10,7 +10,7 @@
diff --git a/gym/templates/gym/theoretical_max_edit.html b/gym/templates/gym/theoretical_max_edit.html
index 62111f9..7f47fa1 100644
--- a/gym/templates/gym/theoretical_max_edit.html
+++ b/gym/templates/gym/theoretical_max_edit.html
@@ -10,7 +10,7 @@
diff --git a/gym/views.py b/gym/views.py
index ca6d1f0..3a7d487 100644
--- a/gym/views.py
+++ b/gym/views.py
@@ -12,12 +12,24 @@ class RoomListView(generic.ListView):
context_object_name = 'rooms'
template_name = 'gym/rooms.html'
+ def dispatch(self, request, *args, **kwargs):
+ if 'session' in request.session:
+ del request.session['session_pk']
+
+ return super().dispatch(request, *args, **kwargs)
+
class RoomDetailView(generic.DetailView):
model = Room
context_object_name = 'room'
template_name = 'gym/room.html'
+ def dispatch(self, request, *args, **kwargs):
+ if 'session' in request.session:
+ del request.session['session_pk']
+
+ return super().dispatch(request, *args, **kwargs)
+
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['sessions'] = self.object.sessions.all().order_by('-start')
@@ -28,16 +40,10 @@ class EquipmentDetailView(generic.DetailView):
model = Equipment
context_object_name = 'equipment'
template_name = 'gym/equipment.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['session'] = self.session
+ context['session'] = self.request.session.get('session_pk')
return context
@@ -46,7 +52,6 @@ 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)
@@ -54,18 +59,13 @@ class EquipmentCreateView(generic.CreateView):
return context
def get_success_url(self):
- url = reverse('equipment-detail', kwargs={'pk': self.object.pk})
- if self.session:
- return "{}?session={}".format(url, self.session)
- return url
+ return reverse('equipment-detail', kwargs={'pk': self.object.pk})
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):
@@ -80,13 +80,11 @@ 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):
@@ -94,8 +92,6 @@ 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):
@@ -105,36 +101,23 @@ class SettingCreateView(generic.CreateView):
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
+ return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
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):
- url = reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
- if self.session:
- return '{}?session={}'.format(url, self.session)
- return url
+ return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
class SettingDeleteView(generic.DeleteView):
@@ -151,13 +134,11 @@ class TheoreticalMaxCreateView(generic.CreateView):
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):
@@ -165,8 +146,6 @@ class TheoreticalMaxCreateView(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):
@@ -177,10 +156,7 @@ class TheoreticalMaxCreateView(generic.CreateView):
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
+ return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})
class SessionCreateView(generic.CreateView):
@@ -196,7 +172,9 @@ class SessionCreateView(generic.CreateView):
return context
def get_success_url(self):
- return reverse('session-detail', kwargs={'pk': self.object.pk})
+ session_pk = self.object.pk
+ self.request.session['session_pk'] = session_pk
+ return reverse('session-detail', kwargs={'pk': session_pk})
def dispatch(self, request, *args, **kwargs):
self.room = get_object_or_404(Room, pk=self.request.GET.get('room'))
@@ -215,24 +193,27 @@ class SessionDetailView(generic.DetailView):
context_object_name = 'session'
template_name = 'gym/session_detail.html'
+ def get(self, request, *args, **kwargs):
+ request.session['session_pk'] = self.get_object().pk
+ return super().get(request, *args, **kwargs)
+
class RoundCreateView(generic.CreateView):
model = Round
fields = ['equipment', 'session', 'theoretical_max_percentage', 'chosen_weight', 'repetition_number', 'notes']
template_name = 'gym/round_edit.html'
equipment = None
- session = None
+ session_pk = None
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Commencer'
context['equipment'] = self.equipment
- context['session'] = self.session
return context
def dispatch(self, request, *args, **kwargs):
self.equipment = get_object_or_404(Equipment, pk=self.request.GET.get('equipment'))
- self.session = get_object_or_404(Equipment, pk=self.request.GET.get('session'))
+ self.session_pk = self.request.session.get('session_pk')
return super().dispatch(request, *args, **kwargs)
@@ -240,7 +221,7 @@ class RoundCreateView(generic.CreateView):
theoretical_max_percentage = 65
initial = super().get_initial()
initial['equipment'] = self.equipment
- initial['session'] = self.session
+ initial['session'] = self.session_pk
initial['repetition_number'] = 3
initial['theoretical_max_percentage'] = theoretical_max_percentage
proposed_weight = 0