diff --git a/deployment/Dockerfile b/deployment/Dockerfile index ab12052..533a9e8 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /usr/src/app RUN --mount=type=cache,target=/var/cache/apt \ apt-get update && \ - apt-get install --no-install-recommends -y build-essential libpq-dev gettext chromium-driver \ + apt-get install --no-install-recommends -y build-essential libpq-dev gettext chromium-driver gdal-bin \ && rm -rf /var/lib/apt/lists/* diff --git a/docker-compose.yml b/docker-compose.yml index 4170c29..dfdc5de 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,7 @@ services: command: [ "/bin/bash", "/app/deployment/scripts/backend/start.sh" ] db: - image: postgres:15.2-alpine + image: postgis/postgis:15-3.4-alpine container_name: "${APP_NAME}-db" hostname: "${POSTGRES_HOST:-db}" volumes: diff --git a/src/agenda_culturel/migrations/0080_place_location_pt.py b/src/agenda_culturel/migrations/0080_place_location_pt.py new file mode 100644 index 0000000..3be541c --- /dev/null +++ b/src/agenda_culturel/migrations/0080_place_location_pt.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.9 on 2024-10-10 20:34 + +import django.contrib.gis.geos.point +from django.db import migrations +import location_field.models.spatial + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0079_contactmessage_spam'), + ] + + operations = [ + migrations.AddField( + model_name='place', + name='location_pt', + field=location_field.models.spatial.LocationField(default=django.contrib.gis.geos.point.Point(45.783329, 3.08333), srid=4326), + ), + ] diff --git a/src/agenda_culturel/migrations/0081_auto_20241010_2235.py b/src/agenda_culturel/migrations/0081_auto_20241010_2235.py new file mode 100644 index 0000000..0b8f2ec --- /dev/null +++ b/src/agenda_culturel/migrations/0081_auto_20241010_2235.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.9 on 2024-10-10 20:35 + +from django.db import migrations +from agenda_culturel.models import Place +from django.contrib.gis.geos import Point + +def change_coord_format(apps, schema_editor): + places = Place.objects.all() + + for p in places: + l = p.location.split(',') + if len(l) == 2: + p.location_pt = Point(float(l[1]), float(l[0])) + else: + p.location_pt = Point(3.08333, 45.783329) + p.save() + + + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0080_place_location_pt'), + ] + + operations = [ + migrations.RunPython(change_coord_format), + ] + + diff --git a/src/agenda_culturel/migrations/0082_alter_place_location_pt.py b/src/agenda_culturel/migrations/0082_alter_place_location_pt.py new file mode 100644 index 0000000..1686c67 --- /dev/null +++ b/src/agenda_culturel/migrations/0082_alter_place_location_pt.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.9 on 2024-10-10 21:15 + +import django.contrib.gis.geos.point +from django.db import migrations +import location_field.models.spatial + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0081_auto_20241010_2235'), + ] + + operations = [ + migrations.AlterField( + model_name='place', + name='location_pt', + field=location_field.models.spatial.LocationField(default=django.contrib.gis.geos.point.Point(3.08333, 45.783329), srid=4326), + ), + ] diff --git a/src/agenda_culturel/migrations/0083_remove_place_location.py b/src/agenda_culturel/migrations/0083_remove_place_location.py new file mode 100644 index 0000000..c07e5b0 --- /dev/null +++ b/src/agenda_culturel/migrations/0083_remove_place_location.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.9 on 2024-10-10 21:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0082_alter_place_location_pt'), + ] + + operations = [ + migrations.RemoveField( + model_name='place', + name='location', + ), + ] diff --git a/src/agenda_culturel/migrations/0084_rename_location_pt_place_location.py b/src/agenda_culturel/migrations/0084_rename_location_pt_place_location.py new file mode 100644 index 0000000..7179a44 --- /dev/null +++ b/src/agenda_culturel/migrations/0084_rename_location_pt_place_location.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.9 on 2024-10-10 21:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0083_remove_place_location'), + ] + + operations = [ + migrations.RenameField( + model_name='place', + old_name='location_pt', + new_name='location', + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 34a2e77..b38187e 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -25,6 +25,8 @@ from django.utils.timezone import datetime from django.utils import timezone from location_field.models.plain import PlainLocationField +from location_field.models.spatial import LocationField +from django.contrib.gis.geos import Point from .calendar import CalendarList, CalendarDay from icalendar import Calendar as icalCal @@ -244,7 +246,7 @@ class Place(models.Model): null=True, ) city = models.CharField(verbose_name=_("City"), help_text=_("City name")) - location = PlainLocationField(based_fields=["name", "address", "city"], zoom=12) + location = LocationField(based_fields=["name", "address", "city"], zoom=12, default=Point(3.08333, 45.783329)) aliases = ArrayField( models.CharField(max_length=512), diff --git a/src/agenda_culturel/settings/base.py b/src/agenda_culturel/settings/base.py index c1ecf42..1c51897 100644 --- a/src/agenda_culturel/settings/base.py +++ b/src/agenda_culturel/settings/base.py @@ -49,6 +49,7 @@ INSTALLED_APPS = [ "compressor", "django_ckeditor_5", "recurrence", + 'django.contrib.gis', "location_field.apps.DefaultConfig", "django.contrib.postgres", "robots", @@ -107,7 +108,7 @@ WSGI_APPLICATION = "agenda_culturel.wsgi.application" DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql", + 'ENGINE': 'django.contrib.gis.db.backends.postgis', "NAME": os_getenv("POSTGRES_DB", "postgres"), "USER": os_getenv("POSTGRES_USER", "postgres"), "PASSWORD": os_getenv("POSTGRES_PASSWORD", "postgres"), diff --git a/src/agenda_culturel/templates/agenda_culturel/place_detail.html b/src/agenda_culturel/templates/agenda_culturel/place_detail.html index 3dae04f..e4040a8 100644 --- a/src/agenda_culturel/templates/agenda_culturel/place_detail.html +++ b/src/agenda_culturel/templates/agenda_culturel/place_detail.html @@ -8,7 +8,7 @@ {% load static %} {% load cache %} {% load i18n %} - +{% load l10n %} {% block entete_header %} {% css_categories %} @@ -39,7 +39,7 @@
diff --git a/src/agenda_culturel/templates/agenda_culturel/place_list.html b/src/agenda_culturel/templates/agenda_culturel/place_list.html index ad348c3..865b94f 100644 --- a/src/agenda_culturel/templates/agenda_culturel/place_list.html +++ b/src/agenda_culturel/templates/agenda_culturel/place_list.html @@ -74,7 +74,7 @@ window.mMapping = {}; {% if object_list %} {% for place in object_list %} - markerArray.push(L.marker([{{ place.location }}]).bindPopup('{{ place.name }}
{% if place.address %}{{ place.address }}, {% endif %}{{ place.city }}')) + markerArray.push(L.marker([{{ place.location|tocoords }}]).bindPopup('{{ place.name }}
{% if place.address %}{{ place.address }}, {% endif %}{{ place.city }}')) markers.addLayer(markerArray[markerArray.length - 1]); window.mMapping[{{ place.id }}] = markerArray[markerArray.length - 1]; window.jQuery('a#open-map-{{ place.id }}').click(function(){ diff --git a/src/agenda_culturel/templatetags/utils_extra.py b/src/agenda_culturel/templatetags/utils_extra.py index ec4f1d9..d3c80a7 100644 --- a/src/agenda_culturel/templatetags/utils_extra.py +++ b/src/agenda_culturel/templatetags/utils_extra.py @@ -119,3 +119,7 @@ def get_item(dictionary, key): @register.filter def remove_id_prefix(value): return int(value.replace("id_", "")) + +@register.filter +def tocoords(c): + return str(c.coords[1]) + ", " + str(c.coords[0]) \ No newline at end of file