]> git.0d.be Git - django-panik-nonstop.git/commitdiff
add jingles management pages
authorFrédéric Péters <fpeters@0d.be>
Sat, 5 Sep 2020 11:59:24 +0000 (13:59 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sat, 5 Sep 2020 12:19:07 +0000 (14:19 +0200)
nonstop/migrations/0031_jingle_soundfile.py [new file with mode: 0644]
nonstop/migrations/0032_auto_20200905_1348.py [new file with mode: 0644]
nonstop/models.py
nonstop/templates/nonstop/jingle_form.html [new file with mode: 0644]
nonstop/templates/nonstop/jingle_list.html [new file with mode: 0644]
nonstop/templates/nonstop/quick_links.html
nonstop/urls.py
nonstop/views.py

diff --git a/nonstop/migrations/0031_jingle_soundfile.py b/nonstop/migrations/0031_jingle_soundfile.py
new file mode 100644 (file)
index 0000000..18b422c
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-09-05 13:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('nonstop', '0030_nonstopzonesettings_weights_text'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='jingle',
+            name='soundfile',
+            field=models.FileField(blank=True, max_length=255, null=True, upload_to='nonstop/jingles/', verbose_name='File'),
+        ),
+    ]
diff --git a/nonstop/migrations/0032_auto_20200905_1348.py b/nonstop/migrations/0032_auto_20200905_1348.py
new file mode 100644 (file)
index 0000000..97338f1
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-09-05 13:48
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('nonstop', '0031_jingle_soundfile'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='jingle',
+            name='filepath',
+            field=models.CharField(blank=True, max_length=255, verbose_name='File Path'),
+        ),
+    ]
index 52fd704e97d5a43c589d1fa24a0408077d287b24..29c2cd2be3660369f5807048c6619b1add00bf2d 100644 (file)
@@ -5,6 +5,7 @@ import os
 import random
 
 from django.conf import settings
+from django.core.files.storage import default_storage
 from django.core.urlresolvers import reverse
 from django.db import models
 from django.db.models.signals import post_delete, post_save
@@ -12,6 +13,8 @@ from django.dispatch import receiver
 from django.utils.timezone import now
 from django.utils.translation import ugettext_lazy as _
 
+from emissions.utils import get_duration
+
 from .app_settings import app_settings
 
 
@@ -215,7 +218,9 @@ class Jingle(models.Model):
         ordering = ['label']
 
     label = models.CharField(_('Label'), max_length=100)
-    filepath = models.CharField(_('File Path'), max_length=255)
+    filepath = models.CharField(_('File Path'), max_length=255, blank=True)
+    soundfile = models.FileField(_('File'), upload_to='nonstop/jingles/',
+            max_length=255, null=True, blank=True)
     duration = models.DurationField(_('Duration'), null=True, blank=True)
     default_for_initial_diffusions = models.BooleanField(_('Default for initial diffusions'), default=False)
     default_for_reruns = models.BooleanField(_('Default for reruns'), default=False)
@@ -224,11 +229,19 @@ class Jingle(models.Model):
     def __str__(self):
         return self.label
 
+    def save(self, *args, **kwargs):
+        super().save(*args, **kwargs)
+        if self.soundfile:
+            self.duration = datetime.timedelta(seconds=float(get_duration(self.get_local_filepath())))
+            super().save(*args, **kwargs)
+
     @property
     def short(self):
         # property for compatibility with Track model
         # for jingles self.filepath is actually only the last part of the path,
         # ex: jingles panik/H_marimba_RP_chucho_zoe.wav
+        if self.soundfile:
+            return os.path.split(self.soundfile.name)[-1]
         return self.filepath
 
     def file_path(self):
@@ -238,6 +251,8 @@ class Jingle(models.Model):
     def get_local_filepath(self):
         if not self.short:
             return None
+        if self.soundfile:
+            return default_storage.path(self.soundfile.name)
         return os.path.join(app_settings.LOCAL_BASE_PATH, app_settings.JINGLES_PREFIX, self.short)
 
     @property
