Skip to content

Commit

Permalink
feat: install postgis and add lat/long fields for facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ngurenyaga committed Jul 22, 2021
1 parent 048f60f commit ccd5357
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 161 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:

- name: Install requirements
run: |
sudo apt-get install postgis gdal-bin libgdal-dev
pip install -r requirements/local.txt && pip install -r requirements/production.txt
npm ci
npm install -g mjml
Expand All @@ -67,7 +68,7 @@ jobs:
# Service containers to run with `container-job`
services:
postgres:
image: postgres
image: postgis/postgis
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
Expand All @@ -91,6 +92,7 @@ jobs:

- name: Install requirements
run: |
sudo apt-get install postgis gdal-bin libgdal-dev
pip install -r requirements/local.txt && pip install -r requirements/production.txt
npm ci
npm install -g mjml
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
# dependencies for building Python packages
build-essential wget \
# psycopg2 dependencies
libpq-dev
libpq-dev postgis gdal-bin libgdal-dev

# Requirements are installed here to ensure they will be cached.
COPY ./requirements .
Expand Down
9 changes: 7 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT", None),
"ENGINE": "django.db.backends.postgresql",
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": True,
}
}
Expand All @@ -65,6 +65,7 @@
"django.contrib.staticfiles",
"django.contrib.humanize",
"django.forms",
"django.contrib.gis",
]
THIRD_PARTY_APPS = [
"crispy_forms",
Expand Down Expand Up @@ -274,7 +275,11 @@
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAuthenticated",
"rest_framework.permissions.DjangoModelPermissions",
"rest_framework.permissions.DjangoObjectPermissions",
),
}
CORS_URLS_REGEX = r"^/api/.*$"

Expand Down
23 changes: 23 additions & 0 deletions fahari/common/migrations/0012_auto_20210722_1525.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.5 on 2021-07-22 12:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0011_alter_facility_facility_type_category'),
]

operations = [
migrations.AddField(
model_name='facility',
name='lat',
field=models.FloatField(default=0.0),
),
migrations.AddField(
model_name='facility',
name='lon',
field=models.FloatField(default=0.0),
),
]
26 changes: 26 additions & 0 deletions fahari/common/migrations/0013_auto_20210722_1538.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.5 on 2021-07-22 12:38

from django.db import migrations

EXTENSIONS_SQL = '''
CREATE EXTENSION IF NOT EXISTS plpgsql;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_raster;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
-- CREATE EXTENSION IF NOT EXISTS postgis_sfcgal;
-- CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
-- CREATE EXTENSION IF NOT EXISTS address_standardizer;
-- CREATE EXTENSION IF NOT EXISTS address_standardizer_data_us;
-- CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
'''

class Migration(migrations.Migration):

dependencies = [
('common', '0012_auto_20210722_1525'),
]

operations = [
migrations.RunSQL(EXTENSIONS_SQL)
]
5 changes: 4 additions & 1 deletion fahari/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from typing import List

from django.conf import settings
from django.contrib.gis.db import models
from django.core.exceptions import ValidationError
from django.db import models, transaction
from django.db import transaction
from django.db.models.base import ModelBase
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -410,6 +411,8 @@ class Facility(AbstractBase):
approved = models.BooleanField(default=True)
public_visible = models.BooleanField(default=True)
closed = models.BooleanField(default=False)
lon = models.FloatField(default=0.0)
lat = models.FloatField(default=0.0)

model_validators = [
"facility_name_longer_than_three_characters",
Expand Down
2 changes: 1 addition & 1 deletion fahari/ops/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.auth import get_user_model
from django.contrib.gis.db import models
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone

from fahari.common.models import AbstractBase, Facility, System
Expand Down

0 comments on commit ccd5357

Please sign in to comment.