<commit_before>from django.views.generic import TemplateView, ListView
from django.db.models import Count, Sum
from django.utils.translation import ugettext_lazy as _

from dashboard.components import DashboardAppMixin
from ophasebase.models import Ophase
from staff.models import TutorGroup
from students.models import Student, Newsletter


class StudentsAppMixin(DashboardAppMixin):
    app_name_verbose = _("Ersties")
    app_name = 'students'
    permissions = ['students.add_student', 'exam.add_assignment']

    @property
    def sidebar_links(self):
        return [
            (_('Übersicht'), self.prefix_reverse_lazy('index')),
            (_('Zertifikate erstellen'), self.prefix_reverse_lazy('certificate')),
            (_('Newsletter'), self.prefix_reverse_lazy('newsletter'))
        ]


class StudentStatsView(StudentsAppMixin, TemplateView):
    template_name = "students/dashboard/view_stats.html"

    def get_context_data(self):
        context = super().get_context_data()

        current_ophase = Ophase.current()
        context['ophase_title'] = 'Ophase'
        if current_ophase is not None:
            context['ophase_title'] = str(current_ophase)

            students = Student.get_current()

            context['count_student'] = students.count()
            context['count_exam'] = students.filter(want_exam=True).count()

            context['tutor_groups'] = TutorGroup.objects\
                                                    .annotate(
                                                        num=Count('student'),
                                                        num_exam=Sum('student__want_exam'))\
                                                    .order_by('group_category', 'name')
        return context<commit_msg>This should fix the bug of #47<commit_after>from django.views.generic import TemplateView, ListView
from django.db.models import Count, Sum
from django.utils.translation import ugettext_lazy as _

from dashboard.components import DashboardAppMixin
from ophasebase.models import Ophase
from staff.models import TutorGroup
from students.models import Student, Newsletter


class StudentsAppMixin(DashboardAppMixin):
    app_name_verbose = _("Ersties")
    app_name = 'students'
    permissions = ['students.add_student', 'exam.add_assignment']

    @property
    def sidebar_links(self):
        return [
            (_('Übersicht'), self.prefix_reverse_lazy('index')),
            (_('Zertifikate erstellen'), self.prefix_reverse_lazy('certificate')),
            (_('Newsletter'), self.prefix_reverse_lazy('newsletter'))
        ]


class StudentStatsView(StudentsAppMixin, TemplateView):
    template_name = "students/dashboard/view_stats.html"

    def get_context_data(self):
        context = super().get_context_data()

        current_ophase = Ophase.current()
        context['ophase_title'] = 'Ophase'
        if current_ophase is not None:
            context['ophase_title'] = str(current_ophase)

            students = Student.get_current()

            context['count_student'] = students.count()
            context['count_exam'] = students.filter(want_exam=True).count()

            tutor_groups = TutorGroup.objects\
                                            .annotate(
                                                num=Count('student'),
                                                num_exam=Sum('student__want_exam'))\
                                            .order_by('group_category', 'name')

            # With some DB Backends Sum returns True instead of 1
            # int() fixes it.
            # see https://github.com/d120/pyophase/issues/47
            for group in tutor_groups:
                if group.num_exam != None:
                    group.num_exam = int(group.num_exam)

            context['tutor_groups'] = tutor_groups
        return context
{'fraction_non_alphanumeric': 0.09619860356865788, 'fraction_numerical': 0.002068787173519524, 'mean_word_length': 2.250420168067227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5080894', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1006, 'n_words': 205}