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

from django.core.urlresolvers import reverse
from django.views import generic

from braces.views import LoginRequiredMixin

from core.views import ActiveListView
from core.models import Investigation, Milestone, ProjectTracking
from project_management.forms import InvestigationForm, MilestoneForm


class InvestigationListView(LoginRequiredMixin, ActiveListView):

    template_name = 'project_management/investigation_list.html'
    model = Investigation

    def get_queryset(self):
        queryset = super(InvestigationListView, self).get_queryset()
        projects = [x.project for x in ProjectTracking.objects.all().filter(user=self.request.user)]
        return queryset.filter(project__in=projects)


class InvestigationDetailView(LoginRequiredMixin, generic.DetailView):

    template_name = 'project_management/investigation_detail.html'
    model = Investigation

    def get_context_data(self, **kwargs):
        context = super(InvestigationDetailView, self).get_context_data(**kwargs)
        investigation = context['investigation']
        context['literature'] = investigation.literature.all()[:20]
        context['processes'] = investigation.target_actions.all().order_by('-timestamp')[:20]
        context['milestones'] = Milestone.objects.filter(
            user=self.request.user).order_by('due_date')
        context['milestone_form'] = MilestoneForm(
            initial={
                'user': self.request.user,
                'investigation': investigation,
            })
        context['active_milestones'] = context['milestones'].filter(is_active=True)
        context['inactive_milestones'] = context['milestones'].filter(is_active=False)
        return context


class InvestigationCreateView(LoginRequiredMixin, generic.CreateView):

    model = Investigation
    template_name = 'project_management/investigation_create.html'
    form_class = InvestigationForm

    def get_form_kwargs(self):<commit_msg>Fixed milestone filtering in Investigation Detail<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.core.urlresolvers import reverse
from django.views import generic

from braces.views import LoginRequiredMixin

from core.views import ActiveListView
from core.models import Investigation, Milestone, ProjectTracking
from project_management.forms import InvestigationForm, MilestoneForm


class InvestigationListView(LoginRequiredMixin, ActiveListView):

    template_name = 'project_management/investigation_list.html'
    model = Investigation

    def get_queryset(self):
        queryset = super(InvestigationListView, self).get_queryset()
        projects = [x.project for x in ProjectTracking.objects.all().filter(user=self.request.user)]
        return queryset.filter(project__in=projects)


class InvestigationDetailView(LoginRequiredMixin, generic.DetailView):

    template_name = 'project_management/investigation_detail.html'
    model = Investigation

    def get_context_data(self, **kwargs):
        context = super(InvestigationDetailView, self).get_context_data(**kwargs)
        investigation = context['investigation']
        context['literature'] = investigation.literature.all()[:20]
        context['processes'] = investigation.target_actions.all().order_by('-timestamp')[:20]
        context['milestones'] = (Milestone.objects.filter(user=self.request.user)
                                                  .filter(investigation=self.object)
                                                  .order_by('due_date'))
        context['milestone_form'] = MilestoneForm(
            initial={
                'user': self.request.user,
                'investigation': investigation,
            })
        context['active_milestones'] = context['milestones'].filter(is_active=True)
        context['inactive_milestones'] = context['milestones'].filter(is_active=False)
        return context


class InvestigationCreateView(LoginRequiredMixin, generic.CreateView):

    model = Investigation
    template_name = 'project_management/investigation_create.html'
    form_class = InvestigationForm

    def get_form_kwargs(self):
{'fraction_non_alphanumeric': 0.09587750294464076, 'fraction_numerical': 0.002355712603062426, 'mean_word_length': 3.9200463499420626, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4030976', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1056, 'n_words': 207}