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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue