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 %} +
{}
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})