build fixes and static files fix, closes #28
This commit is contained in:
parent
bff2525c65
commit
6a44ef30a3
26 changed files with 91 additions and 39 deletions
|
|
@ -1,19 +1,18 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
from accounts.models import CustomUser
|
||||
from django.contrib.auth.models import User
|
||||
class AutoLoginMiddleware:
|
||||
"""
|
||||
In development, automatically logs in as a predefined user if the request is anonymous.
|
||||
"""
|
||||
import time
|
||||
import logging
|
||||
class LogRequestsMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
# Only perform auto-login if in DEBUG mode and user is not authenticated.
|
||||
if settings.DEBUG and not request.user.is_authenticated and request.host in ['pocket-trade.fly.dev', 'localhost', '127.0.0.1']:
|
||||
user = CustomUser.objects.get(email='rob@badblocks.email')
|
||||
login(request, user, backend='django.contrib.auth.backends.ModelBackend')
|
||||
|
||||
start = time.perf_counter()
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
end = time.perf_counter()
|
||||
self.log(request, response, start, end)
|
||||
return response
|
||||
|
||||
def log(self, request, response, start, end):
|
||||
logging.info(f"{request.method} {request.path_info} -> {response.status_code}, took {end - start}s")
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,48 @@ import socket
|
|||
from pathlib import Path
|
||||
import environ
|
||||
import os
|
||||
import logging
|
||||
import sys
|
||||
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False)
|
||||
)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': 'INFO',
|
||||
'class': 'logging.StreamHandler',
|
||||
'stream': sys.stdout,
|
||||
'formatter': 'verbose',
|
||||
'filters': [],
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
},
|
||||
'django.server': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
|
@ -80,10 +117,12 @@ MIDDLEWARE = [
|
|||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"allauth.account.middleware.AccountMiddleware", # django-allauth
|
||||
"django_project.middleware.LogRequestsMiddleware",
|
||||
]
|
||||
|
||||
if DEBUG:
|
||||
MIDDLEWARE.append("django_browser_reload.middleware.BrowserReloadMiddleware")
|
||||
MIDDLEWARE.append(
|
||||
"django_browser_reload.middleware.BrowserReloadMiddleware")
|
||||
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
||||
|
||||
DAISY_SETTINGS = {
|
||||
|
|
@ -164,7 +203,7 @@ STATIC_ROOT = BASE_DIR / "staticfiles"
|
|||
STATIC_URL = "/static/"
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
|
||||
STATICFILES_DIRS = []
|
||||
STATICFILES_DIRS = [BASE_DIR / "static"]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
|
||||
MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
|
@ -211,7 +250,9 @@ INTERNAL_IPS = [
|
|||
|
||||
# for docker development
|
||||
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
|
||||
INTERNAL_IPS.append([ip[:-1] + "1" for ip in ips])
|
||||
for ip in ips:
|
||||
INTERNAL_IPS.append(ip)
|
||||
ALLOWED_HOSTS.append(ip)
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
|
||||
AUTH_USER_MODEL = "accounts.CustomUser"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ urlpatterns = [
|
|||
path('account/', include('accounts.urls')),
|
||||
path("trades/", include("trades.urls")),
|
||||
path("__reload__/", include("django_browser_reload.urls")),
|
||||
#path('silk/', include('silk.urls', namespace='silk')),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ from django.core.wsgi import get_wsgi_application
|
|||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_project.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
app = application
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue