from django import template
from django.utils.safestring import mark_safe
from django.core.cache import cache
from .utils_extra import picto_from_name

from agenda_culturel.models import ReferenceLocation

register = template.Library()


@register.simple_tag
def show_suggested_positions(filter):
    filter.form.full_clean()

    if filter.is_filtered_by_position_radius():
        return ""
    

    locations = ReferenceLocation.objects.all().filter(suggested_distance__isnull=False).order_by("main", "name")
    
    result = ''
    for l in locations:
        result += ' <a class="small-location" role="button" href="' + filter.get_url_add_suggested_position(l) + '">' + picto_from_name("map-pin") + ' ' + l.name + ' ' + str(l.suggested_distance) + 'km</a>'

    return mark_safe(result)
