Skip to content

Commit

Permalink
Merge pull request #149 from ropable/master
Browse files Browse the repository at this point in the history
Bump Django minor version
  • Loading branch information
ropable authored Dec 10, 2024
2 parents cbc0c51 + 620ba81 commit 7091eed
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 184 deletions.
6 changes: 3 additions & 3 deletions 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.12.6-alpine AS builder_base
FROM python:3.12.8-alpine AS builder_base
LABEL [email protected]
LABEL org.opencontainers.image.source=https://github.com/dbca-wa/caddy

Expand All @@ -26,11 +26,11 @@ RUN apk add --no-cache \
proj \
binutils \
&& ln -s /usr/lib/libproj.so.25 /usr/lib/libproj.so \
&& ln -s /usr/lib/libgdal.so.35 /usr/lib/libgdal.so \
&& ln -s /usr/lib/libgdal.so.36 /usr/lib/libgdal.so \
&& ln -s /usr/lib/libgeos_c.so.1 /usr/lib/libgeos_c.so
WORKDIR /app
COPY poetry.lock pyproject.toml ./
ARG POETRY_VERSION=1.8.3
ARG POETRY_VERSION=1.8.5
RUN pip install --no-cache-dir --root-user-action=ignore poetry==${POETRY_VERSION} \
&& poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --only main
Expand Down
140 changes: 70 additions & 70 deletions caddy/settings.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,71 @@
"""
Django settings for caddy project.
"""
from caddy.utils import env
import dj_database_url

import os
import sys

import dj_database_url

from caddy.utils import env

# Project paths
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.join(BASE_DIR, 'caddy')
PROJECT_DIR = os.path.join(BASE_DIR, "caddy")
# Add PROJECT_DIR to the system path.
sys.path.insert(0, PROJECT_DIR)

# Application definition
DEBUG = env('DEBUG', False)
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
SECRET_KEY = env('SECRET_KEY', 'PlaceholderSecretKey')
CSRF_COOKIE_SECURE = env('CSRF_COOKIE_SECURE', False)
SESSION_COOKIE_SECURE = env('SESSION_COOKIE_SECURE', False)
SECURE_SSL_REDIRECT = env('SECURE_SSL_REDIRECT', False)
SECURE_REFERRER_POLICY = env('SECURE_REFERRER_POLICY', None)
SECURE_HSTS_SECONDS = env('SECURE_HSTS_SECONDS', 0)
DEBUG = env("DEBUG", False)
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
SECRET_KEY = env("SECRET_KEY", "PlaceholderSecretKey")
CSRF_COOKIE_SECURE = env("CSRF_COOKIE_SECURE", False)
SESSION_COOKIE_SECURE = env("SESSION_COOKIE_SECURE", False)
SECURE_SSL_REDIRECT = env("SECURE_SSL_REDIRECT", False)
SECURE_REFERRER_POLICY = env("SECURE_REFERRER_POLICY", None)
SECURE_HSTS_SECONDS = env("SECURE_HSTS_SECONDS", 0)
if not DEBUG:
ALLOWED_HOSTS = env('ALLOWED_DOMAINS', '').split(',')
ALLOWED_HOSTS = env("ALLOWED_DOMAINS", "").split(",")
else:
ALLOWED_HOSTS = ['*']
INTERNAL_IPS = ['127.0.0.1', '::1']
ROOT_URLCONF = 'caddy.urls'
WSGI_APPLICATION = 'caddy.wsgi.application'
ALLOWED_HOSTS = ["*"]
INTERNAL_IPS = ["127.0.0.1", "::1"]
ROOT_URLCONF = "caddy.urls"
WSGI_APPLICATION = "caddy.wsgi.application"

# Azure blob storage credentials.
AZURE_ACCOUNT_NAME = env('AZURE_ACCOUNT_NAME', 'account_name')
AZURE_ACCOUNT_KEY = env('AZURE_ACCOUNT_KEY', 'account_key')
AZURE_CONTAINER = env('AZURE_CONTAINER', 'container')
AZURE_ACCOUNT_NAME = env("AZURE_ACCOUNT_NAME", "account_name")
AZURE_ACCOUNT_KEY = env("AZURE_ACCOUNT_KEY", "account_key")
AZURE_CONTAINER = env("AZURE_CONTAINER", "container")

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.postgres',
'django_extensions',
'tastypie',
'shack',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.staticfiles",
"django.contrib.gis",
"django.contrib.postgres",
"django_extensions",
"tastypie",
"shack",
)
MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(PROJECT_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
],
},
},
Expand All @@ -72,55 +75,52 @@
# Database configuration
DATABASES = {
# Defined in the DATABASE_URL env variable.
'default': dj_database_url.config(),
"default": dj_database_url.config(),
}


