<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from operator import itemgetter

from django.http import JsonResponse
from django.shortcuts import redirect
from django.views.generic import TemplateView, View

from scuole.campuses.models import Campus
from scuole.districts.models import District


class AboutView(TemplateView):
    template_name = 'about.html'


class SearchView(TemplateView):
    template_name = 'search.html'

    def get(self, request, *args, **kwargs):
        if not self.request.GET.get('q'):
            return redirect('landing')

        return super(SearchView, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(SearchView, self).get_context_data(**kwargs)

        q = self.request.GET.get('q')

        context['matching_campuses'] = Campus.objects.filter(
            name__icontains=q).select_related('district')
        context['matching_districts'] = District.objects.filter(
            name__icontains=q).prefetch_related('campuses')

        return context


class LookupView(View):
    def get(self, request, *args, **kwargs):
        context = {}

        q = self.request.GET.get('q')

        campuses = [
            {'name': i.name,
             'url': i.get_absolute_url(),
             'type': 'Campus - {}'.format(i.district.name)}
            for i in Campus.objects.filter(
                name__icontains=q).select_related('district__name')[:15]]

        districts = [
            {'name': i.name, 'url': i.get_absolute_url(), 'type': 'District'}
            for i in District.objects.filter(
                name__icontains=q)[:15]]

        context['results'] = sorted(
            campuses + districts, key=itemgetter('name'))

        return JsonResponse(context, **kwargs)<commit_msg>Fix select_related call with Django 1.10<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from operator import itemgetter

from django.http import JsonResponse
from django.shortcuts import redirect
from django.views.generic import TemplateView, View

from scuole.campuses.models import Campus
from scuole.districts.models import District


class AboutView(TemplateView):
    template_name = 'about.html'


class SearchView(TemplateView):
    template_name = 'search.html'

    def get(self, request, *args, **kwargs):
        if not self.request.GET.get('q'):
            return redirect('landing')

        return super(SearchView, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(SearchView, self).get_context_data(**kwargs)

        q = self.request.GET.get('q')

        context['matching_campuses'] = Campus.objects.filter(
            name__icontains=q).select_related('district')
        context['matching_districts'] = District.objects.filter(
            name__icontains=q).prefetch_related('campuses')

        return context


class LookupView(View):
    def get(self, request, *args, **kwargs):
        context = {}

        q = self.request.GET.get('q')

        campuses = [
            {'name': i.name,
             'url': i.get_absolute_url(),
             'type': 'Campus - {}'.format(i.district.name)}
            for i in Campus.objects.filter(
                name__icontains=q).select_related('district')[:15]]

        districts = [
            {'name': i.name, 'url': i.get_absolute_url(), 'type': 'District'}
            for i in District.objects.filter(
                name__icontains=q)[:15]]

        context['results'] = sorted(
            campuses + districts, key=itemgetter('name'))

        return JsonResponse(context, **kwargs)
{'fraction_non_alphanumeric': 0.12766531713900134, 'fraction_numerical': 0.0035087719298245615, 'mean_word_length': 2.8725182863113896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5483709', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1044, 'n_words': 234}