Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions geoposition/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

from django.db import models
from django.utils.six import with_metaclass
from six import with_metaclass
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text

Expand Down Expand Up @@ -47,7 +47,7 @@ def get_prep_value(self, value):
return str(value)

def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
value = self.value_from_object(obj)
return smart_text(value)

def formfield(self, **kwargs):
Expand Down
25 changes: 5 additions & 20 deletions geoposition/static/geoposition/geoposition.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.geoposition-widget {
overflow: hidden;
/* overflow: hidden;*/
font-weight: bold;
}

.geoposition-map {
Expand All @@ -8,21 +9,10 @@
clear: both;
}

.geoposition-widget table {
float: left;
border: 0;
margin-bottom: 8px;
}

.geoposition-widget td {
border: 0;
padding: 0;
padding-right: 5px;
vertical-align: middle;
}

.geoposition-search {
width: 30%;
float: right;
padding-right: 15px;
}

.geoposition-search input {
Expand All @@ -31,12 +21,7 @@

.geoposition-address {
float: left;
text-align: left;
}

.geoposition-search {
float: right;
text-align: left;
line-height: 200%;
}

.geoposition-results {
Expand Down
4 changes: 2 additions & 2 deletions geoposition/static/geoposition/geoposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (jQuery != undefined) {
$mapContainer = $('<div class="geoposition-map" />'),
$addressRow = $('<div class="geoposition-address" />'),
$searchRow = $('<div class="geoposition-search" />'),
$searchInput = $('<input>', {'type': 'search', 'placeholder': 'Start typing an address …'}),
$searchInput = $('<input>', {'type': 'text', 'placeholder': 'Start typing an address …'}),
$latitudeField = $container.find('input.geoposition:eq(0)'),
$longitudeField = $container.find('input.geoposition:eq(1)'),
latitude = parseFloat($latitudeField.val()) || null,
Expand Down Expand Up @@ -120,7 +120,7 @@ if (jQuery != undefined) {
$(this).parent().find('ul.geoposition-results').remove();
});
$searchInput.appendTo($searchRow);
$container.append($searchRow, $mapContainer, $addressRow);
$container.append($searchRow, $addressRow, $mapContainer);

mapLatLng = new google.maps.LatLng(latitude, longitude);

Expand Down
19 changes: 7 additions & 12 deletions geoposition/templates/geoposition/widgets/geoposition.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<div class="geoposition-widget" data-map-widget-height="{{ config.map_widget_height }}" data-map-options="{{ config.map_options }}" data-marker-options="{{ config.marker_options }}">
<table>
<tr>
<td>{{ latitude.label|capfirst }}</td>
<td>{{ latitude.html }}</td>
</tr>
<tr>
<td>{{ longitude.label|capfirst }}</td>
<td>{{ longitude.html }}</td>
</tr>
</table>
</div>
<p class="geoposition-widget" data-map-widget-height="{{ widget.config.map_widget_height }}" data-map-options='{{ widget.config.map_options }}' data-marker-options='{{ widget.config.marker_options }}'>
{{ widget.latitude.label|capfirst }}:
<input type="text" name="position_0" class="geoposition" value="{{ widget.latitude.html }}" />
{{ widget.longitude.label|capfirst }}:
<input type="text" name="position_1" class="geoposition" value="{{ widget.longitude.html }}" />
<br/>
</p>
34 changes: 21 additions & 13 deletions geoposition/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@
import json
from django import forms
from django.template.loader import render_to_string
from django.utils import six
import six
from django.utils.translation import ugettext_lazy as _
from .conf import settings


class GeopositionWidget(forms.MultiWidget):
template_name = 'geoposition/widgets/geoposition.html'

def __init__(self, attrs=None):
widgets = (
forms.TextInput(),
forms.TextInput(),
)
super(GeopositionWidget, self).__init__(widgets, attrs)

def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
if not isinstance(value, list):
value = self.decompress(value)

def decompress(self, value):
if isinstance(value, six.text_type):
return value.rsplit(',')
if value:
return [value.latitude, value.longitude]
return [None, None]

def format_output(self, rendered_widgets):
return render_to_string('geoposition/widgets/geoposition.html', {
context['widget'] = {
'latitude': {
'html': rendered_widgets[0],
'html': value[0],
'label': _("latitude"),
},
'longitude': {
'html': rendered_widgets[1],
'html': value[1],
'label': _("longitude"),
},
'config': {
'map_widget_height': settings.MAP_WIDGET_HEIGHT or 500,
'map_options': json.dumps(settings.MAP_OPTIONS),
'marker_options': json.dumps(settings.MARKER_OPTIONS),
}
})
}
return context

def decompress(self, value):
if isinstance(value, six.text_type):
return value.rsplit(',')
if value:
return [value.latitude, value.longitude]
return [None, None]


class Media:
js = (
Expand Down