<commit_before># -*- coding: utf-8 -*-

import calendar
import datetime
from collections import OrderedDict

from django.utils import timezone

from .models import Category, Event


class EventsMixin(object):
    def get_context_data(self, **kwargs):
        context = super(EventsMixin, self).get_context_data(**kwargs)
        context['events_categories'] = True
        context['categories'] = Category.objects.all()
        return context


class CategoryMixin(object):
    def get_context_data(self, **kwargs):
        context = super(CategoryMixin, self).get_context_data(**kwargs)
        context['current_category'] = self.category
        return context


class EventsQuerysetMixin(object):
    model = Event
    queryset = Event.objects.published()


class CalendarMixin(EventsQuerysetMixin):
    allow_future = True
    allow_empty = True
    month_format = '%m'
    date_field = 'date_url'

    def get_time_now(self):
        return timezone.now()

    def get_current_month(self):
        return datetime.date(year=int(self.get_year()), month=int(self.get_month()), day=1)

    def get_context_data(self, **kwargs):
        context = super(CalendarMixin, self).get_context_data(**kwargs)

        now = self.get_time_now()
        current_month = self.get_current_month()
        previous_month = self.get_previous_month(current_month)
        next_month = self.get_next_month(current_month)

        context['calendar_headings'] = self.get_calendar_day_names()
        context['event_list'] = self.get_events_list()
        context['now_month'] = now
        context['previous_month'] = previous_month
        context['next_month'] = next_month
        context['current_month'] = current_month

        return context

    def get_events_list(self):
        current_month = self.get_current_month()
        next_month = self.get_next_month(current_month)

        month_days = OrderedDict()

        cal = calendar.Calendar(firstweekday=calendar.SUNDAY)
        for week in cal.monthdatescalendar(current_month.year, current_month.month):
            for i in week:
                month_days[i] = []

        # Get queryset from Mixin
        qs = self.get_queryset()

        qs = qs.filter(start__gte=current_month, start__lte=next_month)

        for i in qs:
            event_date = i.start.date()
            month_days[event_date].append(i)

        return month_days.items()

    def get_calendar_day_names(self):
        calendar_days = []
        day_names = list(calendar.day_name)
        cal = calendar.Calendar(firstweekday=calendar.SUNDAY)

        for i in cal.iterweekdays():
            calendar_days.append(day_names[i])

        return calendar_days<commit_msg>Reduce the amount of context needed<commit_after># -*- coding: utf-8 -*-

import calendar
import datetime
from collections import OrderedDict

from django.utils import timezone

from .models import Category, Event


class EventsMixin(object):
    def get_context_data(self, **kwargs):
        context = super(EventsMixin, self).get_context_data(**kwargs)
        context['events_categories'] = True
        context['categories'] = Category.objects.all()
        return context


class CategoryMixin(object):
    def get_context_data(self, **kwargs):
        context = super(CategoryMixin, self).get_context_data(**kwargs)
        context['current_category'] = self.category
        return context


class EventsQuerysetMixin(object):
    model = Event
    queryset = Event.objects.published()


class CalendarMixin(EventsQuerysetMixin):
    allow_future = True
    allow_empty = True
    month_format = '%m'
    date_field = 'date_url'

    def get_time_now(self):
        return timezone.now()

    def get_current_month(self):
        return datetime.date(year=int(self.get_year()), month=int(self.get_month()), day=1)

    def get_context_data(self, **kwargs):
        context = super(CalendarMixin, self).get_context_data(**kwargs)

        context['calendar_headings'] = self.get_calendar_day_names()
        context['calendar_events'] = self.get_events_list()

        return context

    def get_events_list(self):
        current_month = self.get_current_month()
        month_days = OrderedDict()

        cal = calendar.Calendar(firstweekday=calendar.SUNDAY)
        for week in cal.monthdatescalendar(current_month.year, current_month.month):
            for i in week:
                month_days[i] = []

        for obj in self.object_list:
            event_date = obj.start.date()
            month_days[event_date].append(obj)

        return month_days.items()

    def get_calendar_day_names(self):
        calendar_days = []
        day_names = list(calendar.day_name)
        cal = calendar.Calendar(firstweekday=calendar.SUNDAY)

        for i in cal.iterweekdays():
            calendar_days.append(day_names[i])

        return calendar_days
{'fraction_non_alphanumeric': 0.10059658506480149, 'fraction_numerical': 0.0008228759514503189, 'mean_word_length': 3.096040438079191, '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': '3066613', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1398, 'n_words': 281}