Skip to content

Commit 0f54021

Browse files
Merge pull request #20 from neutrons/update_python_django_postgresql
Update python django and postgresql
2 parents 5f2c914 + 0f978c5 commit 0f54021

File tree

9 files changed

+26
-67
lines changed

9 files changed

+26
-67
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
prefix := /var/www/livedata
22
app_dir := live_data_server
3-
DJANGO_COMPATIBLE:=$(shell python -c "import django;t=0 if django.VERSION[1]<9 else 1; print(t)")
3+
DJANGO_COMPATIBLE:=$(shell python -c "import django;t=0 if django.VERSION[0]<4 else 1; print(t)")
44
DJANGO_VERSION:=$(shell python -c "import django;print(django.__version__)")
55

66
# command to run docker compose. change this to be what you have installed
@@ -14,13 +14,13 @@ help:
1414

1515
check: ## Check dependencies
1616
@python -c "import django" || echo "\nERROR: Django is not installed: www.djangoproject.com\n"
17-
@python -c "import psycopg2" || echo "\nWARNING: psycopg2 is not installed: http://initd.org/psycopg\n"
17+
@python -c "import psycopg" || echo "\nWARNING: psycopg is not installed: http://initd.org/psycopg\n"
1818
@python -c "import corsheaders" || echo "\nWARNING: django-cors-headers is not installed: https://github.com/ottoyiu/django-cors-headers\n"
1919

2020
ifeq ($(DJANGO_COMPATIBLE),1)
2121
@echo "Detected Django $(DJANGO_VERSION)"
2222
else
23-
$(error Detected Django $(DJANGO_VERSION) < 1.9. The web monitor requires at least Django 1.9)
23+
$(error Detected Django $(DJANGO_VERSION) < 4. The web monitor requires at least Django 4)
2424
endif
2525

2626
docker/pruneall: docker/compose/validate ## stop all containers, then remove all containers, images, networks, and volumes

config/docker-compose.envlocal.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ services:
4444
condition: service_healthy
4545

4646
db:
47-
# do not upgrade to version > 9.6.23 unless you also upgrade livedata image
48-
image: postgres:9.6.23
47+
image: postgres:16
4948
environment:
5049
POSTGRES_DB: ${DATABASE_NAME}
5150
POSTGRES_USER: ${DATABASE_USER}

environment.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ name: livedata
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.7
6-
- pip
7-
- postgresql=9.5.3
5+
- python=3.12
6+
- postgresql=16
87
- sphinx
98
- sphinx_rtd_theme
10-
- django=2.1
11-
- django-cors-headers
12-
- psycopg2
9+
- django=4.2
10+
- django-cors-headers=4.4
11+
- psycopg=3.2
1312
- gunicorn
1413
- pytest
1514
- build
1615
- versioningit
1716
- toml
18-
- requests<2.31 # can remove this condition once we allow newer versions of openssl
1917
- pre-commit
2018
- coverage

src/live_data_server/live_data_server/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
DEBUG = bool(os.environ.get("APP_DEBUG", False))
2727
# CSRF_COOKIE_SECURE = True
2828
# SESSION_COOKIE_SECURE = True
29-
CSRF_TRUSTED_ORIGINS = [".ornl.gov", ".sns.gov", "localhost", "127.0.0.1"]
29+
CSRF_TRUSTED_ORIGINS = ["https://*.ornl.gov", "https://*.sns.gov", "http://localhost", "http://127.0.0.1"]
3030

