<commit_before>from __future__ import absolute_import, unicode_literals

from dash.orgs.views import OrgPermsMixin

from django.utils.translation import ugettext_lazy as _

from smartmin.users.views import SmartTemplateView

from tracpro.polls.models import Poll
from tracpro.baseline.models import BaselineTerm
from tracpro.baseline.utils import chart_baseline


class HomeView(OrgPermsMixin, SmartTemplateView):
    """TracPro homepage"""

    title = _("Home")
    template_name = 'home/home.html'

    def has_permission(self, request, *args, **kwargs):
        return request.user.is_authenticated()

    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)
        context['polls'] = Poll.get_all(self.request.org).order_by('name')
        # Loop through all baseline terms, until we find one with data
        baselineterms = BaselineTerm.objects.all().order_by('-end_date')
        for baselineterm in baselineterms:
            data_found = baselineterm.check_for_data(self.request.data_regions)
            if data_found:
                answers_dict, baseline_dict, all_regions, date_list = chart_baseline(
                    baselineterm=baselineterm, regions=self.request.data_regions, region_selected=0)
                context['all_regions'] = all_regions
                context['date_list'] = date_list
                context['baseline_dict'] = baseline_dict
                context['answers_dict'] = answers_dict
                context['baselineterm'] = baselineterm
                break  # Found our baseline chart with data, send it back to the view

        # Return top 5 baseline terms only
        context['baselineterms'] = baselineterms[0:5]

        return context<commit_msg>Filter homepage baselines by org.<commit_after>from __future__ import absolute_import, unicode_literals

from dash.orgs.views import OrgPermsMixin

from django.utils.translation import ugettext_lazy as _

from smartmin.users.views import SmartTemplateView

from tracpro.polls.models import Poll
from tracpro.baseline.models import BaselineTerm
from tracpro.baseline.utils import chart_baseline


class HomeView(OrgPermsMixin, SmartTemplateView):
    """TracPro homepage"""

    title = _("Home")
    template_name = 'home/home.html'

    def has_permission(self, request, *args, **kwargs):
        return request.user.is_authenticated()

    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)
        context['polls'] = Poll.get_all(self.request.org).order_by('name')
        # Loop through all baseline terms, until we find one with data
        baselineterms = BaselineTerm.get_all(self.request.org).order_by('-end_date')
        for baselineterm in baselineterms:
            data_found = baselineterm.check_for_data(self.request.data_regions)
            if data_found:
                answers_dict, baseline_dict, all_regions, date_list = chart_baseline(
                    baselineterm=baselineterm, regions=self.request.data_regions, region_selected=0)
                context['all_regions'] = all_regions
                context['date_list'] = date_list
                context['baseline_dict'] = baseline_dict
                context['answers_dict'] = answers_dict
                context['baselineterm'] = baselineterm
                break  # Found our baseline chart with data, send it back to the view

        # Return top 5 baseline terms only
        context['baselineterms'] = baselineterms[0:5]

        return context
{'fraction_non_alphanumeric': 0.08450704225352113, 'fraction_numerical': 0.0022535211267605635, 'mean_word_length': 3.172737955346651, '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': '5592593', 'n_tokens_mistral': 1057, 'n_tokens_neox': 983, 'n_words': 235}