diff --git a/gym/migrations/0007_auto_20180313_0857.py b/gym/migrations/0007_auto_20180313_0857.py new file mode 100644 index 0000000..ebbc11d --- /dev/null +++ b/gym/migrations/0007_auto_20180313_0857.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.2 on 2018-03-13 07:57 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gym', '0006_auto_20180304_2037'), + ] + + operations = [ + migrations.RemoveField( + model_name='theoreticalmax', + name='unit', + ), + migrations.AddField( + model_name='equipment', + name='unit', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='gym.Unit', verbose_name='unité'), + ), + ] diff --git a/gym/models.py b/gym/models.py index bce3c72..d2755f6 100644 --- a/gym/models.py +++ b/gym/models.py @@ -15,6 +15,17 @@ class Room(models.Model): return self.name +class Unit(models.Model): + class Meta: + verbose_name = 'unité' + verbose_name_plural = 'unités' + + name = models.CharField('nom', max_length=50) + + def __str__(self): + return self.name + + class Equipment(models.Model): class Meta: verbose_name = 'machine' @@ -28,6 +39,12 @@ class Equipment(models.Model): related_name='equipments', null=True ) + unit = models.ForeignKey( + verbose_name='unité', + to=Unit, + on_delete=models.PROTECT, + null=True + ) @property def last_theoretical_max(self): @@ -55,17 +72,6 @@ class Setting(models.Model): return f'{self.name}={self.value}' -class Unit(models.Model): - class Meta: - verbose_name = 'unité' - verbose_name_plural = 'unités' - - name = models.CharField('nom', max_length=50) - - def __str__(self): - return self.name - - class TheoreticalMax(models.Model): class Meta: verbose_name = 'maximum théorique' @@ -79,15 +85,9 @@ class TheoreticalMax(models.Model): ) date = models.DateField('date') value = models.FloatField('valeur') - unit = models.ForeignKey( - verbose_name='unité', - to=Unit, - on_delete=models.PROTECT, - null=True - ) def __str__(self): - return f'{self.value} {self.unit.name} le {self.date}' + return f'{self.value} {self.equipment.unit.name} le {self.date}' class Session(models.Model): diff --git a/gym/templates/gym/confirm_delete.html b/gym/templates/gym/confirm_delete.html new file mode 100644 index 0000000..b846169 --- /dev/null +++ b/gym/templates/gym/confirm_delete.html @@ -0,0 +1,17 @@ +{% extends 'gym/base.html' %} +{% load bootstrap4 %} + +{% block title %}Supprimer {{ article }} {{ name }}{% endblock %} +{% block h1 %}Supprimer {{ article }} {{ name }}{% endblock %} + +{% block content %} +
+
+
+ {% csrf_token %} +

{{ message|safe }}

+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/gym/templates/gym/equipment.html b/gym/templates/gym/equipment.html index a4a6023..d532fd1 100644 --- a/gym/templates/gym/equipment.html +++ b/gym/templates/gym/equipment.html @@ -81,7 +81,7 @@ {% if rounds %} diff --git a/gym/templates/gym/round_edit.html b/gym/templates/gym/round_edit.html index 45d8f3c..985d083 100644 --- a/gym/templates/gym/round_edit.html +++ b/gym/templates/gym/round_edit.html @@ -15,7 +15,7 @@ {% buttons %} {% if edit %} - Supprimer + Supprimer {% endif %} {% endbuttons %} diff --git a/gym/urls.py b/gym/urls.py index c93d96a..c03ca73 100644 --- a/gym/urls.py +++ b/gym/urls.py @@ -11,11 +11,13 @@ urlpatterns = [ path('equipment//', views.EquipmentDetailView.as_view(), name='equipment-detail'), path('setting/add/', views.SettingCreateView.as_view(), name='setting-create'), path('setting//', views.SettingUpdateView.as_view(), name='setting-edit'), - path('setting//delete', views.SettingDeleteView.as_view(), name='setting-delete'), + path('setting//delete/', views.SettingDeleteView.as_view(), name='setting-delete'), path('session/start/', views.SessionCreateView.as_view(), name='session-start'), path('session//', views.SessionDetailView.as_view(), name='session-detail'), path('round/add/', views.RoundCreateView.as_view(), name='round-create'), + path('round//', views.RoundUpdateView.as_view(), name='round-edit'), + path('round//delete/', views.RoundDeleteView.as_view(), name='round-delete'), path('theoretical-max/add/', views.TheoreticalMaxCreateView.as_view(), name='theoretical-max-create'), - # path('session//delete', views.SessionDeleteView.as_view(), name='session-delete'), + # path('session//delete/', views.SessionDeleteView.as_view(), name='session-delete'), ] diff --git a/gym/views.py b/gym/views.py index a64a86e..8a14801 100644 --- a/gym/views.py +++ b/gym/views.py @@ -167,8 +167,18 @@ class SettingUpdateView(LoginRequiredMixin, QuickActionsMixin, generic.UpdateVie class SettingDeleteView(LoginRequiredMixin, generic.DeleteView): model = Setting - template_name = 'gym/setting_confirm_delete.html' - context_object_name = 'setting' + template_name = 'gym/confirm_delete.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['article'] = 'une' + context['name'] = 'série' + context['message'] = ('Êtes-vous sûr de vouloir supprimer le réglage ' + '{} pour la machine "{}" ?'.format( + self.object, + self.object.equipment, + )) + return context def get_success_url(self): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) @@ -320,3 +330,50 @@ class RoundCreateView(LoginRequiredMixin, QuickActionsMixin, generic.CreateView) def get_success_url(self): return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) + + +class RoundUpdateView(LoginRequiredMixin, QuickActionsMixin, generic.UpdateView): + model = Round + fields = ['equipment', 'session', 'theoretical_max_percentage', 'chosen_weight', 'repetition_number', 'notes'] + template_name = 'gym/round_edit.html' + + def get_quick_actions(self): + return [ + { + 'url': reverse('equipment-detail', args=(self.object.equipment.pk,)), + 'category': 'secondary', + 'display': 'Retourner à la machine' + }, + ] + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['edit'] = True + context['title'] = 'Commencer' + context['equipment'] = self.object.equipment + return context + + def get_success_url(self): + return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk}) + + +class RoundDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Round + template_name = 'gym/confirm_delete.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['article'] = 'une' + context['name'] = 'série' + context['message'] = ('Êtes-vous sûr de vouloir supprimer ' + 'la série {}, {}x{}{} pour la séance "{}" ?'.format( + self.object.equipment, + self.object.repetition_number, + self.object.chosen_weight, + self.object.equipment.unit, + self.object.session + )) + return context + + def get_success_url(self): + return reverse('equipment-detail', kwargs={'pk': self.object.equipment.pk})