<commit_before>from django.conf import settings
from django.forms import widgets
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.forms.util import flatatt
from gmap_admin import settings as gmap_settings

class GoogleMapsWidget(widgets.HiddenInput):
    
	class Media:
		js = [
			'http://maps.google.com/maps/api/js?sensor=false',
			'gmap_admin/js/google-maps-admin.js',
	        ]

	def render(self, name, value, attrs=None):
		if value is None:
			value = ""
		final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
		if value != "":
			final_attrs['value'] = force_unicode(self._format_value(value))
		html = u"""
					<input%(attrs)s />
					<div class="map_canvas_wrapper" style="display:inline-block;">
						<div id="%(map_id)s" style="width:%(width)spx;height:%(height)spx"></div>
						<script>
							django.jQuery(function($) {
							    $("#%(field_id)s").gmapAdmin({
    							        'zoom': %(zoom)s,
    							        'lat': '%(center_lat)s',
    							        'lng': '%(center_lng)s',
    							        'map_elem': '#%(map_id)s',
    							        'delete_elem' : '#%(delete_id)s',
    							});
							});
						</script>
					</div>
					<p><a id="%(delete_id)s" href="javascript:void(0)">Remove Marker</a></p>
					<p class="help">Double click to zoom in and center on a location. Right click to set the marker on  a position. You can also drag and drop the marker</p>
				""" % { 
				        'field_id' : attrs['id'],
				        'delete_id' : 'map_delete_%s'%attrs['id'],
				        'map_id' : 'map_%s'%attrs['id'],
						'attrs' : flatatt(final_attrs),
						'height': gmap_settings.HEIGHT,
						'width': gmap_settings.WIDTH,
						'zoom' : gmap_settings.ZOOM,
						'center_lng' : gmap_settings.DEFAULT_LNG,
						'center_lat' : gmap_settings.DEFAULT_LAT,
					}
		return mark_safe(html)<commit_msg>make map centre on existing point, if there is one, instead of default centre<commit_after>from django.conf import settings
from django.forms import widgets
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.forms.util import flatatt
from gmap_admin import settings as gmap_settings


class GoogleMapsWidget(widgets.HiddenInput):
	
	class Media:
		js = [
			'http://maps.google.com/maps/api/js?sensor=false',
			'gmap_admin/js/google-maps-admin.js',
			]

	def render(self, name, value, attrs=None):
		if value is None:
			value = ""
			center_lng = gmap_settings.DEFAULT_LNG
			center_lat = gmap_settings.DEFAULT_LAT
		final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
		if value != "":
			final_attrs['value'] = force_unicode(self._format_value(value))
			center_lat,center_lng = final_attrs['value'].split(',')
		html = u"""
					<input%(attrs)s />
					<div class="map_canvas_wrapper" style="display:inline-block;">
						<div id="%(map_id)s" style="width:%(width)spx;height:%(height)spx"></div>
						<script>
							django.jQuery(function($) {
								$("#%(field_id)s").gmapAdmin({
										'zoom': %(zoom)s,
										'lat': '%(center_lat)s',
										'lng': '%(center_lng)s',
										'map_elem': '#%(map_id)s',
										'delete_elem': '#%(delete_id)s',
								});
							});
						</script>
					</div>
					<p><a id="%(delete_id)s" href="javascript:void(0)">Remove Marker</a></p>
					<p class="help">Double click to zoom in and center on a location. Right click to set the marker on a position. You can also drag and drop the marker.</p>
				""" % { 
						'field_id': attrs['id'],
						'delete_id': 'map_delete_%s'%attrs['id'],
						'map_id': 'map_%s'%attrs['id'],
						'attrs': flatatt(final_attrs),
						'height': gmap_settings.HEIGHT,
						'width': gmap_settings.WIDTH,
						'zoom': gmap_settings.ZOOM,
						'center_lng': center_lng,
						'center_lat': center_lat,
					}
		return mark_safe(html)
{'fraction_non_alphanumeric': 0.15728900255754474, 'fraction_numerical': 0.0005115089514066496, 'mean_word_length': 3.1963519313304722, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 29, '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': '2842876', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1335, 'n_words': 272}