Skip to content

Commit c27994e

Browse files
first commit
0 parents  commit c27994e

20 files changed

+569
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 4
5+
indent_style = space
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
end_of_line = crlf
9+
10+
[*.yml]
11+
indent_size = 2

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.venv
2+
.env
3+
__pycache__
4+
*.sqlite3
5+
staticfiles/
6+
media/
7+
.coverage
8+
htmlcov/
9+
temp/
10+
*.pid
11+
*.log

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Keep learning
2+
3+
## Develop
4+
5+
### Python version
6+
3.9
7+
8+
### Create virtual environment
9+
```
10+
python -m venv .venv
11+
```
12+
13+
### Activate virtual environment
14+
```
15+
.venv\Scripts\activate
16+
```
17+
18+
### Install dependencies
19+
```
20+
python -m pip install --upgrade pip
21+
pip install -r requirements.txt
22+
```
23+
24+
### Migrate database
25+
```
26+
python manage.py migrate
27+
```
28+
29+
### Run development server
30+
```
31+
python manage.py runserver
32+
```
33+
34+
### Debug
35+
#### For Visual studio code
36+
Just press F5 (Config is inside `.vscode/`)
37+
38+
#### For other editors
39+
Please contribute if you know how.
40+
41+
### Config environment variables
42+
Default variables should work out of the box already, but in case you want to customize, here is how.
43+
44+
Add `.env` file and write your custom variables to it.
45+
46+
Available variables and their data type can be seen in `keep_learning/settings.py`:
47+
```
48+
env = environ.Env(
49+
... # Variables are listed here
50+
)
51+
```
52+
53+
### Browsable API
54+
You can login to the browsable API and explore it to help with development.
55+
#### Collect static
56+
```
57+
python manage.py collectstatic
58+
```
59+
60+
#### Browse!
61+
Go to this URL in your brower. (You may need to register new user and then login if you haven't already)
62+
```
63+
http://localhost:8000/
64+
```

account/__init__.py

Whitespace-only changes.

account/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

account/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'account'

account/migrations/__init__.py

Whitespace-only changes.

account/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

account/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

account/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

keep-learning.code-workspace

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {}
8+
}

keep_learning/__init__.py

Whitespace-only changes.

keep_learning/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for keep_learning project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'keep_learning.settings')
15+
16+
application = get_asgi_application()

keep_learning/logger/config.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from .filters import downgrade_host_not_allowed_error
2+
3+
4+
def logging_config(base_dir):
5+
return {
6+
'version': 1,
7+
'disable_existing_loggers': False,
8+
'formatters': {
9+
'verbose': {
10+
'format': '{levelname} {asctime} {module} {message}',
11+
'style': '{',
12+
},
13+
'django.server': {
14+
'()': 'django.utils.log.ServerFormatter',
15+
'format': '[{server_time}] {message}',
16+
'style': '{',
17+
},
18+
},
19+
'filters': {
20+
'require_debug_false': {
21+
'()': 'django.utils.log.RequireDebugFalse',
22+
},
23+
'require_debug_true': {
24+
'()': 'django.utils.log.RequireDebugTrue',
25+
},
26+
'downgrade_host_not_allowed_error': {
27+
'()': 'django.utils.log.CallbackFilter',
28+
'callback': downgrade_host_not_allowed_error,
29+
},
30+
},
31+
'handlers': {
32+
'console': {
33+
'level': 'INFO',
34+
'class': 'logging.StreamHandler',
35+
'filters': ['require_debug_true'],
36+
},
37+
'django.server': {
38+
'level': 'INFO',
39+
'class': 'logging.StreamHandler',
40+
'formatter': 'django.server',
41+
},
42+
'file_info': {
43+
'level': 'INFO',
44+
'class': 'logging.FileHandler',
45+
'filename': base_dir / 'logs/info.log',
46+
'filters': ['downgrade_host_not_allowed_error', 'require_debug_false'],
47+
'formatter': 'verbose',
48+
},
49+
'file_warning': {
50+
'level': 'WARNING',
51+
'class': 'logging.FileHandler',
52+
'filename': base_dir / 'logs/warning.log',
53+
'filters': ['downgrade_host_not_allowed_error', 'require_debug_false'],
54+
'formatter': 'verbose',
55+
},
56+
'file_error': {
57+
'level': 'ERROR',
58+
'class': 'logging.FileHandler',
59+
'filename': base_dir / 'logs/error.log',
60+
'filters': ['downgrade_host_not_allowed_error', 'require_debug_false'],
61+
'formatter': 'verbose',
62+
},
63+
'mail_admins': {
64+
'level': 'ERROR',
65+
'class': 'django.utils.log.AdminEmailHandler',
66+
'filters': ['downgrade_host_not_allowed_error', 'require_debug_false'],
67+
},
68+
},
69+
'loggers': {
70+
'django': {
71+
'handlers': ['console', 'file_info', 'file_warning', 'file_error', 'mail_admins'],
72+
'level': 'INFO',
73+
},
74+
'django.server': {
75+
'handlers': ['django.server'],
76+
'level': 'INFO',
77+
'propagate': False,
78+
},
79+
'companion': {
80+
'handlers': ['console', 'file_info', 'file_warning', 'file_error', 'mail_admins'],
81+
'level': 'INFO',
82+
},
83+
'split_the_bill': {
84+
'handlers': ['console', 'file_info', 'file_warning', 'file_error', 'mail_admins'],
85+
'level': 'INFO',
86+
},
87+
'user': {
88+
'handlers': ['console', 'file_info', 'file_warning', 'file_error', 'mail_admins'],
89+
'level': 'INFO',
90+
},
91+
}
92+
}

keep_learning/logger/filters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
3+
def downgrade_host_not_allowed_error(record):
4+
if record.name == 'django.security.DisallowedHost':
5+
record.levelno = logging.WARNING
6+
record.levelname = logging.getLevelName(record.levelno)
7+
return True

0 commit comments

Comments
 (0)