<commit_before>from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.views.generic import CreateView, DetailView, ListView, FormView
from django.views.generic.list import BaseListView

from discussion.forms import CommentForm, PostForm, SearchForm
from discussion.models import Discussion, Comment, Post
from discussion.utils import class_view_decorator


class SearchFormMixin(object):
    """Add the basic search form to your view."""
    def get_context_data(self, **kwargs):
        context = super(SearchFormMixin, self).get_context_data(**kwargs)
        context['search_form'] = SearchForm()
        return context

class DiscussionMixin(object):
    discussion_slug = 'discussion_slug'

    def dispatch(self, request, *args, **kwargs):
        self.discussion = self.get_discussion()
        return super(DiscussionMixin, self).dispatch(request, *args, **kwargs)

    def get_discussion(self):
        return Discussion.objects.get(slug=self.kwargs[self.discussion_slug])
<commit_msg>Fix get_discussion to work before self.kwargs is set<commit_after>from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.views.generic import CreateView, DetailView, ListView, FormView
from django.views.generic.list import BaseListView

from discussion.forms import CommentForm, PostForm, SearchForm
from discussion.models import Discussion, Comment, Post
from discussion.utils import class_view_decorator


class SearchFormMixin(object):
    """Add the basic search form to your view."""
    def get_context_data(self, **kwargs):
        context = super(SearchFormMixin, self).get_context_data(**kwargs)
        context['search_form'] = SearchForm()
        return context

class DiscussionMixin(object):
    discussion_slug = 'discussion_slug'

    def dispatch(self, request, *args, **kwargs):
        self.discussion = self.get_discussion(slug=kwargs[self.discussion_slug])
        return super(DiscussionMixin, self).dispatch(request, *args, **kwargs)

    def get_discussion(self, slug=None):
        if slug is None:
            slug = self.kwargs[self.discussion_slug]
        return Discussion.objects.get(slug=slug)

{'fraction_non_alphanumeric': 0.09151785714285714, 'fraction_numerical': 0.0, 'mean_word_length': 4.775773195876289, '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': '4290151', 'n_tokens_mistral': 622, 'n_tokens_neox': 600, 'n_words': 164}