diff --git a/nonstop/templates/nonstop/jingle_form.html b/nonstop/templates/nonstop/jingle_form.html
new file mode 100644 (file)
index 0000000..c4d7beb
--- /dev/null
@@ -0,0 +1,18 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>{% trans "Jingle" %}</h2>
+{% endblock %}
+
+{% block content %}
+<form method="post" enctype="multipart/form-data">
+  {% csrf_token %}
+  {{ form.as_p }}
+  <div class="buttons">
+    <button class="submit-button">{% if object.id %}{% trans "Save" %}{% else %}{% trans "Add" %}{% endif %}</button>
+    <a class="cancel" href=".">{% trans "Cancel" %}</a>
+  </div>
+</form>
+{% endblock %}
+
diff --git a/nonstop/templates/nonstop/jingle_list.html b/nonstop/templates/nonstop/jingle_list.html
new file mode 100644 (file)
index 0000000..034c512
--- /dev/null
@@ -0,0 +1,21 @@
+{% extends "nonstop/quick_links.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>Nonstop - {% trans "Jingles" %}</h2>
+<span class="actions"><a data-popup href="{% url 'nonstop-jingle-add' %}">{% trans "New" %}</a></span>
+{% endblock %}
+
+{% block content %}
+
+<div class="section">
+<ul class="objects-list single-links">
+{% for jingle in object_list %}
+<li><a data-popup href="{% url 'nonstop-jingle-settings' pk=jingle.pk %}">{{ jingle.label }}</a></li>
+{% endfor %}
+</ul>
+</div>
+
+
+
+{% endblock %}
index e2546aa4141a78839887dc2ec6db05b4cb5998e2..fd8db7200e1f590c51540ff2fdf8300567ab4729 100644 (file)
@@ -25,6 +25,7 @@
      <li><a href="{% url 'nonstop-random-tracks' %}">fichiers au hasards</a></li>
    </ul></li>
  <li><a href="{% url 'nonstop-cleanup' %}">Nettoyage de vieux morceaux</a></li>
+ <li><a href="{% url 'nonstop-jingles-list' %}">Paramétrage des jingles</a></li>
  <li><a href="{% url 'nonstop-zones' %}">Paramétrage des zones</a></li>
  <li><a href="{% url 'nonstop-stats' %}">Statistiques</a></li>
 {% endif %}
index d536ad28e0b98d2ddf762cb916298969ccf8ab4b..731b627bfcd9962b3bef6e1cf922c87c99cf9ac0 100644 (file)
@@ -8,6 +8,7 @@ from .views import (SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView
         QuickLinksView, SearchView, CleanupView, ArtistTracksMetadataView,
         SearchCsvView, AddSomaDiffusionView, DelSomaDiffusionView,
         DiffusionPropertiesView, AjaxProgram, ZonesView, ZoneSettings,
+        JinglesListView, JingleAddView, JingleSettingsView,
         jingle_audio_view, track_sound, ZoneTracklistPercents,
         MuninTracks)
 
@@ -21,6 +22,10 @@ urlpatterns = [
     url(r'^artists/$', ArtistListView.as_view(), name='artist-list'),
     url(r'^artists/(?P<pk>\d+)/$', ArtistDetailView.as_view(), name='artist-view'),
 
+    url(r'^jingles/$', JinglesListView.as_view(), name='nonstop-jingles-list'),
+    url(r'^jingles/add/$', JingleAddView.as_view(), name='nonstop-jingle-add'),
+    url(r'^jingles/(?P<pk>\d+)/$', JingleSettingsView.as_view(), name='nonstop-jingle-settings'),
+
     url(r'^zones/$$', ZonesView.as_view(), name='nonstop-zones'),
     url(r'^zones/(?P<slug>[\w-]+)/settings/$', ZoneSettings.as_view(), name='zone-settings'),
 
index dfbb4d65814921149b6f4c012aa6f98df7c93292..ae5a68de2564be8a9b252dcfda6b4c9fe66cb858 100644 (file)
@@ -131,6 +131,23 @@ class ArtistListView(ListView):
     model = Artist
 
 
+class JinglesListView(ListView):
+    model = Jingle
+
+
+class JingleAddView(CreateView):
+    model = Jingle
+    fields = ['label', 'soundfile']
+    success_url = reverse_lazy('nonstop-jingles-list')
+
+
+class JingleSettingsView(UpdateView):
+    model = Jingle
+    fields = ['label', 'soundfile', 'default_for_initial_diffusions',
+            'default_for_reruns', 'default_for_streams']
+    success_url = reverse_lazy('nonstop-jingles-list')
+
+
 class ZonesView(ListView):
     model = Nonstop
     template_name = 'nonstop/zones.html'