def search_track(request): query_string = request.GET.get('q', '') cur_user = get_user(request) if (cur_user.is_authenticated()): playlists = Playlist.objects.filter(created_by=cur_user) else: playlists = [] form = SearchForm() if query_string: LIST_HEADERS = ( ('Title', 'track__title'), ('Artists', 'track__trackartist__artist__name'), ('Music Writer', 'track__music_writer'), ('Release Date', 'track__release_date'), ('Genre', 'track__genre__genre_name'), ('Original Version', 'track__original_version__title'), ) # additional_params = 'q=' + query_string sort_headers = SortHeaders(request, LIST_HEADERS) entry_query = get_query(query_string.strip(), ['track__title', 'record__genre__genre_name',\ 'track__music_writer', 'track__genre__genre_name' ,\ 'track__trackartist__artist__name', 'record__title', ]) track_list = Recordtrack.objects.filter(entry_query).order_by(sort_headers. get_order_by()).distinct() context = {'q':query_string, 'form': form, 'request_querydict': request.GET, \ 'playlists': playlists, 'view': 'track', 'headers': sort_headers.headers(), } return object_list(request, template_name='search_results.html', queryset=track_list, paginate_by=10, extra_context=context) else: form = SearchForm() context = {'form': form, 'record_list': []} t = loader.get_template("search_results.html") c = RequestContext(request, context) return HttpResponse(t.render(c))
def search_record(request): query_string = request.GET.get('q', '') form = SearchForm() if query_string: LIST_HEADERS = ( ('Title', 'title'), ('Matrix Number', 'matrix_number'), ('Artists', 'artist__name'), ('Rating', 'rating__avg_rating'), ('Genre', 'genre__genre_name'), ('Category', 'category__category_name'), ) # additional_params = 'q=' + query_string sort_headers = SortHeaders(request, LIST_HEADERS) entry_query = get_query(query_string.strip(), ['title', 'genre__genre_name', 'category__category_name', 'artist__name', 'recordtrack__track__title', ]) record_list = Record.objects.filter(entry_query).order_by(sort_headers.get_order_by()).distinct() context = {'q':query_string, 'form': form, 'request_querydict': request.GET, 'view': 'rec', 'headers': sort_headers.headers()} return object_list(request, template_name='search_results.html', queryset=record_list, paginate_by=10, extra_context=context) else: form = SearchForm() context = {'form': form, 'record_list': []} t = loader.get_template("search_results.html") c = RequestContext(request, context) return HttpResponse(t.render(c))