# Internationalization
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Australia/Perth'
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Australia/Perth"
USE_I18N = False
USE_L10N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")


# Tastypie settings
TASTYPIE_DEFAULT_FORMATS = ['json', 'jsonp']
TASTYPIE_DEFAULT_FORMATS = ["json", "jsonp"]


# Logging settings
LOGGING = {
'version': 1,
'formatters': {
'verbose': {'format': '%(asctime)s %(levelname)-12s %(name)-12s %(message)s'},
"version": 1,
"formatters": {
"verbose": {"format": "%(asctime)s %(levelname)-12s %(name)-12s %(message)s"},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'stream': sys.stdout,
'level': 'WARNING',
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "verbose",
"stream": sys.stdout,
"level": "WARNING",
},
'caddy': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'stream': sys.stdout,
'level': 'INFO',
"caddy": {
"class": "logging.StreamHandler",
"formatter": "verbose",
"stream": sys.stdout,
"level": "INFO",
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'WARNING',
"loggers": {
"django": {
"handlers": ["console"],
"level": "WARNING",
},
'caddy': {
'handlers': ['caddy'],
'level': 'INFO'
},
}
"caddy": {"handlers": ["caddy"], "level": "INFO"},
},
}
29 changes: 21 additions & 8 deletions geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def readiness():

@app.route("/api/<object_id>")
def detail(object_id):
# Validate `object_id`: this value needs be castable as an integer, even though we use it as a string.
"""This route will return details of a single land parcel, serialised as a JSON object."""
# Validate `object_id`: this value needs be castable as an integer, even though we handle it as a string.
try:
int(object_id)
except ValueError:
Expand Down Expand Up @@ -89,6 +90,16 @@ def detail(object_id):

@app.route("/api/geocode")
def geocode():
"""This route will accept a query parameter (`q` or `point`), and query for matching land parcels.
`point` must be a string that parses as <float>,<float> and will be used to query for intersection with the `boundary`
spatial column.
`q` will be parsed as free text (non-alphanumeric characters will be ignored) and will be used to perform a text search
against the `tsv` column.
Query results will be returned as serialised JSON objects.
An optional `limit` parameter may be passed in to limit the maximum number of results returned, otherwise the route
defaults to a maximum of five results (no sorting is carried out, so these are simply the first five results from the
query.
"""
q = request.query.q or ""
point = request.query.point or ""
if not q and not point:
Expand All @@ -104,7 +115,9 @@ def geocode():
try:
lon, lat = float(lon), float(lat)
except ValueError:
return "{}"
response.status = 400
return "Bad request"

ewkt = f"SRID=4326;POINT({lon} {lat})"
sql = text("""SELECT object_id, address_nice, owner, ST_AsText(centroid), ST_AsText(envelope), ST_AsText(boundary), data
FROM shack_address
Expand Down Expand Up @@ -149,7 +162,7 @@ def geocode():
else:
limit = 5

sql = text("""SELECT address_nice, owner, ST_X(centroid), ST_Y(centroid), object_id
sql = text("""SELECT object_id, address_nice, owner, ST_X(centroid), ST_Y(centroid)
FROM shack_address
WHERE tsv @@ to_tsquery(:tsquery)
LIMIT :limit""")
Expand All @@ -164,11 +177,11 @@ def geocode():
for i in result:
j.append(
{
"address": i[0],
"owner": i[1],
"lon": i[2],
"lat": i[3],
"pin": i[4],
"object_id": i[0],
"address": i[1],
"owner": i[2],
"lon": i[3],
"lat": i[4],
}
)
return orjson.dumps(j)
Expand Down
10 changes: 5 additions & 5 deletions kustomize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Declarative management of Caddy Kubernetes objects using Kustomize.

# How to use
## How to use

Within an overlay directory, create a `.env` file to contain required secret
values in the format KEY=value (i.e. `overlays/uat/.env`). Required values:
Expand All @@ -22,8 +22,8 @@ Run `kubectl` with the `-k` flag to generate resources for a given overlay:
kubectl apply -k kustomize/overlays/uat --namespace prs --dry-run=client
```

# References:
## References

* https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
* https://github.com/kubernetes-sigs/kustomize
* https://github.com/kubernetes-sigs/kustomize/tree/master/examples
- <https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/>
- <https://github.com/kubernetes-sigs/kustomize>
- <https://github.com/kubernetes-sigs/kustomize/tree/master/examples>
Loading

0 comments on commit 7091eed

Please sign in to comment.