Skip to content

Commit

Permalink
Merge pull request #408 from ropable/master
Browse files Browse the repository at this point in the history
Update project to use Python 3.12, refactor map, bump dependencies
  • Loading branch information
ropable authored Sep 10, 2024
2 parents b0062bb + e2f021b commit db6f870
Show file tree
Hide file tree
Showing 12 changed files with 674 additions and 567 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ updates:
directory: "/"
schedule:
interval: "weekly"
target-branch: "master"
- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "weekly"
target-branch: "master"
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-python@v5
id: setup-python
with:
python-version: '3.11'
python-version: '3.12'
#----------------------------------------------
# Install GDAL into the environment
#----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1
# Prepare the base environment.
FROM python:3.11.9-slim AS builder_base_prs
FROM python:3.12.4-slim AS builder_base_prs
LABEL [email protected]
LABEL org.opencontainers.image.source=https://github.com/dbca-wa/prs

Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ environment. With Poetry installed, change into the project directory and run:

poetry install

To run Python commands in the virtualenv, thereafter run them like so:
Activate the virtualenv like so:

poetry run python manage.py
poetry shell

To run Python commands in the activated virtualenv, thereafter run them like so:

python manage.py

Manage new or updating project dependencies with Poetry also, like so:

Expand Down Expand Up @@ -65,15 +69,15 @@ Credentials for Azure should be defined in the following environment variables:

Use `runserver` to run a local copy of the application:

poetry run python manage.py runserver 0:8080
python manage.py runserver 0:8080

Run console commands manually:

poetry run python manage.py shell_plus
python manage.py shell_plus

Run a single Celery worker alongside the local webserver to test indexing:

poetry run celery --app prs2 worker --loglevel INFO --events --without-heartbeat --without-gossip --without-mingle
celery --app prs2 worker --loglevel INFO --events --without-heartbeat --without-gossip --without-mingle

Note: a message broker service is required for Celery tasks to run; Redis
is typically used for this purpose. The `CELERY_BROKER_URL` env variable
Expand All @@ -85,16 +89,16 @@ should contain the broker URL value. Reference:

Run unit tests as follows:

poetry run python manage.py test --keepdb -v2 --settings prs2.test-settings
python manage.py test --keepdb -v2 --settings prs2.test-settings

To run tests for e.g. models only:

poetry run python manage.py test prs2.referral.test_models --keepdb -v2 --settings prs2.test-settings
python manage.py test prs2.referral.test_models --keepdb -v2 --settings prs2.test-settings

To obtain coverage reports:

poetry run coverage run --source='.' manage.py test --keepdb -v2 --settings prs2.test-settings
poetry run coverage report -m
coverage run --source='.' manage.py test --keepdb -v2 --settings prs2.test-settings
coverage report -m

# Docker image

Expand All @@ -111,6 +115,6 @@ This project includes the following pre-commit hooks:
Pre-commit hooks may have additional system dependencies to run. Optionally
install pre-commit hooks locally like so:

poetry run pre-commit install
pre-commit install

Reference: <https://pre-commit.com/>
2 changes: 1 addition & 1 deletion kustomize/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ patches:
- path: typesense_service_patch.yaml
images:
- name: ghcr.io/dbca-wa/prs
newTag: 2.5.55
newTag: 2.5.56
6 changes: 4 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

# These lines are required for interoperability between local and container environments.
dot_env = os.path.join(os.getcwd(), '.env')
dot_env = os.path.join(os.getcwd(), ".env")
if os.path.exists(dot_env):
from dotenv import load_dotenv

load_dotenv()


Expand All @@ -24,5 +26,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
144 changes: 65 additions & 79 deletions poetry.lock

Large diffs are not rendered by default.

94 changes: 70 additions & 24 deletions prs2/referral/static/js/referral_map.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,102 @@
"use strict";
// NOTE: some global constants are set in the base template.
const geoserver_wmts_url = kmi_geoserver_url + "/gwc/service/wmts?service=WMTS&request=GetTile&version=1.0.0&tilematrixset=mercator&tilematrix=mercator:{z}&tilecol={x}&tilerow={y}&format=image/png"
const geoserver_wmts_url = kmi_geoserver_url + "/gwc/service/wmts?service=WMTS&request=GetTile&version=1.0.0&tilematrixset=gda94&tilematrix=gda94:{z}&tilecol={x}&tilerow={y}";
const geoserver_wmts_url_base = geoserver_wmts_url + "&format=image/jpeg";
const geoserver_wmts_url_overlay = geoserver_wmts_url + "&format=image/png";

// Define baselayer tile layers.
const landgateOrthomosaic = L.tileLayer(
geoserver_wmts_url + "&layer=landgate:virtual_mosaic",
geoserver_wmts_url_base + "&layer=landgate:virtual_mosaic",
{
tileSize: 1024,
zoomOffset: -2,
},
);
const mapboxStreets = L.tileLayer(
geoserver_wmts_url + "&layer=dbca:mapbox-streets",
geoserver_wmts_url_base + "&layer=public:mapbox-streets",
{
tileSize: 1024,
zoomOffset: -2,
},
);
const waCoast = L.tileLayer(
geoserver_wmts_url + "&layer=public:wa_coast_pub",
geoserver_wmts_url_base + "&layer=public:wa_coast_pub",
{
tileSize: 1024,
zoomOffset: -2,
},
);

