<commit_before>from django.db.models import Manager, Q
from django.db.models.query import QuerySet
from timetable.courses.utils import dict_by_attr

class QuerySetManager(Manager):
    use_for_related_fields = True
    def __init__(self, queryset_class=QuerySet):
        super(QuerySetManager, self).__init__()
        self.queryset_class = queryset_class

    def get_query_set(self):
        return self.queryset_class(self.model, using=self.db)

    def __getattr__(self, attr):
        try:
            return super(QuerySetManager, self).__getattr__(attr)
        except AttributeError:
            return getattr(self.get_query_set(), attr)

class SemesterBasedQuerySet(QuerySet):
    def by_semester(self, year=None, month=None):
        qs = self
        if year:
            qs = qs.filter(semesters__year__contains=year)

        if month:
            qs = qs.filter(semesters__month__contains=month)

        if year or month:
            qs = qs.distinct()

        return qs<commit_msg>Added attribution comment because they're the right thing to do.<commit_after>from django.db.models import Manager, Q
from django.db.models.query import QuerySet
from timetable.courses.utils import dict_by_attr

# using the fancy queryset manager technique, as describe:
# http://adam.gomaa.us/blog/2009/feb/16/subclassing-django-querysets/index.html
#
# the one flaw is using abstract models. But we're not using that right?

class QuerySetManager(Manager):
    use_for_related_fields = True
    def __init__(self, queryset_class=QuerySet):
        super(QuerySetManager, self).__init__()
        self.queryset_class = queryset_class

    def get_query_set(self):
        return self.queryset_class(self.model, using=self.db)

    def __getattr__(self, attr):
        try:
            return super(QuerySetManager, self).__getattr__(attr)
        except AttributeError:
            return getattr(self.get_query_set(), attr)

class SemesterBasedQuerySet(QuerySet):
    def by_semester(self, year=None, month=None):
        qs = self
        if year:
            qs = qs.filter(semesters__year__contains=year)

        if month:
            qs = qs.filter(semesters__month__contains=month)

        if year or month:
            qs = qs.distinct()

        return qs
{'fraction_non_alphanumeric': 0.0851721094439541, 'fraction_numerical': 0.00264783759929391, 'mean_word_length': 3.0482142857142858, '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': '1504822', 'n_tokens_mistral': 703, 'n_tokens_neox': 670, 'n_words': 160}