Commit 418f1d40 authored by fred's avatar fred

add switch to compute-durations to handle jingles

parent d54df015
......@@ -4,7 +4,7 @@ import os
from django.core.management.base import BaseCommand
from emissions.utils import get_duration
from ...models import Track
from ...models import Track, Jingle
class Command(BaseCommand):
......@@ -12,16 +12,22 @@ class Command(BaseCommand):
parser.add_argument(
'--recent', action='store_true', default=False,
help='Only do recent files')
parser.add_argument(
'--jingles', action='store_true', default=False,
help='Do jingles')
parser.add_argument(
'--force', action='store_true', default=False,
help='Recompute existing durations')
def handle(self, verbosity, **kwargs):
qs = Track.objects.all()
if kwargs.get('jingles'):
qs = Jingle.objects.all()
else:
qs = Track.objects.all()
if kwargs.get('recent'):
qs = qs.filter(creation_timestamp__gt=datetime.date.today() - datetime.timedelta(days=10))
if not kwargs.get('force'):
qs = qs.filter(duration__isnull=True)
if kwargs.get('recent'):
qs = qs.filter(creation_timestamp__gt=datetime.date.today() - datetime.timedelta(days=10))
if verbosity:
total = qs.count()
for i, track in enumerate(qs):
......
......@@ -182,6 +182,19 @@ class Jingle(models.Model):
Jingle.objects.all().update(**{attr: False})
return super(Jingle, self).save(**kwargs)
@property
def short(self):
return self.filepath[len(REMOTE_BASE_PATH):]
def file_path(self):
# for compatibility with Track model method
return self.get_local_filepath()
def get_local_filepath(self):
if not self.short:
return None
return os.path.join(LOCAL_BASE_PATH, self.short)
@property
def title(self):
return self.label
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment