--- /dev/null
+# -*- 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'),
+ ),
+ ]
--- /dev/null
+# -*- 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'),
+ ),
+ ]
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
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
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)
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):
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
--- /dev/null
+{% 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 %}
+
--- /dev/null
+{% 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 %}
<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 %}
QuickLinksView, SearchView, CleanupView, ArtistTracksMetadataView,
SearchCsvView, AddSomaDiffusionView, DelSomaDiffusionView,
DiffusionPropertiesView, AjaxProgram, ZonesView, ZoneSettings,
+ JinglesListView, JingleAddView, JingleSettingsView,
jingle_audio_view, track_sound, ZoneTracklistPercents,
MuninTracks)
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'),
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'