<commit_before>"""Sample Views"""
from django.db.models import Count, Max
from django.views.generic import DetailView, TemplateView

from .models import Building, Elevator


class Landing(TemplateView):
    template_name = "tx_elevators/landing.html"

    def get_context_data(self, **kwargs):
        context = super(Landing, self).get_context_data(**kwargs)
        tallest_buildings = Building.objects.exclude(
            elevator__floors__isnull=True).annotate(
            height=Max('elevator__floors')).order_by('-height')
        context['tallest_buildings'] = tallest_buildings[:15]
        oldest_elevators = Elevator.objects.exclude(
            year_installed__lt=1000).order_by('year_installed')
        context['oldest_elevators'] = oldest_elevators[:15]
        densest_buildings = Building.objects.exclude(
            elevator__floors__isnull=True).annotate(
            num_elevators=Count('elevator')).order_by('-num_elevators')
        context['densest_buildings'] = densest_buildings[:15]
        return context


class BuildingView(DetailView):
    model = Building
    slug_field = 'elbi'
    slug_url_kwarg = 'elbi'
<commit_msg>limit oldest elevators listing to one per building<commit_after>"""Sample Views"""
from django.db.models import Count, Max
from django.views.generic import DetailView, TemplateView

from .models import Building, Elevator


class Landing(TemplateView):
    template_name = "tx_elevators/landing.html"

    def get_context_data(self, **kwargs):
        context = super(Landing, self).get_context_data(**kwargs)
        tallest_buildings = Building.objects.exclude(
            elevator__floors__isnull=True).annotate(
            height=Max('elevator__floors')).order_by('-height')
        context['tallest_buildings'] = tallest_buildings[:15]
        oldest_elevators = Elevator.objects.exclude(
            year_installed__lt=1000).order_by('year_installed').\
            distinct('building', 'year_installed')
        context['oldest_elevators'] = oldest_elevators[:15]
        densest_buildings = Building.objects.exclude(
            elevator__floors__isnull=True).annotate(
            num_elevators=Count('elevator')).order_by('-num_elevators')
        context['densest_buildings'] = densest_buildings[:15]
        return context


class BuildingView(DetailView):
    model = Building
    slug_field = 'elbi'
    slug_url_kwarg = 'elbi'

{'fraction_non_alphanumeric': 0.10809682804674457, 'fraction_numerical': 0.008347245409015025, 'mean_word_length': 3.8326612903225805, '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': '3910882', 'n_tokens_mistral': 758, 'n_tokens_neox': 733, 'n_words': 117}