<commit_before>from django.conf import settings
from django.contrib.gis.geos import GEOSException, fromstr

import floppyforms as forms


class LeafletMapWidget(forms.gis.BaseGeometryWidget):
    template_name = 'core/formfieldmap_fragment.html'
    display_wkt = settings.DEBUG

    def value_from_datadict(self, data, files, name):
        wkt = super(LeafletMapWidget, self).value_from_datadict(data, files, name)
        if not wkt:
            return None
        try:
            geom = fromstr(wkt, srid=self.settings.API_SRID)
            geom.transform(settings.SRID)
            dim = 3
            extracoords = ' 0.0' * (dim - 2)  # add missing dimensions
            wkt3d = geom.wkt.replace(',', extracoords + ',')
            return wkt3d
        except (GEOSException, TypeError, ValueError):
            return None

    def get_context(self, name, value, attrs=None, extra_context={}):
        context = super(LeafletMapWidget, self).get_context(name, value, attrs, extra_context)
        # Be careful, on form error, value is not a GEOSGeometry
        if value and not isinstance(value, basestring):
            value.transform(settings.API_SRID)
        context['update'] = bool(value)
        context['field'] = value
        context['fitextent'] = value is None
        return context<commit_msg>Oh, the bullet :)<commit_after>from django.conf import settings
from django.contrib.gis.geos import GEOSException, fromstr

import floppyforms as forms


class LeafletMapWidget(forms.gis.BaseGeometryWidget):
    template_name = 'core/formfieldmap_fragment.html'
    display_wkt = settings.DEBUG

    def value_from_datadict(self, data, files, name):
        wkt = super(LeafletMapWidget, self).value_from_datadict(data, files, name)
        if not wkt:
            return None
        try:
            geom = fromstr(wkt, srid=settings.API_SRID)
            geom.transform(settings.SRID)
            dim = 3
            extracoords = ' 0.0' * (dim - 2)  # add missing dimensions
            wkt3d = geom.wkt.replace(',', extracoords + ',')
            return wkt3d
        except (GEOSException, TypeError, ValueError):
            return None

    def get_context(self, name, value, attrs=None, extra_context={}):
        context = super(LeafletMapWidget, self).get_context(name, value, attrs, extra_context)
        # Be careful, on form error, value is not a GEOSGeometry
        if value and not isinstance(value, basestring):
            value.transform(settings.API_SRID)
        context['update'] = bool(value)
        context['field'] = value
        context['fitextent'] = value is None
        return context
{'fraction_non_alphanumeric': 0.09556313993174062, 'fraction_numerical': 0.004550625711035267, 'mean_word_length': 2.710267229254571, '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': '1271013', 'n_tokens_mistral': 797, 'n_tokens_neox': 782, 'n_words': 198}