Skip to content

Commit

Permalink
Fix pre-commit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield committed Jun 18, 2024
1 parent 52bcbe4 commit b92ed80
Show file tree
Hide file tree
Showing 25 changed files with 343 additions and 308 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Developer documentation at https://livedata-ornl.readthedocs.io/en/latest/

## Contributing

Create a conda environment `livedata`, containing all the dependencies
Create a conda environment `livedata`, containing all the dependencies
```python
conda env create -f environment.yml
conda activate livedata
Expand Down Expand Up @@ -66,4 +66,4 @@ run the following command from within directory `docs/`:
make html
```
The documentation will be built in the `docs/_build/html` directory. To view the documentation,
open the `docs/_build/html/index.html` file in a web browser.
open the `docs/_build/html/index.html` file in a web browser.
2 changes: 1 addition & 1 deletion config/docker-compose.envlocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ services:

volumes:
web-static:
db-data:
db-data:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "LIVE DATA SERVER"
copyright = "2023, SAE@ORNL"
copyright = "2023, SAE@ORNL" # noqa A001
author = "SAE@ORNL"

# The version info for the project you're documenting, acts as replacement for
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/config_for_local_use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Changing it to a wildcard lets us ping it as local host and not get a 400 error.


You should now be able to interact with the api on `localhost:9999` but there's a little more.
You need to add a user that you can use for your post requests,
You need to add a user that you can use for your post requests,

.. code-block:: bash
Expand All @@ -53,7 +53,7 @@ You need to add a user that you can use for your post requests,
I personally recommend using `Postman <https://www.postman.com/>`_ when interacting with the api.
If you do, set the request body to `form-data`!

Some relevant form-data field keys:
Some relevant form-data field keys:

#. file
#. username
Expand Down
3 changes: 0 additions & 3 deletions docs/developer/service_through_apache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ Apache HTTP Server.
The `Apache configuration file <https://github.com/neutrons/live_data_server/blob/78ef6ad9b237274ac63c69b99d334657ac373633/apache/apache_django_wsgi.conf>`_
is located at ``/etc/httpd/conf.d/apache_django_wsgi.conf``, and the application is located in
``/var/www/livedata/app``.



2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Indices and tables
* :ref:`genindex`
* :ref:`search`

.. uncomment this once we include the API in the docs * :ref:`modindex`
.. uncomment this once we include the API in the docs * :ref:`modindex`
2 changes: 1 addition & 1 deletion scripts/docker-compose_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ version_validate $version ${MINIMUM_VERSION_NUMBER}
valid=$?

test $valid -eq 1 && echo "Error: Invalid docker-compose. Minimum valid version is ${MINIMUM_VERSION_NUMBER}"
exit $valid
exit $valid
101 changes: 53 additions & 48 deletions src/live_data_server/live_data_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,68 @@
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'bq!jvls*4&^r^_za38ki!@rd7p3d83(f@@@&9q!)j0=5wln3&e'
SECRET_KEY = "bq!jvls*4&^r^_za38ki!@rd7p3d83(f@@@&9q!)j0=5wln3&e"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get("APP_DEBUG", False))
#CSRF_COOKIE_SECURE = True
#SESSION_COOKIE_SECURE = True
CSRF_TRUSTED_ORIGINS = ['.ornl.gov', '.sns.gov', 'localhost', '127.0.0.1']

ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'testfixture02-test.ornl.gov', 'livedata.sns.gov', 'scse-livedata-prod1.sns.gov']
# CSRF_COOKIE_SECURE = True
# SESSION_COOKIE_SECURE = True
CSRF_TRUSTED_ORIGINS = [".ornl.gov", ".sns.gov", "localhost", "127.0.0.1"]

ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
"testfixture02-test.ornl.gov",
"livedata.sns.gov",
"scse-livedata-prod1.sns.gov",
]


# Application definition

INSTALLED_APPS = [
'plots.apps.PlotsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
"plots.apps.PlotsConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"corsheaders",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'live_data_server.urls'
ROOT_URLCONF = "live_data_server.urls"

CORS_ORIGIN_ALLOW_ALL = True

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'live_data_server.wsgi.application'
WSGI_APPLICATION = "live_data_server.wsgi.application"


# Database
Expand All @@ -93,12 +99,12 @@
"PORT": os.environ.get("DATABASE_PORT"),
}
}
DATABASES['default']['CONN_MAX_AGE']=5
DATABASES["default"]["CONN_MAX_AGE"] = 5

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'webcache',
"default": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "webcache",
}
}

