Commit 3a4a451e authored by fred's avatar fred

add page to help cleaning up old tracks

parent 2921b105
......@@ -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)
{% 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 %}
......@@ -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 %}
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'),
]
......@@ -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('.')
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