<commit_before>"""Mixins for Zinnia archive views"""
from datetime import datetime
from datetime import timedelta

from zinnia.settings import PAGINATION
from zinnia.settings import ALLOW_EMPTY
from zinnia.settings import ALLOW_FUTURE


class ArchiveMixin(object):
    """Mixin centralizing the configuration
    of the archives views"""
    paginate_by = PAGINATION
    allow_empty = ALLOW_EMPTY
    allow_future = ALLOW_FUTURE
    date_field = 'creation_date'
    month_format = '%m'
    week_format = '%W'


class PreviousNextPublishedMixin(object):
    """Mixin for correcting the previous/next
    context variable to return dates with published datas"""

    def get_previous_next_published(self, date):
        """
        Returns a dict of the next and previous date periods
        with published entries.
        """
        previous_next = getattr(self, 'previous_next', None)

        if previous_next is None:
            date_year = datetime(date.year, 1, 1)
            date_month = datetime(date.year, date.month, 1)
            date_day = datetime(date.year, date.month, date.day)
            date_next_week = date_day + timedelta(days=7)
            previous_next = {'year': [None, None],
                             'week': [None, None],
                             'month': [None, None],
                             'day':  [None, None]}
            dates = self.get_queryset().datetimes(
                'creation_date', 'day', order='ASC')
            for d in dates:
                d_year = datetime(d.year, 1, 1)
                d_month = datetime(d.year, d.month, 1)
                d_day = datetime(d.year, d.month, d.day)
                if d_year < date_year:
                    previous_next['year'][0] = d_year.date()
                elif d_year > date_year and not previous_next['year'][1]:<commit_msg>Using 1 week is beter than 7 days<commit_after>"""Mixins for Zinnia archive views"""
from datetime import datetime
from datetime import timedelta

from zinnia.settings import PAGINATION
from zinnia.settings import ALLOW_EMPTY
from zinnia.settings import ALLOW_FUTURE


class ArchiveMixin(object):
    """Mixin centralizing the configuration
    of the archives views"""
    paginate_by = PAGINATION
    allow_empty = ALLOW_EMPTY
    allow_future = ALLOW_FUTURE
    date_field = 'creation_date'
    month_format = '%m'
    week_format = '%W'


class PreviousNextPublishedMixin(object):
    """Mixin for correcting the previous/next
    context variable to return dates with published datas"""

    def get_previous_next_published(self, date):
        """
        Returns a dict of the next and previous date periods
        with published entries.
        """
        previous_next = getattr(self, 'previous_next', None)

        if previous_next is None:
            date_year = datetime(date.year, 1, 1)
            date_month = datetime(date.year, date.month, 1)
            date_day = datetime(date.year, date.month, date.day)
            date_next_week = date_day + timedelta(weeks=1)
            previous_next = {'year': [None, None],
                             'week': [None, None],
                             'month': [None, None],
                             'day':  [None, None]}
            dates = self.get_queryset().datetimes(
                'creation_date', 'day', order='ASC')
            for d in dates:
                d_year = datetime(d.year, 1, 1)
                d_month = datetime(d.year, d.month, 1)
                d_day = datetime(d.year, d.month, d.day)
                if d_year < date_year:
                    previous_next['year'][0] = d_year.date()
                elif d_year > date_year and not previous_next['year'][1]:
{'fraction_non_alphanumeric': 0.09629429266973222, 'fraction_numerical': 0.005409791723018664, 'mean_word_length': 2.198961937716263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1860020', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1042, 'n_words': 298}