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:
Jens Langhammer 2019-06-25 18:00:54 +02:00
parent 3b2c2d781f
commit a798412e17
16 changed files with 69 additions and 50 deletions

View file

@ -4,7 +4,7 @@ import os
import sys import sys
if __name__ == '__main__': if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.core.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.root.settings')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:

View file

@ -5,9 +5,9 @@ from django.views.generic import TemplateView
from passbook.admin.mixins import AdminRequiredMixin from passbook.admin.mixins import AdminRequiredMixin
from passbook.core import __version__ from passbook.core import __version__
from passbook.core.celery import CELERY_APP
from passbook.core.models import (Application, Factor, Invitation, Policy, from passbook.core.models import (Application, Factor, Invitation, Policy,
Provider, Source, User) Provider, Source, User)
from passbook.root.celery import CELERY_APP
class AdministrationOverviewView(AdminRequiredMixin, TemplateView): class AdministrationOverviewView(AdminRequiredMixin, TemplateView):

View file

@ -14,6 +14,7 @@ class PassbookCoreConfig(AppConfig):
name = 'passbook.core' name = 'passbook.core'
label = 'passbook_core' label = 'passbook_core'
verbose_name = 'passbook Core' verbose_name = 'passbook Core'
mountpoint = ''
def ready(self): def ready(self):
import_module('passbook.core.policies') import_module('passbook.core.policies')

View file

@ -26,5 +26,5 @@ class Command(BaseCommand):
'-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec '-b', CONFIG.y('web.listen', '0.0.0.0'), # nosec
'--access-log', '/dev/null', '--access-log', '/dev/null',
'--application-close-timeout', '500', '--application-close-timeout', '500',
'passbook.core.asgi:application' 'passbook.root.asgi:application'
]) ])

View file

@ -5,7 +5,7 @@ from logging import getLogger
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import autoreload from django.utils import autoreload
from passbook.core.celery import CELERY_APP from passbook.root.celery import CELERY_APP
LOGGER = getLogger(__name__) LOGGER = getLogger(__name__)

View file

@ -7,8 +7,8 @@ from celery.exceptions import TimeoutError as CeleryTimeoutError
from django.core.cache import cache from django.core.cache import cache
from ipware import get_client_ip from ipware import get_client_ip
from passbook.core.celery import CELERY_APP
from passbook.core.models import Policy, User from passbook.core.models import Policy, User
from passbook.root.celery import CELERY_APP
LOGGER = getLogger(__name__) LOGGER = getLogger(__name__)

View file

@ -6,9 +6,9 @@ from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.html import strip_tags from django.utils.html import strip_tags
from passbook.core.celery import CELERY_APP
from passbook.core.models import Nonce from passbook.core.models import Nonce
from passbook.lib.config import CONFIG from passbook.lib.config import CONFIG
from passbook.root.celery import CELERY_APP
LOGGER = getLogger(__name__) LOGGER = getLogger(__name__)

View file

@ -1,25 +1,14 @@
"""passbook URL Configuration""" """passbook URL Configuration"""
from logging import getLogger from logging import getLogger
from django.conf import settings from django.urls import path
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
from passbook.core.auth import view from passbook.core.auth import view
from passbook.core.views import authentication, error, overview, user from passbook.core.views import authentication, overview, user
from passbook.lib.utils.reflection import get_apps
LOGGER = getLogger(__name__) LOGGER = getLogger(__name__)
admin.autodiscover()
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
handler400 = error.BadRequestView.as_view() urlpatterns = [
handler403 = error.ForbiddenView.as_view()
handler404 = error.NotFoundView.as_view()
handler500 = error.ServerErrorView.as_view()
core_urls = [
# Authentication views # Authentication views
path('auth/login/', authentication.LoginView.as_view(), name='auth-login'), path('auth/login/', authentication.LoginView.as_view(), name='auth-login'),
path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'), path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'),
@ -39,27 +28,3 @@ core_urls = [
# Overview # Overview
path('', overview.OverviewView.as_view(), name='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

View file

@ -1,17 +1,29 @@
"""passbook sentry integration""" """passbook sentry integration"""
from logging import getLogger
LOGGER = getLogger(__name__)
def before_send(event, hint): def before_send(event, hint):
"""Check if error is database error, and ignore if so""" """Check if error is database error, and ignore if so"""
from django.db import OperationalError
from django_redis.exceptions import ConnectionInterrupted from django_redis.exceptions import ConnectionInterrupted
from django.db import OperationalError, InternalError
ignored_classes = [ from rest_framework.exceptions import APIException
from billiard.exceptions import WorkerLostError
from django.core.exceptions import DisallowedHost
ignored_classes = (
OperationalError, OperationalError,
ConnectionInterrupted, ConnectionInterrupted,
] APIException,
InternalError,
ConnectionResetError,
WorkerLostError,
DisallowedHost,
ConnectionResetError,
)
if 'exc_info' in hint: if 'exc_info' in hint:
_exc_type, exc_value, _ = hint['exc_info'] _exc_type, exc_value, _ = hint['exc_info']
if isinstance(exc_value, ignored_classes): if isinstance(exc_value, ignored_classes):
LOGGER.info("Supressing error %r", exc_value)
return None return None
return event return event

View file

View file

@ -8,6 +8,6 @@ import os
import django import django
from channels.routing import get_default_application 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() django.setup()
application = get_default_application() application = get_default_application()

View file

@ -7,7 +7,7 @@ from celery import Celery, signals
from django.conf import settings from django.conf import settings
# set the default Django settings module for the 'celery' program. # 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__) LOGGER = logging.getLogger(__name__)

41
passbook/root/urls.py Normal file
View 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