<commit_before>from django import http
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.views.generic import FormView, View

from formtools.wizard.views import NamedUrlCookieWizardView

from . import models
from home_page import forms as shared_forms


class SectorWizardView(NamedUrlCookieWizardView):
    TEMPLATES = {
        'sector_form': 'sectors/sector_form.html',
        'job_descriptions_form': 'sectors/job_descriptions.html',
    }

    def get(self, *args, **kwargs):
        if 'restart' in self.request.GET:
            self.storage.reset()
            return HttpResponseRedirect(reverse('sectors:start'))
        return super().get(*args, **kwargs)

    def get_template_names(self):
        return [self.TEMPLATES[self.steps.current]]

    def get_form_kwargs(self, step):
        kwargs = {}
        if step == 'job_descriptions_form':
            sectors = self.get_cleaned_data_for_step('sector_form')['sector']
            kwargs['keywords'] = sectors
            if 'show_more[]' in self.request.GET:
                kwargs['show_more'] = self.request.GET['show_more[]']
        return kwargs

    def done(self, form_list, form_dict, **kwargs):
        discriptions_key = 'job_descriptions_form'
        description_form_data = \
            self.storage.get_step_data(discriptions_key)
        soc_codes = []
        for k, v in description_form_data.items():
            if k.startswith(discriptions_key) and '-' in k:
                soc_codes.append(k.split('-')[1])
        soc_codes_string = ','.join(soc_codes)
        report, _created = models.SectorsReport.objects.get_or_create(
            soc_codes=soc_codes_string)
        url = reverse("sectors:report", kwargs={'report_id': report.pk})
        return HttpResponseRedirect(url)
<commit_msg>Remove defunct code from sectors<commit_after>from django import http
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.views.generic import FormView, View

from formtools.wizard.views import NamedUrlCookieWizardView

from . import models
from home_page import forms as shared_forms


class SectorWizardView(NamedUrlCookieWizardView):
    TEMPLATES = {
        'sector_form': 'sectors/sector_form.html',
        'job_descriptions_form': 'sectors/job_descriptions.html',
    }

    def get(self, *args, **kwargs):
        if 'restart' in self.request.GET:
            self.storage.reset()
            return HttpResponseRedirect(reverse('sectors:start'))
        return super().get(*args, **kwargs)

    def get_template_names(self):
        return [self.TEMPLATES[self.steps.current]]

    def get_form_kwargs(self, step):
        kwargs = {}
        if step == 'job_descriptions_form':
            sectors = self.get_cleaned_data_for_step('sector_form')['sector']
            kwargs['keywords'] = sectors
        return kwargs

    def done(self, form_list, form_dict, **kwargs):
        discriptions_key = 'job_descriptions_form'
        description_form_data = \
            self.storage.get_step_data(discriptions_key)
        soc_codes = []
        for k, v in description_form_data.items():
            if k.startswith(discriptions_key) and '-' in k:
                soc_codes.append(k.split('-')[1])
        soc_codes_string = ','.join(soc_codes)
        report, _created = models.SectorsReport.objects.get_or_create(
            soc_codes=soc_codes_string)
        url = reverse("sectors:report", kwargs={'report_id': report.pk})
        return HttpResponseRedirect(url)

{'fraction_non_alphanumeric': 0.10190399570930544, 'fraction_numerical': 0.002145347278090641, 'mean_word_length': 3.181614349775785, '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': '4207918', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1087, 'n_words': 228}