diff --git a/.gitignore b/.gitignore index 8fe522d..fa8ad7e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ MANIFEST *.egg *.sqlite3 docs/_build/ +README.html +.idea diff --git a/AUTHORS b/AUTHORS index 2275d74..e72dfa8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,6 @@ +Author: +- Andras Gefferth, @kefirbandi + Original author: - Philipp Bosch, @philippbosch diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0a7613c..2b3fc2b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +Version 0.3.0.opt (2017-03-15) +============================== +Forked from 0.3.0 + +* Add hide_coords and get_address_line options + + Version 0.3.0 (2016-08-05) ========================== diff --git a/README.rst b/README.rst index e08ce2d..70738b8 100644 --- a/README.rst +++ b/README.rst @@ -1,18 +1,10 @@ -================== -django-geoposition -================== +========================== +django-geoposition-options +========================== A model field that can hold a geoposition (latitude/longitude), and corresponding admin/form widget. - -.. image:: https://badge.fury.io/py/django-geoposition.svg - :target: https://badge.fury.io/py/django-geoposition - -.. image:: https://travis-ci.org/philippbosch/django-geoposition.svg?branch=master - :target: https://travis-ci.org/philippbosch/django-geoposition - -.. image:: https://badges.gitter.im/philippbosch/django-geoposition.svg - :alt: Join the chat at https://gitter.im/philippbosch/django-geoposition - :target: https://gitter.im/philippbosch/django-geoposition?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +A fork of django-geoposition version 0.3. Added two optional parameters to the form field allowing to hide the +lat/lon fields from the user and allowing to display and return the textual address. (See below for details) Prerequisites ------------- @@ -102,7 +94,13 @@ just a little more work. In your template make sure that - the static files (JS, CSS) of the map widget are included (just use ``{{ form.media }}``) -**Example**:: +Example +....... + + + + +- In your ``myapp/templates/geoposition_example.html``::
{% csrf_token %} @@ -111,6 +109,36 @@ just a little more work. In your template make sure that
+- In your ``myapp/views.py``:: + + from geoposition.forms import GeopositionField + from decimal import Decimal + + class GMForm(forms.Form): + pos = GeopositionField() + + + def geoposition_example(request): + + if request.method == 'POST': + form = GMForm(request.POST) + if form.is_valid(): + + # Form field returns a list of length 2 of Decimals: + coordinates = form.cleaned_data['pos'] #e.g. [Decimal(1.23), Decimal(2.34)] + + # From which you can create a geoposition object, if you want to: + position = Geoposition(*coordinates) + do_my_function(position.latitude, position.longitude) + + return HttpResponseRedirect(reverse('geoposition_example')) + + else: + form = GMForm(initial={'pos':Geoposition(Decimal(45.6),Decimal(12.3))}) + + return render(request, 'geoposition_example.html', {'form':form}) + + Settings -------- @@ -118,6 +146,9 @@ You can customize the `MapOptions`_ and `MarkerOptions`_ used to initialize the map and marker in JavaScript by defining ``GEOPOSITION_MAP_OPTIONS`` or ``GEOPOSITION_MARKER_OPTIONS`` in your ``settings.py``. +Display settings +^^^^^^^^^^^^^^^^ + **Example**:: GEOPOSITION_MAP_OPTIONS = { @@ -137,6 +168,21 @@ string in the JavaScript code and not be evaluated. Please use You can also customize the height of the displayed map widget by setting ``GEOPOSITION_MAP_WIDGET_HEIGHT`` to an integer value (default is 480). +Form field options +^^^^^^^^^^^^^^^^^^ + +The geoposition.forms.GeopositionField has two optional keyword arguments. +If called as ``GeopositionField(hide_coords=True)`` then the widget will not display the Latitude and Longitude fields, +but the value of these fields will still be returned by the form. + +The other optional argument of ``GeopositionField`` is ``get_address_line``. If set to ``True``, then the textual +address of the location is retrieved from GMaps, displayed on the screen and returned as a third item of the return +value of the form field. In other words if in the above example the ``GMForm`` class is defined as: + + class GMForm(forms.Form): + pos = GeopositionField(get_address_line=True) + +then ``form.cleaned_data['pos']`` is a list of 3, with the third element being the textual address. License ------- diff --git a/docs/conf.py b/docs/conf.py index 2dd7aaf..03b16dc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,16 +44,16 @@ # General information about the project. project = u'django-geoposition' -copyright = u'2011, Philipp Bosch' +copyright = u'2011, Philipp Bosch; 2017, Andras Gefferth' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '0.1' +version = '0.3.0.opt' # The full version, including alpha/beta/rc tags. -release = '0.1.4' +release = '0.3.0.opt' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -182,7 +182,7 @@ # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'django-geoposition.tex', u'django-geoposition Documentation', - u'Philipp Bosch', 'manual'), + u'Andras Gefferth', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -215,7 +215,7 @@ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'django-geoposition', u'django-geoposition Documentation', - [u'Philipp Bosch'], 1) + [u'Andras Gefferth'], 1) ] @@ -223,9 +223,9 @@ # Bibliographic Dublin Core info. epub_title = u'django-geoposition' -epub_author = u'Philipp Bosch' -epub_publisher = u'Philipp Bosch' -epub_copyright = u'2011, Philipp Bosch' +epub_author = u'Philipp Bosch; Andras Gefferth' +epub_publisher = u'Philipp Bosch; Andras Gefferth' +epub_copyright = u'2011, Philipp Bosch; 2017 Andras Gefferth' # The language of the text. It defaults to the language option # or en if the language is not set. diff --git a/geoposition/__init__.py b/geoposition/__init__.py index eafb2f2..5acfc3f 100644 --- a/geoposition/__init__.py +++ b/geoposition/__init__.py @@ -3,7 +3,7 @@ default_app_config = 'geoposition.apps.GeoPositionConfig' -VERSION = (0, 3, 0) +VERSION = (0, 3, 0, 'opt') __version__ = '.'.join(map(str, VERSION)) diff --git a/geoposition/forms.py b/geoposition/forms.py index 02c4954..9327a9a 100644 --- a/geoposition/forms.py +++ b/geoposition/forms.py @@ -13,11 +13,16 @@ class GeopositionField(forms.MultiValueField): } def __init__(self, *args, **kwargs): - self.widget = GeopositionWidget() - fields = ( + + get_address_line = kwargs.pop('get_address_line', False) + self.widget = GeopositionWidget({'hide_coords':kwargs.pop('hide_coords', False), + 'get_address_line':get_address_line}) + fields = [ forms.DecimalField(label=_('latitude')), forms.DecimalField(label=_('longitude')), - ) + ] + if get_address_line: + fields.append(forms.CharField()) if 'initial' in kwargs: kwargs['initial'] = Geoposition(*kwargs['initial'].split(',')) super(GeopositionField, self).__init__(fields, **kwargs) diff --git a/geoposition/static/geoposition/geoposition.js b/geoposition/static/geoposition/geoposition.js index ec5df01..0ae2665 100644 --- a/geoposition/static/geoposition/geoposition.js +++ b/geoposition/static/geoposition/geoposition.js @@ -32,6 +32,7 @@ if (jQuery != undefined) { var $container = $(this), $mapContainer = $('
'), $addressRow = $('
'), + $addressRow2 = $container.find('input.geoposition:eq(2)'), $searchRow = $('