]> git.0d.be Git - django-panik-nonstop.git/commitdiff
quick edit of metadata of recently added files
authorFrédéric Péters <fpeters@0d.be>
Tue, 3 Oct 2017 12:56:20 +0000 (14:56 +0200)
committerFrédéric Péters <fpeters@0d.be>
Tue, 3 Oct 2017 12:56:20 +0000 (14:56 +0200)
nonstop/models.py
nonstop/templates/nonstop/recent_tracks.html [new file with mode: 0644]
nonstop/urls.py
nonstop/views.py

index 676d816256c1171061127ec7c70b616d67f93f23..64aca087829a9fca3b691dcd7e4a6f3206c0ec8a 100644 (file)
@@ -81,6 +81,8 @@ class Track(models.Model):
         from emissions.models import Nonstop
 
         for zone in Nonstop.objects.all():
+            if not zone.slug in TRANCHE_SLUG_DIR_MAPPING:
+                continue
             zone_dir = TRANCHE_SLUG_DIR_MAPPING[zone.slug]
             zone_path = os.path.join(LOCAL_BASE_PATH, 'Tranches', zone_dir, filename)
             if zone in current_zones:
diff --git a/nonstop/templates/nonstop/recent_tracks.html b/nonstop/templates/nonstop/recent_tracks.html
new file mode 100644 (file)
index 0000000..171a451
--- /dev/null
@@ -0,0 +1,52 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>Nonstop - {% trans "Recent Tracks" %}</h2>
+{% endblock %}
+
+{% block content %}
+<form method="post">
+{% csrf_token %}
+<table id="edit-recent">
+<thead>
+ <tr><th>{% trans "Title" %}</th><th>{% trans "Artist" %}</th>
+     <th class="en">EN</th><th class="fr">FR</th><th class="nl">NL</th>
+     <th class="instru">Instru</th><th class="sabam">Sabam</th><th class="cfwb">CFWB</th></tr>
+</thead>
+<tbody>
+{% for track in object_list %}
+<tr>
+ <td><input type="hidden" name="track" value="{{track.id}}">{{track.title}}</td><td>{{track.artist.name}}</td>
+ <td class="en"><input type="radio" name="lang-{{track.id}}" value="en" {% if track.language == "en" %}checked{% endif %}></td>
+ <td class="fr"><input type="radio" name="lang-{{track.id}}" value="fr" {% if track.language == "fr" %}checked{% endif %}></td>
+ <td class="nl"><input type="radio" name="lang-{{track.id}}" value="nl" {% if track.language == "nl" %}checked{% endif %}></td>
+ <td class="instru"><input type="checkbox" name="instru-{{track.id}}" {% if track.instru %}checked{% endif %}></td>
+ <td class="sabam"><input type="checkbox" name="sabam-{{track.id}}" {% if track.sabam %}checked{% endif %}></td>
+ <td class="cfwb"><input type="checkbox" name="cfwb-{{track.id}}" {% if track.cfwb %}checked{% endif %}></td>
+</tr>
+{% endfor %}
+</tbody>
+</table>
+
+  <div class="buttons">
+    <button class="submit-button">{% trans "Save" %}</button>
+  </div>
+</form>
+
+<style>
+table#edit-recent th,
+table#edit-recent td {
+  padding: 0 1ex;
+}
+</style>
+
+<script>
+$('table#edit-recent th').on('click', function() {
+  var propvalue = true;
+  if ($(this)[0].className == 'sabam') propvalue = false;
+  $('tbody').find('.' + $(this)[0].className + ' input').prop('checked', propvalue);
+});
+</script>
+
+{% endblock %}
index 9293e38d40a904f295343d9a018b86b7952c3c86..da785e8efd8f71cca229c06f3c971321a0006dc5 100644 (file)
@@ -1,6 +1,6 @@
 from django.conf.urls import url
 
-from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView
+from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView, RecentTracksView
 
 urlpatterns = [
     # Example: /2012/nov/10/
@@ -17,4 +17,5 @@ urlpatterns = [
         name="archive_day_csv"),
 
     url(r'^upload/$', UploadTracksView.as_view(), name='nonstop-upload-tracks'),
+    url(r'^recent/$', RecentTracksView.as_view(), name='nonstop-recent-tracks'),
 ]
index a77d48b79f5789ea87da49aba6e989bf0b55649e..ada063c97faa18be80ce472242df2d2c2533c7ee 100644 (file)
@@ -209,9 +209,27 @@ class UploadTracksView(FormView):
             track, created = Track.objects.get_or_create(title=track_title, artist=artist)
             nonstop_file.track = track
             nonstop_file.save()
+            nonstop_file.track.sync_nonstop_zones()
             if request.POST.get('nonstop_zone'):
                 track.nonstop_zones.add(
                         Nonstop.objects.get(id=request.POST.get('nonstop_zone')))
 
         messages.info(self.request, '%d new track(s)' % len(tracks))
         return self.form_valid(form)
+
+
+class RecentTracksView(ListView):
+    template_name = 'nonstop/recent_tracks.html'
+
+    def get_queryset(self):
+        return Track.objects.all().order_by('-creation_timestamp')[:20]
+
+    def post(self, request, *args, **kwargs):
+        for track_id in request.POST.getlist('track'):
+            track = Track.objects.get(id=track_id)
+            track.language = request.POST.get('lang-%s' % track_id, '')
+            track.instru = 'instru-%s' % track_id in request.POST
+            track.sabam = 'sabam-%s' % track_id in request.POST
+            track.cfwb = 'cfwb-%s' % track_id in request.POST
+            track.save()
+        return HttpResponseRedirect('.')