<commit_before># This file contains the functions for MesoBoxes
# See mesobox/boxes.py for the enabling code.
from mesoblog.models import Article, Category

import calendar

BOX_INCLUDES = (
        'categories',
        'dates',
)

def categories(request):
    result = {}
    if request.resolver_match.app_name is "mesoblog":
        c = Category.objects.all().order_by('name')
        result = { "boxes": {"left": ['mesoblog/boxes/category-list.html',]}, "context": {"all_categories": c}}

    return result

class ArchiveMonth:
    def __init__(self, month):
        self.month = month
        self.name = calendar.month_name[month]
        self.count = 0
        self.nameNumber = str(month).zfill(2)

    def inc(self):
        self.count = self.count + 1

class ArchiveYear:
    def __init__(self, year):
        self.year = year
        self.name =  str(year).zfill(4)
        self.months = []
        for n in range(1,12):
            self.months.append(ArchiveMonth(n))

    def __eq__(self, other):
        return self.year == other

def dates(request):
    result = {}
    if request.resolver_match.app_name is "mesoblog":
        articles = Article.objects.all().order_by("-date_published")

        d = {}
        for a in articles:
            year = None
            for y in d.values():
                if y.year == a.date_published.year:
                    year = y
                    break
            if year is None:
                year = ArchiveYear(a.date_published.year)

            month = year.months[a.date_published.month-1]
            month.inc()
            year.months[a.date_published.month-1] = month

            d[a.date_published.year] = year

        d = d.values()

        result = { "boxes": {"right": ['mesoblog/boxes/dates-list.html',]}, "context": {"dates": d}}

    return result
<commit_msg>Sort the archive box so most recent year is at the top.<commit_after># This file contains the functions for MesoBoxes
# See mesobox/boxes.py for the enabling code.
from mesoblog.models import Article, Category

import calendar
import functools

BOX_INCLUDES = (
        'categories',
        'dates',
)

def categories(request):
    result = {}
    if request.resolver_match.app_name is "mesoblog":
        c = Category.objects.all().order_by('name')
        result = { "boxes": {"left": ['mesoblog/boxes/category-list.html',]}, "context": {"all_categories": c}}

    return result

class ArchiveMonth:
    def __init__(self, month):
        self.month = month
        self.name = calendar.month_name[month]
        self.count = 0
        self.nameNumber = str(month).zfill(2)

    def inc(self):
        self.count = self.count + 1

@functools.total_ordering
class ArchiveYear:
    def __init__(self, year):
        self.year = year
        self.name =  str(year).zfill(4)
        self.months = []
        for n in range(1,12):
            self.months.append(ArchiveMonth(n))

    def __eq__(self, other):
        return self.year == other

    def __lt__(self, other):
        if self.year < other.year:
            return True
        else:
            return False

def dates(request):
    result = {}
    if request.resolver_match.app_name is "mesoblog":
        articles = Article.objects.all()
        d = {}
        for a in articles:
            year = None
            for y in d.values():
                if y.year == a.date_published.year:
                    year = y
                    break
            if year is None:
                year = ArchiveYear(a.date_published.year)

            month = year.months[a.date_published.month-1]
            month.inc()
            year.months[a.date_published.month-1] = month

            d[a.date_published.year] = year

        d = sorted(d.values(), reverse=True)

        result = { "boxes": {"right": ['mesoblog/boxes/dates-list.html',]}, "context": {"dates": d}}

    return result

{'fraction_non_alphanumeric': 0.12139917695473251, 'fraction_numerical': 0.004629629629629629, 'mean_word_length': 2.062204724409449, 'pattern_counts': {'":': 20, '<': 4, '<?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': '185029', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1147, 'n_words': 288}