]> git.0d.be Git - django-panik-nonstop.git/commitdiff
add page to help cleaning up old tracks
authorFrédéric Péters <fpeters@0d.be>
Wed, 4 Oct 2017 15:30:16 +0000 (17:30 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 4 Oct 2017 15:30:57 +0000 (17:30 +0200)
nonstop/forms.py
nonstop/templates/nonstop/cleanup.html [new file with mode: 0644]
nonstop/templates/nonstop/quick_links.html
nonstop/urls.py
nonstop/views.py

index 8eda9d2917fe80002393952a80b3b21e13306d99..b421fc0c811a1877258b3c0db6a4172a5be3ed82 100644 (file)
@@ -27,3 +27,7 @@ class TrackSearchForm(forms.Form):
     zone = forms.ChoiceField(label=_('Nonstop Zone'), choices=get_optional_nonstop_zones)
     order_by = forms.ChoiceField(label=_('Order'),
             choices=[('alpha', _('Alphabetically'))])
+
+
+class CleanupForm(forms.Form):
+    zone = forms.ChoiceField(label=_('Nonstop Zone'), choices=get_optional_nonstop_zones)
diff --git a/nonstop/templates/nonstop/cleanup.html b/nonstop/templates/nonstop/cleanup.html
new file mode 100644 (file)
index 0000000..f66704d
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>Nonstop{% if zone %} — {{zone.title}} — {{count}} tracks{% endif %}</h2>
+{% endblock %}
+
+{% block content %}
+<form id="track-search">
+  {{ form.as_p }}
+  <button>{% trans "Submit" %}</button>
+</form>
+<hr>
+
+{% if tracks.exists %}
+<form method="post">
+  {% csrf_token %}
+<table>
+  {% for track in tracks %}
+  <tr>
+    <td><input name="track" type="hidden" value="{{track.id}}">
+        <input type="checkbox" name="remove-{{track.id}}"></td>
+    <td><a href="{% url 'track-view' pk=track.id %}">{{track.title}}</a></td>
+    <td>{{track.artist.name}}</td>
+    <td>{{track.added_to_nonstop_timestamp|date:"SHORT_DATE_FORMAT"}}</td>
+  </tr>
+  {% endfor %}
+</table>
+<div class="buttons">
+  <button>{% trans "Remove checked tracks" %}</button>
+</div>
+</form>
+
+<style>
+td {
+  padding: 0 1ex;
+}
+</style>
+{% endif %}
+
+{% endblock %}
index 57910d053c48283521f154f9ff3d3cb36fcff380..995bee6aabb6a8691b7f87c57c63bcc42ce15c7e 100644 (file)
@@ -13,5 +13,6 @@
  <li><a href="{% url 'nonstop-search' %}">Recherche</a> dans les pistes et artistes</li>
  <li><a href="{% url 'nonstop-upload-tracks' %}">Ajout de nouveaux morceaux</a></li>
  <li><a href="{% url 'nonstop-recent-tracks' %}">Édition rapide de métadonnées de nouveaux morceaux</a> (langue, Instru, SABAM, CFWB)</li>
+ <li><a href="{% url 'nonstop-cleanup' %}">Nettoyage de vieux morceaux</a></li>
 </ul>
 {% endblock %}
index b52f7ae58c233c440207342b76713a251f45da4c..34b1d01269979cbe364c04af18644d25da810076 100644 (file)
@@ -1,6 +1,6 @@
 from django.conf.urls import url
 
-from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView, RecentTracksView, QuickLinksView, SearchView
+from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView, RecentTracksView, QuickLinksView, SearchView, CleanupView
 
 urlpatterns = [
     # Example: /2012/nov/10/
@@ -20,4 +20,5 @@ urlpatterns = [
     url(r'^recent/$', RecentTracksView.as_view(), name='nonstop-recent-tracks'),
     url(r'^search/$', SearchView.as_view(), name='nonstop-search'),
     url(r'^quick-links/$', QuickLinksView.as_view(), name='nonstop-quick-links'),
+    url(r'^cleanup/$', CleanupView.as_view(), name='nonstop-cleanup'),
 ]
index c82dae75024cb8888fee77bbd14f7cbc6bafed25..16581943c0dcdbd7ce3c0ebdf270b45f2e1c87f0 100644 (file)
@@ -19,7 +19,7 @@ from django.views.generic.detail import DetailView
 from django.views.generic.edit import FormView
 from django.views.generic.list import ListView
 
-from .forms import UploadTracksForm, TrackMetaForm, TrackSearchForm
+from .forms import UploadTracksForm, TrackMetaForm, TrackSearchForm, CleanupForm
 from .models import SomaLogLine, Track, Artist, NonstopFile
 from emissions.models import Nonstop
 
@@ -262,3 +262,32 @@ class SearchView(TemplateView):
             ctx['tracks'] = queryset.order_by('title').select_related()
 
         return ctx
+
+
+class CleanupView(TemplateView):
+    template_name = 'nonstop/cleanup.html'
+
+    def get_context_data(self, **kwargs):
+        ctx = super(CleanupView, self).get_context_data(**kwargs)
+        ctx['form'] = CleanupForm()
+
+        zone = self.request.GET.get('zone')
+        if zone:
+            from emissions.models import Nonstop
+            ctx['zone'] = Nonstop.objects.get(id=zone)
+            ctx['count'] = Track.objects.filter(nonstop_zones=zone).count()
+            ctx['tracks'] = Track.objects.filter(nonstop_zones=zone).order_by(
+                            'added_to_nonstop_timestamp').select_related()[:30]
+        return ctx
+
+    def post(self, request, *args, **kwargs):
+        count = 0
+        for track_id in request.POST.getlist('track'):
+            if request.POST.get('remove-%s' % track_id):
+                track = Track.objects.get(id=track_id)
+                track.nonstop_zones.clear()
+                track.sync_nonstop_zones()
+                count += 1
+        if count:
+            messages.info(self.request, 'Removed %d new track(s)' % count)
+        return HttpResponseRedirect('.')