Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit d94f73d

Browse files
committed
Merge branch dashboard into master
1 parent ac12a89 commit d94f73d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1563
-427
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data/
2+
**/*__pycache__*

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true
4+
5+
[*.py]
6+
indent_style = space
7+
indent_size = 4
8+
9+
[*.js]
10+
indent_style = space
11+
indent_size = 4
12+
13+
[package.json]
14+
indent_style = space
15+
indent_size = 2

.github/workflows/django.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ jobs:
3131
poetry run ./manage.py test
3232
env:
3333
DS_SECRET_KEY: test
34-
- name: Check PEP8
34+
- name: Check flake8
3535
run: |
36-
poetry run pycodestyle --exclude=ds/migrations/ dayliostats/ ds/
37-
env:
38-
DS_SECRET_KEY: test
36+
poetry run flake8 --extend-exclude=ds/migrations ds
3937
- name: Check isort
4038
run: |
41-
poetry run isort --check-only . --skip=ds/migrations/ --skip=node_modules/
39+
poetry run isort --check-only --skip ds/migrations ds
40+
- name: Check black
41+
run: |
42+
poetry run black --check --diff --extend-exclude=ds/migrations ds
43+
- name: Check PEP257
44+
run: |
45+
poetry run pydocstyle ds

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ db.sqlite3
88
__pycache__/
99
cachegrind.out*
1010
data/db
11+
.coverage
12+
moods.json
13+
.venv

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.3.0
4+
hooks:
5+
- id: black
6+
exclude: ds/migrations
7+
- repo: https://github.com/PyCQA/isort
8+
rev: 5.13.2
9+
hooks:
10+
- id: isort
11+
exclude: ds/migrations
12+

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Meesha
3+
Copyright (c) 2020 staticf0x
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ After cloning the repo:
2424
- `$ npm install` (this is only for development currently)
2525
- `$ poetry install`
2626

27+
### Database
28+
29+
Running from local MariaDB server, you'll need a database and a user, create
30+
them using this:
31+
32+
```mysql
33+
CREATE DATABASE dayliostats CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
34+
CREATE USER 'dayliostats'@'localhost' IDENTIFIED BY 'dayliostats';
35+
GRANT ALL PRIVILEGES ON dayliostats.* TO 'dayliostats'@'localhost';
36+
```
37+
2738
### Secret key for Django
2839

2940
Either set the `DS_SECRET_KEY` env variable directly, or read the key from a file.

dayliostats/settings.py

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,130 +18,133 @@
1818
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1919
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2020

21-
dotenv.read_dotenv(os.path.join(BASE_DIR, '.env'))
21+
dotenv.read_dotenv(os.path.join(BASE_DIR, ".env"))
2222

2323
# Quick-start development settings - unsuitable for production
2424
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
2525

2626
# SECURITY WARNING: keep the secret key used in production secret!
27-
SECRET_KEY = os.environ['DS_SECRET_KEY']
27+
SECRET_KEY = os.environ["DS_SECRET_KEY"]
2828

2929
# SECURITY WARNING: don't run with debug turned on in production!
3030
DEBUG = False
3131

3232
# This enabled the django admin console
3333
ADMIN = False
3434

35-
ALLOWED_HOSTS = ['daylio-stats.herokuapp.com', 'localhost', '127.0.0.1']
36-
35+
ALLOWED_HOSTS = ["daylio-stats.herokuapp.com", "localhost", "127.0.0.1"]
36+
# INTERNAL_IPS = ['127.0.0.1']
3737

3838
# Application definition
3939

4040
INSTALLED_APPS = [
41-
'django.contrib.admin',
42-
'django.contrib.auth',
43-
'django.contrib.contenttypes',
44-
'django.contrib.sessions',
45-
'django.contrib.messages',
46-
'django.contrib.staticfiles',
47-
'django_extensions',
48-
'ds',
41+
"django.contrib.admin",
42+
"django.contrib.auth",
43+
"django.contrib.contenttypes",
44+
"django.contrib.sessions",
45+
"django.contrib.messages",
46+
"django.contrib.staticfiles",
47+
"django_extensions",
48+
"debug_toolbar",
49+
"ds",
4950
]
5051

5152
MIDDLEWARE = [
52-
'django.middleware.security.SecurityMiddleware',
53-
'whitenoise.middleware.WhiteNoiseMiddleware',
54-
'django.contrib.sessions.middleware.SessionMiddleware',
55-
'django.middleware.common.CommonMiddleware',
56-
'django.middleware.csrf.CsrfViewMiddleware',
57-
'django.contrib.auth.middleware.AuthenticationMiddleware',
58-
'django.contrib.messages.middleware.MessageMiddleware',
59-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
"django.middleware.security.SecurityMiddleware",
54+
"whitenoise.middleware.WhiteNoiseMiddleware",
55+
"django.contrib.sessions.middleware.SessionMiddleware",
56+
"django.middleware.common.CommonMiddleware",
57+
"django.middleware.csrf.CsrfViewMiddleware",
58+
"django.contrib.auth.middleware.AuthenticationMiddleware",
59+
"django.contrib.messages.middleware.MessageMiddleware",
60+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
61+
"debug_toolbar.middleware.DebugToolbarMiddleware",
6062
]
6163

62-
ROOT_URLCONF = 'dayliostats.urls'
64+
ROOT_URLCONF = "dayliostats.urls"
6365

6466
TEMPLATES = [
6567
{
66-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
67-
'DIRS': [],
68-
'APP_DIRS': True,
69-
'OPTIONS': {
70-
'context_processors': [
71-
'django.template.context_processors.debug',
72-
'django.template.context_processors.request',
73-
'django.contrib.auth.context_processors.auth',
74-
'django.contrib.messages.context_processors.messages',
75-
'ds.context_processors.global_vars',
68+
"BACKEND": "django.template.backends.django.DjangoTemplates",
69+
"DIRS": [],
70+
"APP_DIRS": True,
71+
"OPTIONS": {
72+
"context_processors": [
73+
"django.template.context_processors.debug",
74+
"django.template.context_processors.request",
75+
"django.contrib.auth.context_processors.auth",
76+
"django.contrib.messages.context_processors.messages",
77+
"ds.context_processors.global_vars",
7678
],
7779
},
7880
},
7981
]
8082

81-
WSGI_APPLICATION = 'dayliostats.wsgi.application'
83+
WSGI_APPLICATION = "dayliostats.wsgi.application"
8284

8385

8486
# Database
8587
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
8688

8789
DATABASES = {
88-
'default': {
89-
'ENGINE': 'django.db.backends.mysql',
90-
'NAME': os.getenv('DS_DB_NAME', 'dayliostats'),
91-
'USER': os.getenv('DS_DB_USER', 'dayliostats'),
92-
'PASSWORD': os.getenv('DS_DB_PASSWORD', 'dayliostats'),
93-
'HOST': os.getenv('DS_DB_HOST', 'localhost'),
94-
'PORT': 3306,
90+
"default": {
91+
"ENGINE": "django.db.backends.mysql",
92+
"NAME": os.getenv("DS_DB_NAME", "dayliostats"),
93+
"USER": os.getenv("DS_DB_USER", "dayliostats"),
94+
"PASSWORD": os.getenv("DS_DB_PASSWORD", "dayliostats"),
95+
"HOST": os.getenv("DS_DB_HOST", "localhost"),
96+
"PORT": 3306,
97+
"OPTIONS": {
98+
"charset": "utf8mb4",
99+
},
95100
}
96101
}
97102

98-
if len(sys.argv) > 1 and sys.argv[1] == 'test':
99-
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
100-
DATABASES['default']['NAME'] = ':memory:'
103+
if len(sys.argv) > 1 and sys.argv[1] == "test":
104+
print("?")
105+
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
101106

102-
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
107+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
103108

104109
# Password validation
105110
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
106111

107112
AUTH_PASSWORD_VALIDATORS = [
108113
{
109-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
114+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
110115
},
111116
{
112-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
117+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
113118
},
114119
{
115-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
120+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
116121
},
117122
{
118-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
123+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
119124
},
120125
]
121126

122127

123128
# Internationalization
124129
# https://docs.djangoproject.com/en/3.0/topics/i18n/
125130

126-
LANGUAGE_CODE = 'en-us'
131+
LANGUAGE_CODE = "en-us"
127132

128-
TIME_ZONE = 'UTC'
133+
TIME_ZONE = "UTC"
129134

130135
USE_I18N = True
131136

132137
USE_L10N = True
133138

134139
USE_TZ = True
135140

136-
SECURE_REFERRER_POLICY = 'same-origin'
141+
SECURE_REFERRER_POLICY = "same-origin"
137142

138143
# Static files (CSS, JavaScript, Images)
139144
# https://docs.djangoproject.com/en/3.0/howto/static-files/
140-
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
141-
STATIC_URL = '/static/'
145+
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
146+
STATIC_URL = "/static/"
142147

143-
STATICFILES_DIRS = (
144-
os.path.join(BASE_DIR, 'ds', 'static'),
145-
)
148+
STATICFILES_DIRS = (os.path.join(BASE_DIR, "ds", "static"),)
146149

147150
TEST_RUNNER = "green.djangorunner.DjangoRunner"

dayliostats/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
17+
import debug_toolbar
1618
from django.contrib import admin
1719
from django.urls import include, path
1820

19-
from dayliostats.settings import ADMIN
21+
from dayliostats.settings import ADMIN, DEBUG
2022

2123
urlpatterns = [
2224
path('', include('ds.urls', namespace='ds')),
2325
]
2426

27+
if DEBUG:
28+
urlpatterns += path('__debug__/', include(debug_toolbar.urls)),
29+
2530
if ADMIN:
2631
urlpatterns += [path('admin/', admin.site.urls), ]

docker-compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "3.9"
2+
3+
services:
4+
db:
5+
image: mariadb
6+
restart: always
7+
volumes:
8+
- ./data/db:/var/lib/mysql
9+
env_file:
10+
- .env
11+
ports:
12+
- 3306:3306
13+
healthcheck:
14+
test: "/usr/bin/mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --execute \"SHOW DATABASES;\""
15+
interval: 3s
16+
timeout: 1s
17+
retries: 5
18+
security_opt:
19+
- label=type:container_runtime_t
20+
21+
daylio-stats:
22+
build: .
23+
volumes:
24+
- .:/usr/src/app
25+
ports:
26+
- 8000:8000
27+
env_file:
28+
- .env
29+
security_opt:
30+
- label=type:container_runtime_t
31+
depends_on:
32+
db:
33+
condition: service_healthy

0 commit comments

Comments
 (0)