<commit_before>from django import template
from django.core.urlresolvers import reverse
from survey.interviewer_configs import MONTHS
from survey.models.helper_constants import CONDITIONS
from survey.utils.views_helper import get_ancestors
from survey.models import Survey, Question, Batch, Interviewer, MultiChoiceAnswer, \
    GroupCondition, Answer, AnswerAccessDefinition, ODKAccess, HouseholdMember
from survey.odk.utils.log import logger
from django.core.exceptions import ObjectDoesNotExist
from django.utils.safestring import mark_safe
from dateutils import relativedelta
from datetime import date
import json, inspect
from django.utils import html

register = template.Library()

@register.filter
def next(value, arg):
    try:
        return value[int(arg)+1]
    except:
        return None

@register.filter
def space_replace(value, search_string):
    return value.replace(search_string, ' ')


@register.filter
def is_location_selected(locations_data, location):
    if locations_data.has_location_selected(location):
        return "selected='selected'"

@register.filter
def is_ea_selected(locations_data, ea):
    if locations_data.selected_ea == ea:
        return "selected='selected'"


@register.filter
def is_selected(batch, selected_batch):
    if batch == selected_batch:
        return "selected='selected'"

@register.filter
def is_batch_open_for_location(open_locations, location):
    if location in open_locations:
        return "checked='checked'"

@register.filter
def is_mobile_number(field):
    return 'mobile number' in field.lower()

@register.filter
def is_radio(field):
    if "radio" in str(field) and not "select" in str(field):
        return "radio_field"
    return ""

@register.filter
def display_list(list):
    new_list = [str(item) for item in list]
    return mark_safe(', '.join(new_list))

@register.filter
def join_list(list, delimiter):
    new_list = ['<span class="muted">%s</span>' % str(item) for item in list]
    return mark_safe(delimiter.join(new_list))

@register.filter
def get_value(dict, key):
    return dict.get(key, "")

@register.filter
def batches_enabled(survey, ea):
    return 'Enabled' if survey.batches_enabled(ea) else 'Not Enabled'

@register.filter
def get_month(index):
    if not str(index).isdigit() and not index :
        return "N/A"
    return MONTHS[int(index)][1]

@register.filter
def format_date(date):
    if date:
        return date.strftime("%b %d, %Y")

@register.filter
def get_age(d):
    return relativedelta(date.today() - d).years


@register.filter
def get_url_with_ids(args, url_name):
    if not str(args).isdigit():
      arg_list = [int(arg) for arg in args.split(',')]
      return reverse(url_name, args=arg_list)
    return reverse(url_name, args=(args,))    

@register.filter
def get_url_without_ids(url_name):
    return reverse(url_name)    

@register.filter
def add_string(int_1, int_2):
    return "%s, %s"%(str(int_1), str(int_2))

@register.filter
def condition_text(key):
    value = CONDITIONS.get(key, "")
    return value

@register.filter
def modulo(num, val):
    return num % val == 0
<commit_msg>household age not coming fixed<commit_after>from django import template
from django.core.urlresolvers import reverse
from survey.interviewer_configs import MONTHS
from survey.models.helper_constants import CONDITIONS
from survey.utils.views_helper import get_ancestors
from survey.models import Survey, Question, Batch, Interviewer, MultiChoiceAnswer, \
    GroupCondition, Answer, AnswerAccessDefinition, ODKAccess, HouseholdMember
from survey.odk.utils.log import logger
from django.core.exceptions import ObjectDoesNotExist
from django.utils.safestring import mark_safe
from dateutil import relativedelta
from datetime import date
import json, inspect
from django.utils import html

register = template.Library()

@register.filter
def next(value, arg):
    try:
        return value[int(arg)+1]
    except:
        return None

@register.filter
def space_replace(value, search_string):
    return value.replace(search_string, ' ')


@register.filter
def is_location_selected(locations_data, location):
    if locations_data.has_location_selected(location):
        return "selected='selected'"

@register.filter
def is_ea_selected(locations_data, ea):
    if locations_data.selected_ea == ea:
        return "selected='selected'"


@register.filter
def is_selected(batch, selected_batch):
    if batch == selected_batch:
        return "selected='selected'"

@register.filter
def is_batch_open_for_location(open_locations, location):
    if location in open_locations:
        return "checked='checked'"

@register.filter
def is_mobile_number(field):
    return 'mobile number' in field.lower()

@register.filter
def is_radio(field):
    if "radio" in str(field) and not "select" in str(field):
        return "radio_field"
    return ""

@register.filter
def display_list(list):
    new_list = [str(item) for item in list]
    return mark_safe(', '.join(new_list))

@register.filter
def join_list(list, delimiter):
    new_list = ['<span class="muted">%s</span>' % str(item) for item in list]
    return mark_safe(delimiter.join(new_list))

@register.filter
def get_value(dict, key):
    return dict.get(key, "")

@register.filter
def batches_enabled(survey, ea):
    return 'Enabled' if survey.batches_enabled(ea) else 'Not Enabled'

@register.filter
def get_month(index):
    if not str(index).isdigit() and not index :
        return "N/A"
    return MONTHS[int(index)][1]

@register.filter
def format_date(date):
    if date:
        return date.strftime("%b %d, %Y")

@register.filter
def get_age(d):
    return relativedelta.relativedelta(date.today(), d).years


@register.filter
def get_url_with_ids(args, url_name):
    if not str(args).isdigit():
      arg_list = [int(arg) for arg in args.split(',')]
      return reverse(url_name, args=arg_list)
    return reverse(url_name, args=(args,))    

@register.filter
def get_url_without_ids(url_name):
    return reverse(url_name)    

@register.filter
def add_string(int_1, int_2):
    return "%s, %s"%(str(int_1), str(int_2))

@register.filter
def condition_text(key):
    value = CONDITIONS.get(key, "")
    return value

@register.filter
def modulo(num, val):
    return num % val == 0

{'fraction_non_alphanumeric': 0.10923297719661935, 'fraction_numerical': 0.002232498804018498, 'mean_word_length': 4.610017889087657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3088319', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1971, 'n_words': 514}