diff --git a/debian_packages.txt b/debian_packages.txt deleted file mode 100644 index 41e3cd2..0000000 --- a/debian_packages.txt +++ /dev/null @@ -1,4 +0,0 @@ -libpq-dev -build-essential -libpython3-dev -postgis \ No newline at end of file diff --git a/debian_setup.sh b/debian_setup.sh new file mode 100644 index 0000000..5109eea --- /dev/null +++ b/debian_setup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +apt install libpq-dev build-essential libpython3-dev postgis python3-pip python3-venv -y +python3 -m venv venv +source venv/bin/activate +pip install -Ur requirements.txt \ No newline at end of file diff --git a/public/templatetags/mapimage.py b/public/templatetags/mapimage.py index d3d86bb..3955e90 100644 --- a/public/templatetags/mapimage.py +++ b/public/templatetags/mapimage.py @@ -1,24 +1,22 @@ from django import template -import requests import base64 +import io + +from staticmap import StaticMap, CircleMarker from dbsettings.models import Setting register = template.Library() @register.simple_tag -def mapimage(location, zoom=8, width=348, height=250): - payload = { - 'center': f"{location.y},{location.x}", - 'zoom': str(zoom), - "size": "%ix%i" % (width, height), - 'sensor': "false", - 'key': Setting.objects.get(key="google.api.key").value # pylint: disable=no-member - } - - r = requests.get('https://maps.googleapis.com/maps/api/staticmap', params=payload) - image = r.content +def mapimage(location, zoom=7, width=348, height=250): + smap = StaticMap(width, height, url_template="http://a.tile.osm.org/{z}/{x}/{y}.png") + marker = CircleMarker((location.x, location.y), color="orange", width=20) + smap.add_marker(marker) + image = smap.render(zoom) + bio = io.BytesIO() + image.save(bio, format="JPEG") data_uri = 'data:image/jpg;base64,' - data_uri += base64.b64encode(image).decode().replace('\n', '') + data_uri += base64.b64encode(bio.getvalue()).decode().replace('\n', '') return data_uri diff --git a/requirements.txt b/requirements.txt index 190dd07..6d99644 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ django-polymorphic psycopg2 dbsettings django-bootstrap4 -pyinvoice django-countries paypal-checkout-serversdk python-dateutil @@ -15,4 +14,6 @@ geopy django-phonenumber-field phonenumbers googlemaps -Babel \ No newline at end of file +Babel +staticmap +git+https://kumig.it/kumisystems/PyInvoice \ No newline at end of file