<commit_before>import datetime
from itertools import chain

from django import template
from django.conf import settings
from django.utils.encoding import force_text
from django.utils.timesince import timesince
from django.utils.safestring import mark_safe

from articles.models import Article
from photos.models import Gallery
from video.models import Video

register = template.Library()


@register.inclusion_tag('includes/formatted_time.html')
def format_time(date_obj, time_obj=None, datebox=False, dt_type=None):
    """
    Returns formatted HTML5 elements based on given datetime object.
    By default returns a time element, but will return a .datebox if requested.

    dt_type allows passing dt_start or dt_end for hcal formatting.
    link allows passing a url to the datebox.

    Usage:
    {% format_time obj.pub_date %}
    {% format_time obj.start_date 'datebox' 'dtstart' %}
    {% format_time obj.end_date obj.end_time 'datebox' 'dt_end' %}
    """
    if not time_obj:
        try:
            time_obj = date_obj.time
        except:
            time_obj = None
    return {
        'date_obj': date_obj,
        'time_obj': time_obj,
        'datebox': datebox,
        'current_year': datetime.date.today().year,
        'dt_type': dt_type,
    }


@register.filter
def short_timesince(date):
    """
    A shorter version of Django's built-in timesince filter.
    Selects only the first part of the returned string,
    splitting on the comma.

    Falls back on default Django timesince if it fails.

    Example: 3 days, 20 hours becomes "3 days".

    """
    try:
        return timesince(date).split(", ")[0]
    except IndexError():
        timesince(date)


@register.filter
def fix_indents(value):
    """
    Strips tabs and extra spaces from user-submitted text
    to avoid triggering pre code in markdown.

    Use this with caution.
    It's much better to sanitize the content before save().

    Likely to be replaced by a smarter minification.
    """
    value = value.replace('\t', '').replace('    ', ' ')<commit_msg>Cleanup<commit_after>import datetime
from itertools import chain

from django import template
from django.conf import settings
from django.utils.encoding import force_text
from django.utils.timesince import timesince
from django.utils.safestring import mark_safe

from articles.models import Article
from photos.models import Gallery
from video.models import Video

register = template.Library()


@register.inclusion_tag('includes/formatted_time.html')
def format_time(date_obj, time_obj=None, datebox=False, dt_type=None):
    """
    Returns formatted HTML5 elements based on given datetime object.
    By default returns a time element, but will return a .datebox if requested.

    dt_type allows passing dt_start or dt_end for hcal formatting.
    link allows passing a url to the datebox.

    Usage:
    {% format_time obj.pub_date %}
    {% format_time obj.start_date 'datebox' 'dtstart' %}
    {% format_time obj.end_date obj.end_time 'datebox' 'dt_end' %}
    """
    if not time_obj:
        time_obj = getattr(date_obj.time, None)

    return {
        'date_obj': date_obj,
        'time_obj': time_obj,
        'datebox': datebox,
        'current_year': datetime.date.today().year,
        'dt_type': dt_type,
    }


@register.filter
def short_timesince(date):
    """
    A shorter version of Django's built-in timesince filter.
    Selects only the first part of the returned string,
    splitting on the comma.

    Falls back on default Django timesince if it fails.

    Example: 3 days, 20 hours becomes "3 days".

    """
    try:
        return timesince(date).split(", ")[0]
    except IndexError:
        timesince(date)


@register.filter
def fix_indents(value):
    """
    Strips tabs and extra spaces from user-submitted text
    to avoid triggering pre code in markdown.

    Use this with caution.
    It's much better to sanitize the content before save().

    Likely to be replaced by a smarter minification.
    """
    value = value.replace('\t', '').replace('    ', ' ')
{'fraction_non_alphanumeric': 0.08744780152296733, 'fraction_numerical': 0.0029476787030213707, 'mean_word_length': 3.1721311475409837, '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': '1871042', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1170, 'n_words': 411}