<commit_before># -*- coding: utf-8 -*-
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView
from django.views.generic import ListView, DetailView, TemplateView
from django.shortcuts import get_object_or_404
from fuzzopress.blog.models import Post, NavItem, Widget

class CustomContextMixin(object):
    """
    Same context data for every class view
    """
    def get_context_data(self, **kwargs):
        context = super(CustomContextMixin, self).get_context_data(**kwargs)
        context.update({ 'navItems': NavItem.objects.all(), 'widgets': Widget.objects.all() })
        return context

class BlogPostView(CustomContextMixin, DetailView):
    """
    A single post view
    """
    context_object_name='post'

    def get_object(self):
        return get_object_or_404(Post, slug=self.kwargs['slug'])    

class BlogView(CustomContextMixin, ListView):
    """
    Main blog view
    """
    paginate_by = 3
    context_object_name = 'post_list'

    def get_queryset(self):
        return Post.objects.published()

class AboutView(CustomContextMixin, TemplateView):
    """
    For static pages. template_name can be set here or in urls.py
    """

class CustomDateMixin(CustomContextMixin, object):
    """
    Same date_field and context_object_name for every Dated-class view
    """
    date_field = 'published'
    context_object_name = 'post_list'

    def get_queryset(self):
        return Post.objects.published()

class ArchiveDay(CustomDateMixin, DayArchiveView):
    """
    For a day
    """
    month_format='%m'

class ArchiveMonth(CustomDateMixin, MonthArchiveView):
    """
    For a month
    """
    month_format='%m'

class ArchiveYear(CustomDateMixin, YearArchiveView):
    """
    For a year
    """
    make_object_list=True<commit_msg>Added archive to the main context<commit_after># -*- coding: utf-8 -*-
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView
from django.views.generic import ListView, DetailView, TemplateView
from fuzzopress.blog.models import Post, NavItem, Widget
from django.shortcuts import get_object_or_404
from datetime import date

class CustomContextMixin(object):
    """
    Same context data for every class view
    """
    def get_context_data(self, **kwargs):
        context = super(CustomContextMixin, self).get_context_data(**kwargs)
        arch = Post.objects.dates('published', 'month', order='DESC')
        archives = {}
        for i in arch:
            year = i.year
            month = i.month
            try:
                archives[year][month-1][1] = True
            except KeyError:
                # catch the KeyError, and set up list for that year
                archives[year] = [[date(year, m ,1),False] for m in xrange(1,13)]
                archives[year][month-1][1] = True
        context.update({
            'archives': sorted(archives.items(),reverse=True),
            'navItems': NavItem.objects.all(), 
            'widgets': Widget.objects.all() })
        return context

class BlogPostView(CustomContextMixin, DetailView):
    """
    A single post view
    """
    context_object_name='post'

    def get_object(self):
        return get_object_or_404(Post, slug=self.kwargs['slug'])    

class BlogView(CustomContextMixin, ListView):
    """
    Main blog view
    """
    paginate_by = 3
    context_object_name = 'post_list'

    def get_queryset(self):
        return Post.objects.published()

class AboutView(CustomContextMixin, TemplateView):
    """
    For static pages. template_name can be set here or in urls.py
    """

class CustomDateMixin(CustomContextMixin, object):
    """
    Same date_field and context_object_name for every Dated-class view
    """
    date_field = 'published'
    model = Post
    context_object_name = 'post_list'

class ArchiveDay(CustomDateMixin, DayArchiveView):
    """
    For a day
    """
    month_format='%m'

class ArchiveMonth(CustomDateMixin, MonthArchiveView):
    """
    For a month
    """
    month_format='%m'

class ArchiveYear(CustomDateMixin, YearArchiveView):
    """
    For a year
    """
    make_object_list=True
{'fraction_non_alphanumeric': 0.10685920577617329, 'fraction_numerical': 0.005776173285198556, 'mean_word_length': 3.168505516549649, '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': '2193005', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1223, 'n_words': 302}