3131
ALLOWED_HOSTS = [
3232
"localhost",
@@ -63,7 +63,7 @@
6363

6464
ROOT_URLCONF = "live_data_server.urls"
6565

66-
CORS_ORIGIN_ALLOW_ALL = True
66+
CORS_ALLOW_ALL_ORIGINS = True
6767

6868
TEMPLATES = [
6969
{
@@ -89,7 +89,7 @@
8989

9090
DATABASES = {
9191
"default": {
92-
"ENGINE": "django.db.backends.postgresql_psycopg2", # , 'mysql', 'sqlite3' or 'oracle'.
92+
"ENGINE": "django.db.backends.postgresql", # , 'mysql', 'sqlite3' or 'oracle'.
9393
"NAME": os.environ.get("DATABASE_NAME"), # Or path to database file if using sqlite3.
9494
"USER": os.environ.get("DATABASE_USER"), # Not used with sqlite3.
9595
"PASSWORD": os.environ.get("DATABASE_PASS"), # Not used with sqlite3.

src/live_data_server/plots/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=invalid-name, line-too-long
21
"""
32
Define url structure
43
"""

src/live_data_server/plots/view_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=invalid-name, bare-except
21
"""
32
Utility functions to support views.
43
"""

src/live_data_server/plots/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=unused-argument, invalid-name
21
"""
32
Definition of views
43
"""

test_client/test_client.py

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,22 @@
1-
# pylint: disable=invalid-name
21
"""
32
Test client that uploads data
43
"""
54

65
import argparse
76
import datetime
87
import json
8+
import os
99
import string
10-
import sys
1110

1211
import numpy as np
1312
import plotly.graph_objs as go
1413
import requests
1514
from plotly.offline import plot
1615

17-
sys.path.insert(0, "../live_data_server")
18-
19-
JSON_DATA = False
20-
API_USER = "admin"
21-
API_PWD = "adminadmin"
22-
INSTRUMENT = "REF_L"
23-
RUN_NUMBER = 123456
24-
UPLOAD_URL = "http://127.0.0.1:8888/plots/$instrument/$run_number/upload_plot_data/"
25-
USER_UPLOAD_URL = "http://127.0.0.1:8888/plots/$user/upload_user_data/"
26-
27-
28-
def test_sine_wave(run_number, instrument):
29-
"""
30-
Produce test sine wave plot
31-
"""
32-
now = datetime.datetime.now()
33-
x = np.arange(1, now.second)
34-
y = np.sin(x)
35-
x2 = np.arange(1, now.second)
36-
y2 = np.sin(x + 1.0)
37-
err = 0.2 * np.ones(len(x))
38-
sys.path.append("/opt/postprocessing/postprocessing")
39-
from publish_plot import plot1d
40-
41-
data = [[x, y, err, 2 * err], [x2, y2, err, 2 * err]]
42-
data_names = ["data", "offset"]
43-
return plot1d(
44-
run_number, data_list=data, instrument=instrument, x_title="theta", y_title="sin(theta)", data_names=data_names
45-
)
16+
API_USER = os.environ.get("DJANGO_SUPERUSER_USERNAME")
17+
API_PWD = os.environ.get("DJANGO_SUPERUSER_PASSWORD")
18+
UPLOAD_URL = "http://127.0.0.1/plots/$instrument/$run_number/upload_plot_data/"
19+
USER_UPLOAD_URL = "http://127.0.0.1/plots/$user/upload_user_data/"
4620

4721

4822
def get_plot_as_json():
@@ -96,32 +70,23 @@ def get_plot_as_div():
9670
parser.add_argument("-r", metavar="runid", type=int, help="Run number (int)", dest="runid", required=True)
9771
parser.add_argument("-d", metavar="description", help="Data description", dest="description", required=False)
9872
parser.add_argument("-i", metavar="instrument", help="Instrument", dest="instrument", required=True)
99-
parser.add_argument("-c", metavar="config", help="Config file", dest="config_file", required=False)
10073
namespace = parser.parse_args()
101-
as_json_data = JSON_DATA if namespace.as_json is None else namespace.as_json
10274

10375
monitor_user = {"username": API_USER, "password": API_PWD}
10476
url_template = string.Template(UPLOAD_URL)
10577
url = url_template.substitute(instrument=namespace.instrument, run_number=namespace.runid)
10678

107-
if as_json_data:
79+
if namespace.as_json:
10880
print("Producing json data")
10981
files = {"file": json.dumps(get_plot_as_json())}
11082
else:
11183
print("Producing html data")
11284
files = {"file": get_plot_as_div()}
11385

114-
if namespace.config_file is not None:
115-
sys.path.append("/opt/postprocessing/postprocessing")
116-
from publish_plot import publish_plot
117-
118-
request = publish_plot(namespace.instrument, namespace.runid, files=files, config_file=namespace.config_file)
119-
else:
120-
# request = test_sine_wave(namespace.runid, namespace.instrument)
121-
if namespace.description is not None:
122-
url_template = string.Template(USER_UPLOAD_URL)
123-
url = url_template.substitute(user=namespace.instrument)
124-
monitor_user["data_id"] = namespace.description
86+
if namespace.description is not None:
87+
url_template = string.Template(USER_UPLOAD_URL)
88+
url = url_template.substitute(user=namespace.instrument)
89+
monitor_user["data_id"] = namespace.description
12590

126-
request = requests.post(url, data=monitor_user, files=files, verify=False)
91+
request = requests.post(url, data=monitor_user, files=files, verify=False)
12792
print(request.status_code)

tests/test_post_get.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55

6-
import psycopg2
6+
import psycopg
77
import requests
88

99
TEST_URL = "http://127.0.0.1"
@@ -17,8 +17,8 @@ class TestLiveDataServer:
1717
@classmethod
1818
def setup_class(cls):
1919
"""Clean the database before running tests"""
20-
conn = psycopg2.connect(
21-
database=os.environ.get("DATABASE_NAME"),
20+
conn = psycopg.connect(
21+
dbname=os.environ.get("DATABASE_NAME"),
2222
user=os.environ.get("DATABASE_USER"),
2323
password=os.environ.get("DATABASE_PASS"),
2424
port=os.environ.get("DATABASE_PORT"),

0 commit comments

Comments
 (0)