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

from django.shortcuts import get_object_or_404
from django.views.generic import DetailView

from .models import Campus, CampusStats
from scuole.districts.models import District, DistrictStats
from scuole.states.models import StateStats
from scuole.stats.models import SchoolYear
from scuole.counties.models import County, CountyCohorts
from scuole.regions.models import RegionCohorts


class CampusDetailView(DetailView):
    county_cohorts_model = CountyCohorts
    region_cohorts_model = RegionCohorts

    def get_object(self):
        return get_object_or_404(
            Campus.objects.prefetch_related('principals'),
            slug=self.kwargs['slug'],
            district__slug=self.kwargs['district_slug'])

    def get_context_data(self, **kwargs):
        context = super(CampusDetailView, self).get_context_data(**kwargs)
        county_cohorts = self.county_cohorts_model.objects.filter(
            county=self.object.county)
        region_cohorts = self.region_cohorts_model.objects.filter(
            region=self.object.district.region)
        year = self.kwargs['campus_year']

        if year:
            context['stat'] = get_object_or_404(
                CampusStats, year__name=year, campus=self.object)
            context['district'] = get_object_or_404(
                DistrictStats, year__name=year, district=self.object.district)
            context['state'] = get_object_or_404(
                StateStats, year__name=year, state__name='TX')
        else:
            latest_year = SchoolYear.objects.first()

            context['stat'] = get_object_or_404(
                CampusStats, year=latest_year,
                campus=self.object)
            context['district'] = get_object_or_404(
                DistrictStats, year=latest_year, district=self.object.district)
            context['state'] = get_object_or_404(
                StateStats, year=latest_year, state__name='TX')

        context['county'] = get_object_or_404(
            County, name=self.object.county)

        context['region'] = get_object_or_404(
            District, name=self.object.district)

        context['latest_county_cohort'] = county_cohorts.latest_cohort(
            county=self.object.county)
        context['latest_region_cohort'] = region_cohorts.latest_cohort(
            region=self.object.district.region)
        return context<commit_msg>got rid of unecessary code in the view that was confusing campuses with districts that have non-unique names<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.shortcuts import get_object_or_404
from django.views.generic import DetailView

from .models import Campus, CampusStats
from scuole.districts.models import District, DistrictStats
from scuole.states.models import StateStats
from scuole.stats.models import SchoolYear
from scuole.counties.models import County, CountyCohorts
from scuole.regions.models import RegionCohorts


class CampusDetailView(DetailView):
    county_cohorts_model = CountyCohorts
    region_cohorts_model = RegionCohorts

    def get_object(self):
        return get_object_or_404(
            Campus.objects.prefetch_related('principals'),
            slug=self.kwargs['slug'],
            district__slug=self.kwargs['district_slug'])

    def get_context_data(self, **kwargs):
        context = super(CampusDetailView, self).get_context_data(**kwargs)
        county_cohorts = self.county_cohorts_model.objects.filter(
            county=self.object.county)
        region_cohorts = self.region_cohorts_model.objects.filter(
            region=self.object.district.region)
        year = self.kwargs['campus_year']

        if year:
            context['stat'] = get_object_or_404(
                CampusStats, year__name=year, campus=self.object)
            context['district'] = get_object_or_404(
                DistrictStats, year__name=year, district=self.object.district)
            context['state'] = get_object_or_404(
                StateStats, year__name=year, state__name='TX')
        else:
            latest_year = SchoolYear.objects.first()

            context['stat'] = get_object_or_404(
                CampusStats, year=latest_year,
                campus=self.object)
            context['district'] = get_object_or_404(
                DistrictStats, year=latest_year, district=self.object.district)
            context['state'] = get_object_or_404(
                StateStats, year=latest_year, state__name='TX')

        # context['county'] = get_object_or_404(
        #     County, name=self.object.county)

        # context['region'] = get_object_or_404(
        #     District, name=self.object.district)

        # context['latest_county_cohort'] = county_cohorts.latest_cohort(
        #     county=self.object.county)
        # context['latest_region_cohort'] = region_cohorts.latest_cohort(
        #     region=self.object.district.region)
        return context
{'fraction_non_alphanumeric': 0.09177027827116636, 'fraction_numerical': 0.012236037102822183, 'mean_word_length': 2.9936958234830575, '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': '6579055', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1439, 'n_words': 258}