<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009  <NAME>  <<EMAIL>>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# See the file COPYING for details.

"""
Extra widgets and fields
"""

from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

from www import settings

class AreaWidget(forms.TextInput):
    """
    Manage the edition of an area on the map
    """
    def render(self, name, value, attrs=None):
        """
        Render the bbox selection widget.
        """
        # Initially the widget shows no bounding box and shows an area that
        # contains the France
        if value:
            upper_left_lat, upper_left_lon, \
                lower_right_lat, lower_right_lon = value
        else:
            upper_left_lat, upper_left_lon, \
                lower_right_lat, lower_right_lon = settings.BASE_BOUNDING_BOX

        tpl = u"""<div id="step-location-map"></div>
        <div class="row-fluid step-location-map-bbox">
          <div class="span12">
            <input type="text" name="lat_upper_left" id="id_lat_upper_left"
                   value="%(tl_lat)s" title="%(tl_lat_help)s" />
            &middot;
            <input type="text" name="lon_upper_left" id="id_lon_upper_left"
                   value="%(tl_lon)s" title="%(tl_lon_help)s" />
            &nbsp;&rarr;&nbsp;
            <input type="text" name="lat_bottom_right" id="id_lat_bottom_right"
                   value="%(br_lat)s" title="%(br_lat_help)s" />
            &middot;
            <input type="text" name="lon_bottom_right" id="id_lon_bottom_right"
                   value="%(br_lon)s" title="%(br_lon_help)s" />
          </div>
        </div>
        <div id="area-size-alert" class="alert alert-error">%(alert)s</div>
        """ % {'tl_lat': upper_left_lat, 'tl_lon': upper_left_lon,
                   'br_lat': lower_right_lat, 'br_lon': lower_right_lon,
                   'tl_lat_help': _('Latitude of the top left corner'),
                   'tl_lon_help': _('Longitude of the top left corner'),
                   'br_lat_help': _('Latitude of the bottom right corner'),
                   'br_lon_help': _('Longitude of the bottom right corner'),
                   'alert': _('<p/>&nbsp;</p><span class="alert alert-danger"><i class="glyphicon glyphicon-warning-sign"></i>&nbsp;&nbsp; Area too big to be rendered!</span>'),
                   'clear': _('Remove any selected region from the map')
                  }

        return mark_safe(tpl)

    def value_from_datadict(self, data, files, name):<commit_msg>split glyphicon from translatable string<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009  <NAME>  <etienne.loks_AT_peacefrogsDOTnet>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# See the file COPYING for details.

"""
Extra widgets and fields
"""

from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

from www import settings

class AreaWidget(forms.TextInput):
    """
    Manage the edition of an area on the map
    """
    def render(self, name, value, attrs=None):
        """
        Render the bbox selection widget.
        """
        # Initially the widget shows no bounding box and shows an area that
        # contains the France
        if value:
            upper_left_lat, upper_left_lon, \
                lower_right_lat, lower_right_lon = value
        else:
            upper_left_lat, upper_left_lon, \
                lower_right_lat, lower_right_lon = settings.BASE_BOUNDING_BOX

        alert = '<i class="glyphicon glyphicon-warning-sign"></i>&nbsp;&nbsp;%s' % _('Area too big to be rendered!')

        tpl = u"""<div id="step-location-map"></div>
        <div class="row-fluid step-location-map-bbox">
          <div class="span12">
            <input type="text" name="lat_upper_left" id="id_lat_upper_left"
                   value="%(tl_lat)s" title="%(tl_lat_help)s" />
            &middot;
            <input type="text" name="lon_upper_left" id="id_lon_upper_left"
                   value="%(tl_lon)s" title="%(tl_lon_help)s" />
            &nbsp;&rarr;&nbsp;
            <input type="text" name="lat_bottom_right" id="id_lat_bottom_right"
                   value="%(br_lat)s" title="%(br_lat_help)s" />
            &middot;
            <input type="text" name="lon_bottom_right" id="id_lon_bottom_right"
                   value="%(br_lon)s" title="%(br_lon_help)s" />
          </div>
        </div>
        <div id="area-size-alert" class="alert alert-danger">%(alert)s</div>
        """ % {'tl_lat': upper_left_lat, 'tl_lon': upper_left_lon,
                   'br_lat': lower_right_lat, 'br_lon': lower_right_lon,
                   'tl_lat_help': _('Latitude of the top left corner'),
                   'tl_lon_help': _('Longitude of the top left corner'),
                   'br_lat_help': _('Latitude of the bottom right corner'),
                   'br_lon_help': _('Longitude of the bottom right corner'),
                   'alert': alert,
                   'clear': _('Remove any selected region from the map')
                  }

        return mark_safe(tpl)

    def value_from_datadict(self, data, files, name):
{'fraction_non_alphanumeric': 0.1137973514012935, 'fraction_numerical': 0.0024638127502309825, 'mean_word_length': 2.57064321055525, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3069921', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1885, 'n_words': 579}