<commit_before>from django import template
from django.db.models.query_utils import Q
from django.template.defaultfilters import stringfilter
from vpw.models import Material
from vpw.vpr_api import vpr_materials_by_author, vpr_get_favorite

register = template.Library()


@register.filter(is_safe=True)
@stringfilter
def normalize_string(value):
    """
    Converts to lowercase, removes non-word characters but still keep alphanumerics
    and converts spaces to hyphens. Also strips leading and trailing whitespace.
    Also converts vietnamese characters.
    """
    from vpw.utils import normalize_string
    return normalize_string(value)


@register.filter
@stringfilter
def break_keywords(value):
    """ Replace CR-LF in string value by comma character """
    return ', '.join(value.split('\n'))


@register.filter
@stringfilter
def strip(value):
    """ Replace CR-LF in string value by comma character """
    return value.strip()


@register.filter
@stringfilter
def get_unpublished_count(uid):
    stats_count = ''

    materials = Material.objects.filter(Q(creator_id=uid) & (Q(version=None) | Q(version=0)))
    stats_count = len(materials)

    if stats_count:
        return ' (%s)' % stats_count

    return


@register.filter
@stringfilter
def get_published_count(pid):
    stats_count = ''

    published_items = vpr_materials_by_author(pid)
    stats_count = published_items['count']

    if stats_count:
        return ' (%s)' % stats_count

    return


@register.filter
@stringfilter
def get_favorites_count(pid):
    stats_count = ''

    favorites = vpr_get_favorite(pid)
    stats_count = favorites['count']

    if stats_count:
        return ' (%s)' % stats_count

    return
<commit_msg>fixbug show number None<commit_after>from django import template
from django.db.models.query_utils import Q
from django.template.defaultfilters import stringfilter
from vpw.models import Material
from vpw.vpr_api import vpr_materials_by_author, vpr_get_favorite

register = template.Library()


@register.filter(is_safe=True)
@stringfilter
def normalize_string(value):
    """
    Converts to lowercase, removes non-word characters but still keep alphanumerics
    and converts spaces to hyphens. Also strips leading and trailing whitespace.
    Also converts vietnamese characters.
    """
    from vpw.utils import normalize_string
    return normalize_string(value)


@register.filter
@stringfilter
def break_keywords(value):
    """ Replace CR-LF in string value by comma character """
    return ', '.join(value.split('\n'))


@register.filter
@stringfilter
def strip(value):
    """ Replace CR-LF in string value by comma character """
    return value.strip()


@register.filter
@stringfilter
def get_unpublished_count(uid):
    materials = Material.objects.filter(Q(creator_id=uid) & (Q(version=None) | Q(version=0)))
    stats_count = len(materials)

    if stats_count is None:
        stats_count = 0

    return ' (%s)' % stats_count


@register.filter
@stringfilter
def get_published_count(pid):
    published_items = vpr_materials_by_author(pid)
    stats_count = published_items['count']

    if stats_count is None:
        stats_count = 0

    return ' (%s)' % stats_count


@register.filter
@stringfilter
def get_favorites_count(pid):
    favorites = vpr_get_favorite(pid)
    stats_count = favorites['count']

    if stats_count is None:
        stats_count = 0

    return ' (%s)' % stats_count

{'fraction_non_alphanumeric': 0.09374090247452693, 'fraction_numerical': 0.001455604075691412, 'mean_word_length': 4.1437125748503, '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': '6178712', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1011, 'n_words': 275}