stamina: add settings/hack to merge tracks from multiple zones
authorFrédéric Péters <fpeters@0d.be>
Mon, 20 Jul 2020 11:47:23 +0000 (13:47 +0200)
committerFrédéric Péters <fpeters@0d.be>
Mon, 20 Jul 2020 11:47:23 +0000 (13:47 +0200)
nonstop/app_settings.py
nonstop/management/commands/stamina.py

index 2ea71cf..641f1aa 100644 (file)
@@ -50,5 +50,12 @@ class AppSettings:
     def SERVER_BIND_PORT(self):
         return self.get_setting('SERVER_BIND_PORT', 8888)
 
+    @property
+    def EXTRA_ZONES(self):
+        # zone slug to list of zone slugs,
+        # ex: {"le-mange-disque": ['hop-bop-and-co', 'up-beat-tempo']}
+        # to get tracks from additional zones.
+        return self.get_setting('EXTRA_ZONES', {})
+
 
 app_settings = AppSettings()
index a740db2..768e455 100644 (file)
@@ -108,9 +108,13 @@ class Command(BaseCommand):
                 current_datetime = start_datetime + sum(
                         [x.duration for x in playlist], datetime.timedelta(seconds=0))
 
+            zone_ids = [zone.id]
+            extra_zones = app_settings.EXTRA_ZONES.get(zone.slug)
+            if extra_zones:
+                zone_ids.extend([x.id for x in Nonstop.objects.filter(slug__in=extra_zones)])
             remaining_time = (end_datetime - current_datetime)
             track = Track.objects.filter(
-                    nonstop_zones=zone,
+                    nonstop_zones__in=zone_ids,
                     duration__isnull=False).exclude(
                             id__in=recent_tracks_id + [x.id for x in playlist if isinstance(x, Track)]
                     ).order_by('?').first()