From 631015e82d524623d4eb444a7597c30f4ff5c4e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 22 Nov 2020 20:08:25 +0100 Subject: [PATCH] add minimal/maximal duration filters to sounds cell --- .../migrations/0020_auto_20201122_2005.py | 25 +++++++++++++++++++ panikombo/models.py | 10 ++++++++ 2 files changed, 35 insertions(+) create mode 100644 panikombo/migrations/0020_auto_20201122_2005.py diff --git a/panikombo/migrations/0020_auto_20201122_2005.py b/panikombo/migrations/0020_auto_20201122_2005.py new file mode 100644 index 0000000..b3d1396 --- /dev/null +++ b/panikombo/migrations/0020_auto_20201122_2005.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-11-22 20:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('panikombo', '0019_soundscell_sound_format'), + ] + + operations = [ + migrations.AddField( + model_name='soundscell', + name='maximal_duration', + field=models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='Maximal duration (in minutes)'), + ), + migrations.AddField( + model_name='soundscell', + name='minimal_duration', + field=models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='Minimal duration (in minutes)'), + ), + ] diff --git a/panikombo/models.py b/panikombo/models.py index 454678f..178ade1 100644 --- a/panikombo/models.py +++ b/panikombo/models.py @@ -231,6 +231,12 @@ class SoundsCell(CellBase): limit_to_focus = models.BooleanField(_('Limit to focused elements'), default=False) sound_format = models.ForeignKey('emissions.Format', verbose_name=_('Limit to format'), null=True, blank=True) + minimal_duration = models.PositiveIntegerField( + _('Minimal duration (in minutes)'), + default=None, blank=True, null=True) + maximal_duration = models.PositiveIntegerField( + _('Maximal duration (in minutes)'), + default=None, blank=True, null=True) count = models.PositiveSmallIntegerField(_('Count'), default=20) sort_order = models.CharField(_('Sort order'), default='-creation_timestamp', max_length=30, @@ -255,6 +261,10 @@ class SoundsCell(CellBase): soundfiles = soundfiles.filter(got_focus__isnull=False) if self.sound_format: soundfiles = soundfiles.filter(format_id=self.sound_format_id) + if self.minimal_duration: + soundfiles = soundfiles.filter(duration__gte=self.minimal_duration * 60) + if self.maximal_duration: + soundfiles = soundfiles.filter(duration__lte=self.maximal_duration * 60) soundfiles = soundfiles.select_related().extra( select={'first_diffusion': 'emissions_diffusion.datetime', }, select_params=(False, True), -- 2.39.2