<commit_before>from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView

from ..universities.models import University
from ..professors.models import Professor
from ..comments.models import Comment
from .models import Department


class DepartmentView(TemplateView):
    template_name = 'department.html'

    def get_context_data(self, **kwargs):
        if 'view' not in kwargs:
            kwargs['view'] = self
        uni = get_object_or_404(University, slug=kwargs['slug'])
        department = get_object_or_404(
            Department, slug=kwargs['department_slug'])
        professors = Professor.objects.filter(
            university=uni,
            department=department, score__gt=0)
        comments = Comment.objects.filter(professor__in=professors).exclude(
            body__exact='').order_by('-created_at', '-id')

        kwargs['university'] = uni
        kwargs['department'] = department
        kwargs['professors'] = professors.order_by('first_name')
        kwargs['hi_professors'] = professors.order_by('score').reverse()[:5]
        kwargs['low_professors'] = professors.order_by('score')[:5]
        kwargs['recent_comments'] = comments[:5]
        return kwargs<commit_msg>fixed error on professor display with 0 ratings<commit_after>from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView

from ..universities.models import University
from ..professors.models import Professor
from ..comments.models import Comment
from .models import Department


class DepartmentView(TemplateView):
    template_name = 'department.html'

    def get_context_data(self, **kwargs):
        if 'view' not in kwargs:
            kwargs['view'] = self
        uni = get_object_or_404(University, slug=kwargs['slug'])
        department = get_object_or_404(
            Department, slug=kwargs['department_slug'])
        professors = Professor.objects.filter(
            university=uni,
            department=department, score__gt=0)
        all_professors = Professor.objects.filter(
            university=uni, department=department)
        comments = Comment.objects.filter(professor__in=professors).exclude(
            body__exact='').order_by('-created_at', '-id')

        kwargs['university'] = uni
        kwargs['department'] = department
        kwargs['professors'] = all_professors.order_by('first_name')
        kwargs['hi_professors'] = professors.order_by('score').reverse()[:5]
        kwargs['low_professors'] = professors.order_by('score')[:5]
        kwargs['recent_comments'] = comments[:5]
        return kwargs
{'fraction_non_alphanumeric': 0.11289092295957284, 'fraction_numerical': 0.010297482837528604, 'mean_word_length': 3.4991423670668955, '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': '4411177', 'n_tokens_mistral': 756, 'n_tokens_neox': 721, 'n_words': 146}