Commit d366e423 authored by fred's avatar fred

add search page

parent a83ed11d
......@@ -10,6 +10,7 @@
<ul>
<li><a href="{% url 'nonstop-today' %}">Aujourd'hui</a> (avec des liens pour naviguer vers les autres jours)</li>
<li><a href="{% url 'artist-list' %}">Artistes</a> présents (un jour ou l'autre) dans le nonstop</li>
<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>
</ul>
......
{% extends "base.html" %}
{% load i18n %}
{% block appbar %}
<h2>Nonstop</h2>
{% endblock %}
{% block content %}
<form><input name="q" type="search"><button>{% trans "Search" %}</button></form>
<hr>
{% if artists.exists %}
<h3>{% trans "Artists" %}</h3>
<ul>
{% for artist in artists %}
<li><a href="{% url 'artist-view' pk=artist.id %}">{{artist.name}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% if tracks.exists %}
<h3>{% trans "Tracks" %}</h3>
<ul>
{% for track in tracks %}
<li><a href="{% url 'track-view' pk=track.id %}">{{track.title}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
from django.conf.urls import url
from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView, RecentTracksView, QuickLinksView
from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView, UploadTracksView, RecentTracksView, QuickLinksView, SearchView
urlpatterns = [
# Example: /2012/nov/10/
......@@ -18,5 +18,6 @@ urlpatterns = [
url(r'^upload/$', UploadTracksView.as_view(), name='nonstop-upload-tracks'),
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'),
]
......@@ -238,3 +238,15 @@ class RecentTracksView(ListView):
class QuickLinksView(TemplateView):
template_name = 'nonstop/quick_links.html'
class SearchView(TemplateView):
template_name = 'nonstop/search.html'
def get_context_data(self, **kwargs):
ctx = super(SearchView, self).get_context_data(**kwargs)
q = self.request.GET.get('q')
if q:
ctx['artists'] = Artist.objects.filter(name__icontains=q.lower())
ctx['tracks'] = Track.objects.filter(title__icontains=q.lower())
return ctx
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