<commit_before>from django.views.generic import TemplateView
from django.views.generic.edit import FormMixin

from .forms import SearchWeatherForm


class SearchView(FormMixin, TemplateView):
    form_class = SearchWeatherForm
    template_name = 'search/search.html'

    def get(self, request, *args, **kwargs):
        query = None
        results = None
        if 'q' in request.GET:
            form = self.form_class(request.GET)
            if form.is_valid():
                query = form.cleaned_data['q']
                results = form.get_results(query)
        else:
            form = self.get_form()
        context = self.get_context_data(form=form, query=query, results=results)
        return self.render_to_response(context)<commit_msg>Rewrote search view<commit_after>from django.views.generic import TemplateView
from django.views.generic.edit import FormMixin
from django.urls import reverse_lazy

from .forms import SearchWeatherForm


class SearchView(FormMixin, TemplateView):
    form_class = SearchWeatherForm
    template_name = 'search/search.html'
    query = None
    results = None

    def get(self, request, *args, **kwargs):
        form = self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

    def get_context_data(self, **kwargs):
        if 'query' not in kwargs:
            kwargs['query'] = self.query
        if 'results' not in kwargs:
            kwargs['results'] = self.results
        return super(SearchView, self).get_context_data(**kwargs)

    def get_form_kwargs(self):
        kwargs = super(SearchView, self).get_form_kwargs()
        if self.request.method in ('GET'):
            if 'q' in self.request.GET and self.request.GET['q'] is not None:
                kwargs.update({
                    'data': self.request.GET,
                })
        return kwargs

    def form_valid(self, form):
        self.query = form.cleaned_data['q']
        self.results = form.get_results(self.query)
        return self.render_to_response(self.get_context_data(form=form))
{'fraction_non_alphanumeric': 0.09981078524124881, 'fraction_numerical': 0.0, 'mean_word_length': 2.572635135135135, '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': '2733703', 'n_tokens_mistral': 611, 'n_tokens_neox': 599, 'n_words': 143}