separate passbook.core into passbook.root and passbook.core
Move Main Django Project into passbook.root while passbook.core holds core functionality. passbook.root contains main settings, ASGI & WSGI, celery and URLs.
This commit is contained in:
parent
3b2c2d781f
commit
a798412e17
|
@ -4,7 +4,7 @@ import os
|
|||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.core.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.root.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
|
|
|
@ -5,9 +5,9 @@ from django.views.generic import TemplateView
|
|||
|
||||
from passbook.admin.mixins import AdminRequiredMixin
|
||||
from passbook.core import __version__
|
||||
from passbook.core.celery import CELERY_APP
|
||||
from passbook.core.models import (Application, Factor, Invitation, Policy,
|
||||
Provider, Source, User)
|
||||
from passbook.root.celery import CELERY_APP
|
||||
|
||||
|
||||
class AdministrationOverviewView(AdminRequiredMixin, TemplateView):
|
||||
|
|
|
@ -14,6 +14,7 @@ class PassbookCoreConfig(AppConfig):
|
|||
name = 'passbook.core'
|
||||
label = 'passbook_core'
|
||||
verbose_name = 'passbook Core'
|
||||
mountpoint = ''
|
||||
|
||||
def ready(self):
|
||||
import_module('passbook.core.policies')
|
||||
|
|
|
@ -26,5 +26,5 @@ class Command(BaseCommand):
|
|||
'-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec
|
||||
'--access-log', '/dev/null',
|
||||
'--application-close-timeout', '500',
|
||||
'passbook.core.asgi:application'
|
||||
'passbook.root.asgi:application'
|
||||
])
|
||||
|
|
|
@ -5,7 +5,7 @@ from logging import getLogger
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.utils import autoreload
|
||||
|
||||
from passbook.core.celery import CELERY_APP
|
||||
from passbook.root.celery import CELERY_APP
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ from celery.exceptions import TimeoutError as CeleryTimeoutError
|
|||
from django.core.cache import cache
|
||||
from ipware import get_client_ip
|
||||
|
||||
from passbook.core.celery import CELERY_APP
|
||||
from passbook.core.models import Policy, User
|
||||
from passbook.root.celery import CELERY_APP
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ from django.core.mail import EmailMultiAlternatives
|
|||
from django.template.loader import render_to_string
|
||||
from django.utils.html import strip_tags
|
||||
|
||||
from passbook.core.celery import CELERY_APP
|
||||
from passbook.core.models import Nonce
|
||||
from passbook.lib.config import CONFIG
|
||||
from passbook.root.celery import CELERY_APP
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
"""passbook URL Configuration"""
|
||||
from logging import getLogger
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.views.generic import RedirectView
|
||||
from django.urls import path
|
||||
|
||||
from passbook.core.auth import view
|
||||
from passbook.core.views import authentication, error, overview, user
|
||||
from passbook.lib.utils.reflection import get_apps
|
||||
from passbook.core.views import authentication, overview, user
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
admin.autodiscover()
|
||||
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
|
||||
|
||||
handler400 = error.BadRequestView.as_view()
|
||||
handler403 = error.ForbiddenView.as_view()
|
||||
handler404 = error.NotFoundView.as_view()
|
||||
handler500 = error.ServerErrorView.as_view()
|
||||
|
||||
core_urls = [
|
||||
urlpatterns = [
|
||||
# Authentication views
|
||||
path('auth/login/', authentication.LoginView.as_view(), name='auth-login'),
|
||||
path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'),
|
||||
|
@ -39,27 +28,3 @@ core_urls = [
|
|||
# Overview
|
||||
path('', overview.OverviewView.as_view(), name='overview'),
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
# Core (include our own URLs so namespaces are used everywhere)
|
||||
path('', include((core_urls, 'passbook_core'), namespace='passbook_core')),
|
||||
]
|
||||
|
||||
for _passbook_app in get_apps():
|
||||
if hasattr(_passbook_app, 'mountpoint'):
|
||||
_path = path(_passbook_app.mountpoint, include((_passbook_app.name+'.urls',
|
||||
_passbook_app.label),
|
||||
namespace=_passbook_app.label))
|
||||
urlpatterns.append(_path)
|
||||
LOGGER.debug("Loaded %s's URLs", _passbook_app.name)
|
||||
|
||||
urlpatterns += [
|
||||
# Administration
|
||||
path('administration/django/', admin.site.urls),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
urlpatterns = [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
"""passbook sentry integration"""
|
||||
from logging import getLogger
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
def before_send(event, hint):
|
||||
"""Check if error is database error, and ignore if so"""
|
||||
from django.db import OperationalError
|
||||
from django_redis.exceptions import ConnectionInterrupted
|
||||
|
||||
ignored_classes = [
|
||||
from django.db import OperationalError, InternalError
|
||||
from rest_framework.exceptions import APIException
|
||||
from billiard.exceptions import WorkerLostError
|
||||
from django.core.exceptions import DisallowedHost
|
||||
ignored_classes = (
|
||||
OperationalError,
|
||||
ConnectionInterrupted,
|
||||
]
|
||||
APIException,
|
||||
InternalError,
|
||||
ConnectionResetError,
|
||||
WorkerLostError,
|
||||
DisallowedHost,
|
||||
ConnectionResetError,
|
||||
)
|
||||
if 'exc_info' in hint:
|
||||
_exc_type, exc_value, _ = hint['exc_info']
|
||||
if isinstance(exc_value, ignored_classes):
|
||||
LOGGER.info("Supressing error %r", exc_value)
|
||||
return None
|
||||
return event
|
||||
|
|
0
passbook/root/__init__.py
Normal file
0
passbook/root/__init__.py
Normal file
|
@ -8,6 +8,6 @@ import os
|
|||
import django
|
||||
from channels.routing import get_default_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.core.settings")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings")
|
||||
django.setup()
|
||||
application = get_default_application()
|
|
@ -7,7 +7,7 @@ from celery import Celery, signals
|
|||
from django.conf import settings
|
||||
|
||||
# set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.core.settings")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings")
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
41
passbook/root/urls.py
Normal file
41
passbook/root/urls.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""passbook URL Configuration"""
|
||||
from logging import getLogger
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from passbook.core.views import error
|
||||
from passbook.lib.utils.reflection import get_apps
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
admin.autodiscover()
|
||||
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
|
||||
|
||||
handler400 = error.BadRequestView.as_view()
|
||||
handler403 = error.ForbiddenView.as_view()
|
||||
handler404 = error.NotFoundView.as_view()
|
||||
handler500 = error.ServerErrorView.as_view()
|
||||
|
||||
urlpatterns = [
|
||||
]
|
||||
|
||||
for _passbook_app in get_apps():
|
||||
if hasattr(_passbook_app, 'mountpoint'):
|
||||
_path = path(_passbook_app.mountpoint, include((_passbook_app.name+'.urls',
|
||||
_passbook_app.label),
|
||||
namespace=_passbook_app.label))
|
||||
urlpatterns.append(_path)
|
||||
LOGGER.debug("Loaded %s's URLs", _passbook_app.name)
|
||||
|
||||
urlpatterns += [
|
||||
# Administration
|
||||
path('administration/django/', admin.site.urls),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
urlpatterns = [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
Reference in a new issue