simon-the-shark / django-mapbox-location-field

Simple in use location model and form field with MapInput widget for picking some location. Uses mapbox gl js, flexible map provider API. Fully compatible with bootstrap framework. Can be used with spatial or plain databases.
MIT License
66 stars 23 forks source link

ValueError, could not convert string to float #5

Closed MaxDragonheart closed 5 years ago

MaxDragonheart commented 5 years ago

Here I describe my problem. Maybe it is a bug?

This is the traceback: Environment:

Request Method: POST Request URL: http://127.0.0.1:8000/geomonitor/add/illegal-dump-map/

Django Version: 2.2.5 Python Version: 3.6.8 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.sitemaps', 'django.contrib.flatpages', 'django.contrib.gis', 'blog', 'geomodels', 'geosources', 'kernel', 'sitemapgenerator', 'usermanager', 'django_summernote', 'mapbox_location_field'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware']

Template error: In template /home/max/Django/gealogos/gealogos_dev/gealogos/geosources/templates/geosources/base_map.html, error at line 0 could not convert string to float: '6.01245266838146,-10.16992187499897' 1 : {% load static %} 2 : <!doctype html> 3 : 4 : 5 : {% include 'google.html' %} 6 : 7 : 8 : 9 : {% block head_title %}GeaLogos{% endblock head_title %} 10 :

Traceback:

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/max/Django/gealogos/gealogos_dev/gealogos/geomodels/views.py" in add_illegal_dump

  1. return render(request, template, context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/shortcuts.py" in render

  1. content = loader.render_to_string(template_name, context, request, using=using)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/loader.py" in render_to_string

  1. return template.render(context, request)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/backends/django.py" in render

  1. return self.template.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render

  1. return self._render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render

  1. bit = node.render_annotated(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render_annotated

  1. return self.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/loader_tags.py" in render

  1. return compiled_parent._render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in _render

  1. return self.nodelist.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render

  1. bit = node.render_annotated(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render_annotated

  1. return self.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/loader_tags.py" in render

  1. result = block.nodelist.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render

  1. bit = node.render_annotated(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render_annotated

  1. return self.render(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in render

  1. output = self.filter_expression.resolve(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in resolve

  1. obj = self.var.resolve(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in resolve

  1. value = self._resolve_lookup(context)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/template/base.py" in _resolve_lookup

  1. current = current()

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/forms/forms.py" in as_p

  1. errors_on_separate_row=True,

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/forms/forms.py" in _html_output

  1. 'field_name': bf.html_name,

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/utils/html.py" in

  1. klass.str = lambda self: mark_safe(klass_str(self))

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/forms/boundfield.py" in str

  1. return self.as_widget()

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/django/forms/boundfield.py" in as_widget

  1. renderer=self.form.renderer,

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/mapbox_location_field/widgets.py" in render

  1. rend += self.get_config_settings()

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/mapbox_location_field/widgets.py" in get_config_settings

  1. default_map_attrs["center"] = parse_tuple_string(self.center_point)

File "/home/max/Django/gealogos/devenv/lib/python3.6/site-packages/mapbox_location_field/widgets.py" in parse_tuple_string

  1. return tuple(map(float, tuple_string[1:-1].split(", ")))

Exception Type: ValueError at /geomonitor/add/illegal-dump-map/ Exception Value: could not convert string to float: '6.01245266838146,-10.16992187499897'

simon-the-shark commented 5 years ago

I will look on it, when I end my deadline project

aitoehigie commented 5 years ago

Hello @MaxDragonheart I have also had this issue and its actually a bug. Edit line 6 of this file: mapbox_location_field/widgets.py and change it to:

def parse_tuple_string(tuple_string): return tuple(map(float, tuple_string[1:-1].split(",")))

That fixes it. I think i should send in a PR

aitoehigie commented 5 years ago

@Simon-the-Shark I have opened a PR that resolves the problem. https://github.com/Simon-the-Shark/django-mapbox-location-field/pull/7

MaxDragonheart commented 5 years ago

Thanks @aitoehigie :)

MaxDragonheart commented 5 years ago

Now, as long as @Simon-the-Shark doesn't solve the bug I cant use the packcage? Now I've no problem on my project but it is in local and not yet online. What do you suggest @aitoehigie ?

aitoehigie commented 5 years ago

You can clone it, effect the change to your own copy of the clone. So whenever you want to use the library you can pip install git+[URL to you own repo] Till he merges the PR containing the fix into the main branch.

Does that make sense?

On Mon, 28 Oct 2019, 09:59 Massimiliano Moraca, notifications@github.com wrote:

Now, as long as @Simon-the-Shark https://github.com/Simon-the-Shark doesn't solve the bug I cant use the packcage? Now I've no problem on my project but it is in local and not yet online. What do you suggest @aitoehigie https://github.com/aitoehigie ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Simon-the-Shark/django-mapbox-location-field/issues/5?email_source=notifications&email_token=AABPDWCG5FCI6D7Q6PN7IR3QQ2SXPA5CNFSM4JASESNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECME4IA#issuecomment-546852384, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABPDWD4MCC7J4O2AEM6BPDQQ2SXPANCNFSM4JASESNA .

MaxDragonheart commented 5 years ago

I think that yours is a good method. I'm not an expert, it's the first time for me to use my personal repository with Django but I can try :)

aitoehigie commented 5 years ago

Let me know if it works for you.

On Mon, Oct 28, 2019 at 7:23 PM Massimiliano Moraca < notifications@github.com> wrote:

I think that yours is a good method. I'm not an expert, it's the first time for me to use my personal repository with Django but I can try :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Simon-the-Shark/django-mapbox-location-field/issues/5?email_source=notifications&email_token=AABPDWC555RCHUK3CVCJ6U3QQ4UYJA5CNFSM4JASESNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECN45MQ#issuecomment-547081906, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABPDWGASXFUPNAFS26PEWTQQ4UYJANCNFSM4JASESNA .

simon-the-shark commented 5 years ago

Hi! Sorry for late response. I was assuming that right format of entering center point was with space after comma. But @aitoehigie version is better because it accepts both format (with space and spaceless) and that's why it is in the newest version 0.2.7. You can update it with pip even now.

MaxDragonheart commented 5 years ago

Thank you :)