<commit_before># -*- coding: utf-8 -*-
# This code is distributed under the two-clause BSD license.
# Copyright (c) 2013 <NAME>


from django import forms as django_forms
from django import http
from django.contrib import messages
from django.views import generic

from . import forms


class BaseUploadView(generic.FormView):
    STEP_UPLOAD = 'upload'
    STEP_LINES = 'lines'

    # Sane defaults
    upload_template_name = 'batchform/upload_form.html'
    lines_template_name = 'batchform/lines_form.html'

    upload_form_class = forms.BaseUploadForm
    lines_formset_class = forms.LineFormSet

    # Required extensions
    inner_form_class = None
    columns = ()

    def __init__(self, *args, **kwargs):
        super(BaseUploadView, self).__init__(*args, **kwargs)
        self.current_step = self.STEP_UPLOAD

    # Overrides
    # =========

    def get_form(self, form_class, **extra):
        kwargs = self.get_form_kwargs()
        kwargs.update(extra)
        return form_class(**kwargs)

    def get_context_data(self, **kwargs):
        context = super(BaseUploadView, self).get_context_data(**kwargs)
        context['global_step'] = self.current_step
        return context

    # Dispatching
    # ===========

    # Control path is:
    # post() -> get_form(get_form_class()).is_valid() -> form_valid() / form_invalid()

    def post(self, request, *args, **kwargs):
        if request.POST['global_step'] not in (self.STEP_LINES, self.STEP_UPLOAD):
            raise django_forms.ValidationError(u"Invalid request.")
        self.current_step = request.POST['global_step']
        return super(BaseUploadView, self).post(request, *args, **kwargs)
<commit_msg>Minor bugfix.<commit_after># -*- coding: utf-8 -*-
# This code is distributed under the two-clause BSD license.
# Copyright (c) 2013 <NAME>


from django import forms as django_forms
from django import http
from django.contrib import messages
from django.views import generic

from . import forms


class BaseUploadView(generic.FormView):
    STEP_UPLOAD = 'upload'
    STEP_LINES = 'lines'

    # Sane defaults
    upload_template_name = 'batchform/upload_form.html'
    lines_template_name = 'batchform/lines_form.html'

    upload_form_class = forms.BaseUploadForm
    lines_formset_class = forms.LineFormSet

    # Required extensions
    inner_form_class = None
    columns = ()

    def __init__(self, *args, **kwargs):
        super(BaseUploadView, self).__init__(*args, **kwargs)
        self.current_step = self.STEP_UPLOAD

    # Overrides
    # =========

    def get_form(self, form_class, **extra):
        kwargs = self.get_form_kwargs()
        kwargs.update(extra)
        return form_class(**kwargs)

    def get_context_data(self, **kwargs):
        context = super(BaseUploadView, self).get_context_data(**kwargs)
        context['global_step'] = self.current_step
        return context

    # Dispatching
    # ===========

    # Control path is:
    # post() -> get_form(get_form_class()).is_valid() -> form_valid() / form_invalid()

    def post(self, request, *args, **kwargs):
        if request.POST.get('global_step') not in (self.STEP_LINES, self.STEP_UPLOAD):
            raise django_forms.ValidationError(u"Invalid request.")
        self.current_step = request.POST['global_step']
        return super(BaseUploadView, self).post(request, *args, **kwargs)

{'fraction_non_alphanumeric': 0.12047477744807121, 'fraction_numerical': 0.002967359050445104, 'mean_word_length': 3.4238845144356955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '463997', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1017, 'n_words': 233}