1# Copyright 2015 The Distro Tracker Developers 

2# See the COPYRIGHT file at the top-level directory of this distribution and 

3# at https://deb.li/DTAuthors 

4# 

5# This file is part of Distro Tracker. It is subject to the license terms 

6# in the LICENSE file found in the top-level directory of this 

7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

8# including this file, may be copied, modified, propagated, or distributed 

9# except according to the terms contained in the LICENSE file. 

10"""Views for the :mod:`distro_tracker.vendor.debian` app.""" 

11 

12from django.http import HttpResponseBadRequest 

13from django.shortcuts import redirect 

14from django.utils.http import urlencode 

15from django.views.generic import View 

16 

17 

18class CodeSearchView(View): 

19 

20 BASE_URL = 'https://codesearch.debian.net/search' 

21 

22 def get(self, request): 

23 if 'query' not in request.GET or 'package' not in request.GET: 

24 return HttpResponseBadRequest('Both package and query are required ' 

25 'parameters') 

26 q = request.GET.get('query') 

27 if q == "": 

28 return HttpResponseBadRequest('Empty query is not allowed') 

29 package = request.GET.get('package') 

30 search = q + ' package:' + package 

31 url = self.BASE_URL + '?' + urlencode({'q': search}) 

32 return redirect(url)