Expand All @@ -107,26 +113,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'America/New_York'
TIME_ZONE = "America/New_York"

USE_I18N = True

Expand All @@ -138,8 +144,8 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/livedata/static/'
STATIC_URL = "/static/"
STATIC_ROOT = "/var/www/livedata/static/"

# Add secret key to settings only if there's a non-empty environment variable with same name
if "LIVE_PLOT_SECRET_KEY" in os.environ:
Expand All @@ -149,8 +155,7 @@

# Import local settings if available
try:
from local_settings import *
except ImportError as e:
from local_settings import * # noqa: F403
except ImportError:
LOCAL_SETTINGS = False
pass

11 changes: 6 additions & 5 deletions src/live_data_server/live_data_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: path(r'^blog/', include('blog.urls'))
"""
from django.urls import re_path, include

from django.contrib import admin
from django.urls import include, re_path
from django.views.generic.base import RedirectView

app_name = 'live_data_server'
app_name = "live_data_server"

urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^$', RedirectView.as_view(url='/plots/')),
re_path(r'^plots/', include('plots.urls', namespace="plots")),
re_path(r"^admin/", admin.site.urls),
re_path(r"^$", RedirectView.as_view(url="/plots/")),
re_path(r"^plots/", include("plots.urls", namespace="plots")),
]
12 changes: 8 additions & 4 deletions src/live_data_server/plots/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from django.contrib import admin

from plots.models import DataRun, Instrument, PlotData


class PlotDataAdmin(admin.ModelAdmin):
readonly_fields=('data_run',)
list_display = ('id', 'data_run', 'data_type', 'timestamp')
readonly_fields = ("data_run",)
list_display = ("id", "data_run", "data_type", "timestamp")


class DataRunAdmin(admin.ModelAdmin):
list_display = ('id', 'run_number', 'run_id', 'instrument', 'created_on')
list_display = ("id", "run_number", "run_id", "instrument", "created_on")


admin.site.register(DataRun, DataRunAdmin)
admin.site.register(Instrument)
admin.site.register(PlotData, PlotDataAdmin)
admin.site.register(PlotData, PlotDataAdmin)
4 changes: 1 addition & 3 deletions src/live_data_server/plots/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class PlotsConfig(AppConfig):
name = 'plots'
name = "plots"
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def add_arguments(self, parser):
parser.add_argument("--email", help="Admin's email")
parser.add_argument("--password", help="Admin's password")

def handle(self, *args, **options):
User = get_user_model()
if not User.objects.filter(username=options["username"]).exists():
User.objects.create_superuser(
def handle(self, *args, **options): # noqa: ARG002
user = get_user_model()
if not user.objects.filter(username=options["username"]).exists():
user.objects.create_superuser(
username=options["username"],
email=options["email"],
password=options["password"],
Expand Down
44 changes: 20 additions & 24 deletions src/live_data_server/plots/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-05-31 20:53
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='DataRun',
name="DataRun",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('run_number', models.IntegerField()),
('run_id', models.TextField()),
('created_on', models.DateTimeField(auto_now_add=True, verbose_name='Timestamp')),
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("run_number", models.IntegerField()),
("run_id", models.TextField()),
("created_on", models.DateTimeField(auto_now_add=True, verbose_name="Timestamp")),
],
),
migrations.CreateModel(
name='Instrument',
name="Instrument",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True)),
('run_id_type', models.IntegerField(default=0)),
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("name", models.CharField(max_length=128, unique=True)),
("run_id_type", models.IntegerField(default=0)),
],
),
migrations.CreateModel(
name='PlotData',
name="PlotData",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data_type', models.IntegerField()),
('data', models.TextField()),
('timestamp', models.DateTimeField(verbose_name='Timestamp')),
('data_run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plots.DataRun')),
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("data_type", models.IntegerField()),
("data", models.TextField()),
("timestamp", models.DateTimeField(verbose_name="Timestamp")),
("data_run", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="plots.DataRun")),
],
),
migrations.AddField(
model_name='datarun',
name='instrument',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plots.Instrument'),
model_name="datarun",
name="instrument",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="plots.Instrument"),
),
]
Loading

0 comments on commit b92ed80

Please sign in to comment.