<commit_before>from django import template
from django.conf import settings
from django.template import Context
from django.contrib.gis.geos import GEOSGeometry, Point

register = template.Library()


@register.filter
def fieldmap(obj, fieldname):
    """Usage: {{ object|fieldmap:"geom" }}"""
    name = "map%s%s" % (obj.__class__.__name__, fieldname)
    t = template.loader.get_template("mapentity/fieldmap_fragment.html")
    return t.render(Context(dict(
                    object=obj,
                    mapname=name)))


@register.filter
def latlngbounds(obj, fieldname='geom'):
    if obj is None or isinstance(obj, basestring):
        return 'null'
    if not isinstance(obj, GEOSGeometry):
        obj = getattr(obj, fieldname)
    if obj is None:
        return 'null'
    obj.transform(settings.API_SRID)
    if isinstance(obj, Point):
        extent = [obj.x-0.005, obj.y-0.005, obj.x+0.005, obj.y+0.005]
    else:
        extent = list(obj.extent)
    return [[extent[1], extent[0]], [extent[3], extent[2]]]<commit_msg>Restore context parameters since Context processors are not triggered in template tags<commit_after>from django import template
from django.conf import settings
from django.template import Context
from django.contrib.gis.geos import GEOSGeometry, Point

register = template.Library()


@register.filter
def fieldmap(obj, fieldname):
    """Usage: {{ object|fieldmap:"geom" }}"""
    name = "map%s%s" % (obj.__class__.__name__, fieldname)
    t = template.loader.get_template("mapentity/fieldmap_fragment.html")
    return t.render(Context(dict(
                    object=obj,
                    mapname=name,
                    # TODO: refactor, use {% with and include %} instead ! ContextProcessor have no effect with simple Context :(
                    LAYERCOLOR_PATHS=settings.LAYERCOLOR_PATHS,
                    LAYERCOLOR_LAND=settings.LAYERCOLOR_LAND,
                    LAYERCOLOR_OTHERS=settings.LAYERCOLOR_OTHERS)))


@register.filter
def latlngbounds(obj, fieldname='geom'):
    if obj is None or isinstance(obj, basestring):
        return 'null'
    if not isinstance(obj, GEOSGeometry):
        obj = getattr(obj, fieldname)
    if obj is None:
        return 'null'
    obj.transform(settings.API_SRID)
    if isinstance(obj, Point):
        extent = [obj.x-0.005, obj.y-0.005, obj.x+0.005, obj.y+0.005]
    else:
        extent = list(obj.extent)
    return [[extent[1], extent[0]], [extent[3], extent[2]]]
{'fraction_non_alphanumeric': 0.1195784353465748, 'fraction_numerical': 0.016214025131738953, 'mean_word_length': 3.0928689883913765, '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': '7196261', 'n_tokens_mistral': 790, 'n_tokens_neox': 750, 'n_words': 183}