# Copyright 2015 The Distro Tracker Developers
# See the COPYRIGHT file at the top-level directory of this distribution and
# at https://deb.li/DTAuthors
#
# This file is part of Distro Tracker. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
"""Views for the :mod:`distro_tracker.vendor.debian` app."""
from django.http import HttpResponseBadRequest
from django.shortcuts import redirect
from django.utils.http import urlencode
from django.views.generic import View
[docs]class CodeSearchView(View):
BASE_URL = 'https://codesearch.debian.net/search'
[docs] def get(self, request):
if 'query' not in request.GET or 'package' not in request.GET:
return HttpResponseBadRequest('Both package and query are required '
'parameters')
q = request.GET.get('query')
if q == "":
return HttpResponseBadRequest('Empty query is not allowed')
package = request.GET.get('package')
search = q + ' package:' + package
url = self.BASE_URL + '?' + urlencode({'q': search})
return redirect(url)