]> git.0d.be Git - django-panik-emissions.git/commitdiff
do not display duration messages if there's no future diffusions
authorFrédéric Péters <fpeters@0d.be>
Mon, 25 Sep 2023 07:58:34 +0000 (09:58 +0200)
committerFrédéric Péters <fpeters@0d.be>
Mon, 25 Sep 2023 07:58:34 +0000 (09:58 +0200)
emissions/views.py

index 880ceac94e346c97d61d9654df8e821cf21d6749..4eec5ee0bd90054636b2d3a25055a5896c87e4dc 100644 (file)
@@ -475,16 +475,20 @@ class EpisodeAddSoundFileView(CreateView):
         response = super().form_valid(form)
         if not form.instance.duration:
             form.instance.compute_duration()
-            if form.instance.is_too_short():
-                messages.warning(
-                    self.request,
-                    _('The sound file duration does not match the expected duration (too short).'),
-                )
-            if form.instance.is_too_long():
-                messages.warning(
-                    self.request,
-                    _('The sound file duration does not match the expected duration (too long).'),
-                )
+            now = datetime.datetime.now()
+            if not form.instance.fragment:
+                diffusions = Diffusion.objects.filter(episode=form.instance.episode_id)
+                if any(x for x in diffusions if x.datetime > now):
+                    if form.instance.is_too_short():
+                        messages.warning(
+                            self.request,
+                            _('The sound file duration does not match the expected duration (too short).'),
+                        )
+                    if form.instance.is_too_long():
+                        messages.warning(
+                            self.request,
+                            _('The sound file duration does not match the expected duration (too long).'),
+                        )
             form.instance.save()
         return response