from django import template

register = template.Library()

@register.filter
def get_player_status(tournament, user):
    return tournament.get_player_registration_status_by_licence(user)

@register.filter
def lookup(dictionary, key):
    """Template filter to lookup dictionary values by key"""
    return dictionary.get(key, '')

@register.filter
def array_lookup(array, index):
    """Template filter to lookup array values by index"""
    try:
        index = int(index)
        if 0 <= index < len(array):
            return array[index]
        return ''
    except (ValueError, TypeError, IndexError):
        return ''
