Skip to content

Commit

Permalink
Merge pull request #131 from opennorth/upgrade
Browse files Browse the repository at this point in the history
Upgrade Python and Django
  • Loading branch information
jpmckinney authored Jun 26, 2024
2 parents 631c147 + cdbed46 commit 5ae968c
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 36 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint
on: [push, pull_request]
jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install --upgrade flake8 isort
- run: flake8 .
- run: isort .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
settings.py
/paramiko.log
/staticfiles
/static
/data
/static
2 changes: 1 addition & 1 deletion finder/templates/api.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load staticfiles %}
{% load static %}

{% block title %}API Reference | Represent Elected Officials and Electoral Districts API for Canada{% endblock %}
{% block bodyattributes %}id="api"{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion finder/templates/data.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block title %}{% trans "CSV Downloads" %} | {% trans "Represent Elected Officials and Electoral Districts API for Canada" %}{% endblock %}
{% block bodyattributes %}id="data"{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion finder/templates/demo.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block title %}{% trans "Find Your Canadian Representatives with the Represent API" %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion finder/templates/government.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block title %}{% trans "For Government" %} | {% trans "Represent Elected Officials and Electoral Districts API for Canada" %}{% endblock %}
{% block bodyattributes %}id="government"{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion finder/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block title %}{% trans "Represent Elected Officials and Electoral Districts API for Canada" %}{% endblock %}

Expand Down
18 changes: 9 additions & 9 deletions finder/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.conf.urls import url
from django.urls import path
from django.views.i18n import JavaScriptCatalog

from finder import views

urlpatterns = [
url(r'^jsi18n/$', JavaScriptCatalog.as_view(packages=['finder']), name='javascript-catalog'),
url(r'^setlang/$', views.set_language, name='set_language'),
url(r'^api/$', views.api, name='apidoc'),
url(r'^data/$', views.data, name='data'),
url(r'^demo/$', views.demo, name='demo'),
url(r'^government/$', views.government, name='government'),
url(r'^privacy/$', views.privacy, name='privacy'),
url(r'^$', views.index),
path('jsi18n/', JavaScriptCatalog.as_view(packages=['finder']), name='javascript-catalog'),
path('setlang/', views.set_language, name='set_language'),
path('api/', views.api, name='apidoc'),
path('data/', views.data, name='data'),
path('demo/', views.demo, name='demo'),
path('government/', views.government, name='government'),
path('privacy/', views.privacy, name='privacy'),
path('', views.index),
]
8 changes: 4 additions & 4 deletions finder/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django import http
from django.conf import settings
from django.shortcuts import render
from django.utils.http import url_has_allowed_host_and_scheme
from django.utils.translation import check_for_language
from django.utils.http import is_safe_url


def index(request):
Expand Down Expand Up @@ -36,9 +36,9 @@ def _render(template_name, request):
# @see django/views/i18n.py
def set_language(request):
next = request.GET.get('next')
if not is_safe_url(url=next, host=request.get_host()):
next = request.META.get('HTTP_REFERER')
if not is_safe_url(url=next, host=request.get_host()):
if not url_has_allowed_host_and_scheme(url=next, host=request.get_host()):
next = request.headers.get('referer')
if not url_has_allowed_host_and_scheme(url=next, host=request.get_host()):
next = '/'
response = http.HttpResponseRedirect(next)
lang_code = request.GET.get('language')
Expand Down
11 changes: 10 additions & 1 deletion represent/default_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
Expand Down Expand Up @@ -63,6 +62,11 @@
ROOT_URLCONF = 'represent.urls'
WSGI_APPLICATION = 'represent.wsgi.application'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

LANGUAGES = (
('en', 'English'),
('fr', 'Français'),
Expand Down Expand Up @@ -116,3 +120,8 @@
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
},
}

if 'GDAL_LIBRARY_PATH' in os.environ:
GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
if 'GEOS_LIBRARY_PATH' in os.environ:
GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
19 changes: 13 additions & 6 deletions represent/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from django.conf.urls import include, url
from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles import views
from django.urls import include, path, re_path

admin.autodiscover()

urlpatterns = [
url(r'^admin/', admin.site.urls),
url('', include('boundaries.urls')),
url('', include('representatives.urls')),
url('', include('postcodes.urls')),
url('', include('finder.urls')),
re_path(r'^admin/', admin.site.urls),
path('', include('boundaries.urls')),
path('', include('representatives.urls')),
path('', include('postcodes.urls')),
path('', include('finder.urls')),
]

if settings.DEBUG:
urlpatterns += [
re_path(r"^static/(?P<path>.*)$", views.serve),
]
4 changes: 3 additions & 1 deletion represent/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"""

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "represent.settings")

from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application # noqa: E402

application = get_wsgi_application()
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Django==1.11.29
psycopg2-binary==2.7.4
Django<5
psycopg2-binary==2.9.9
python3-memcached==1.51
represent-boundaries==0.9.3
-e git+https://github.com/opennorth/represent-reps.git#egg=represent-representatives
-e git+https://github.com/opennorth/represent-postcodes.git#egg=represent-postcodes
# represent-boundaries==0.9.3
-e git+https://github.com/opennorth/represent-boundaries.git@upgrade#egg=represent-boundaries
-e git+https://github.com/opennorth/represent-reps.git@upgrade#egg=represent-representatives
-e git+https://github.com/opennorth/represent-postcodes.git@upgrade#egg=represent-postcodes

# Server
eventlet==0.35.2
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[isort]
line_length = 119
profile = black

[flake8]
max-line-length = 119
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load staticfiles %}<!DOCTYPE html>
{% load i18n %}{% load static %}<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
Expand Down
2 changes: 1 addition & 1 deletion templates/boundaries/apibrowser.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load staticfiles %}
{% load static %}

{% block title %}{{ title.capitalize }} | Represent API{% endblock %}

Expand Down
3 changes: 0 additions & 3 deletions tox.ini

This file was deleted.

0 comments on commit 5ae968c

Please sign in to comment.