// Define overlay tile layers.
// Cadastre uses KB as the source, not KMI.
const cadastre = L.tileLayer.wms(mapproxy_url, {
layers: 'dbca-cadastre',
format: 'image/png',
transparent: true,
opacity: 0.75,
minZoom: 13,
});
const cadastre = L.tileLayer.wms(
mapproxy_url,
{
layers: 'dbca-cadastre',
format: 'image/png',
transparent: true,
opacity: 0.75,
minZoom: 13,
}
);
// PRS uses WMS, being a "live" layer.
const prsLocations = L.tileLayer.wms(kmi_geoserver_url + "/ows", {
layers: prs_layer_name,
format: 'image/png',
transparent: true,
opacity: 0.75,
});
const prsLocations = L.tileLayer.wms(
kmi_geoserver_url + "/ows",
{
layers: prs_layer_name,
format: 'image/png',
transparent: true,
opacity: 0.75,
}
);
const dbcaRegions = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:dbca_regions",
geoserver_wmts_url_overlay + "&layer=cddp:kaartdijin-boodja-public_CPT_DBCA_REGIONS",
{
tileSize: 1024,
zoomOffset: -2,
},
);
const dbcaTenure = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:dbca_managed_tenure",
geoserver_wmts_url_overlay + "&layer=cddp:dbca_managed_tenure",
{
tileSize: 1024,
zoomOffset: -2,
opacity: 0.75,
},
);
const regionalParks = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:regional_parks",
geoserver_wmts_url_overlay + "&layer=cddp:regional_parks",
{
tileSize: 1024,
zoomOffset: -2,
},
);
const swanCannDevContArea = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:cpt_swan_cann_dev_cont_area",
geoserver_wmts_url_overlay + "&layer=cddp:cpt_swan_cann_dev_cont_area",
{
tileSize: 1024,
zoomOffset: -2,
},
);
const ucl = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:unallocated_crown_land",
geoserver_wmts_url_overlay + "&layer=cddp:unallocated_crown_land",
{
tileSize: 1024,
zoomOffset: -2,
opacity: 0.75,
},
);
const lgaBoundaries = L.tileLayer(
geoserver_wmts_url + "&layer=cddp:local_gov_authority",
geoserver_wmts_url_overlay + "&layer=cddp:local_gov_authority",
{
tileSize: 1024,
zoomOffset: -2,
},
);

// Define map.
var map = L.map('map', {
crs: L.CRS.EPSG3857,
crs: L.CRS.EPSG4326, // WGS 84
center: [-31.96, 115.87],
zoom: 16,
minZoom: 6,
Expand Down
8 changes: 4 additions & 4 deletions prs2/referral/templates/referral/referral_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

{% block extra_style %}
{{ block.super }}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.css" integrity="sha512-1xoFisiGdy9nvho8EgXuXvnpR5GAMSjFwp40gSRE3NwdUdIMIKuPa7bqoUhLD0O/5tPNhteAsE5XyyMi5reQVA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.6.0/Control.FullScreen.css" integrity="sha256-RTALnHN76PJ32RJx2mxggy+RUt9TIRV+mfPLSLbI75A=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.css" integrity="sha512-h9FcoyWjHcOcmEVkxOfTLnmZFWIH0iZhZT1H2TbOq55xssQGEJHEaIm+PgoUaZbRvQTNTluNOEfb1ZRy6D3BOw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/3.0.2/Control.FullScreen.min.css" integrity="sha512-icRYRbqvwyLFADCizHy+7d4vVNnzF92F0ADsgIlPU2eegXZJ9iHtF1BMi7xdgo1lSyd0nsyI5Lvxhhlxx7WxZg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="{% static 'css/leaflet-search.min.css' %}" />
<style>
#map {
Expand All @@ -31,8 +31,8 @@

{% block extra_js %}
{{ block.super }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.min.js" integrity="sha512-SeiQaaDh73yrb56sTW/RgVdi/mMqNeM2oBwubFHagc5BkixSpP1fvqF47mKzPGWYSSy4RwbBunrJBQ4Co8fRWA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.6.0/Control.FullScreen.min.js" integrity="sha256-6H5xWuqlbGtfk8UL9eMYmp14brCbCw1ZZialT8fHLRE=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js" integrity="sha512-BwHfrr4c9kmRkLw6iXFdzcdWV/PGkVgiIyIWLLlTSXzWQzxuSg4DiQUCpauz/EWjgk5TYQqX/kvn9pG1NpYfqg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/3.0.2/Control.FullScreen.min.js" integrity="sha512-G3uVfdWq1gdYQ0tfaN8APmD3UBQCv0Am3csZtRdaNbCBzNgh57yu7MhgrXozjeflGsRapDpBVdrKCQahT99p0Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-search/3.0.2/leaflet-search.min.js" integrity="sha512-lmt2nQGwuhA/7xEG4KjOuzy+kBQVOgpBNFxJR2yWp8J57H8nYxWC8J7Y5woDbqBBpBVHHLbFEi503u5K49KcOA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="{% static 'js/referral_map.js' %}"></script>
<script>
Expand Down
15 changes: 8 additions & 7 deletions prs2/referral/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@


class AuditTestCase(PrsTestCase):

def test_save(self):
"""Test that the save() method sets a creator and modifier outside of a HTTP request
"""
"""Test that the save() method sets a creator and modifier outside of a HTTP request"""
r = Referral.objects.create(
type=ReferralType.objects.first(), referring_org=Organisation.objects.first(),
reference='foo', referral_date=date.today())
self.assertEquals(r.creator.pk, 1)
self.assertEquals(r.modifier.pk, 1)
type=ReferralType.objects.first(),
referring_org=Organisation.objects.first(),
reference="foo",
referral_date=date.today(),
)
self.assertEqual(r.creator.pk, 1)
self.assertEqual(r.modifier.pk, 1)
Loading

0 comments on commit db6f870

Please sign in to comment.