mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-10 15:04:52 +03:00
Address several comments from Code review
This commit is contained in:
parent
139e1ba89c
commit
9d2edc161f
|
@ -173,7 +173,6 @@ COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
|
||||||
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
||||||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
|
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
|
||||||
COMPRESS_URL = STATIC_URL
|
COMPRESS_URL = STATIC_URL
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- if cookiecutter.use_whitenoise == 'n' -%}
|
{%- if cookiecutter.use_whitenoise == 'n' -%}
|
||||||
# Collectfast
|
# Collectfast
|
||||||
|
@ -181,32 +180,16 @@ COMPRESS_URL = STATIC_URL
|
||||||
# https://github.com/antonagestam/collectfast#installation
|
# https://github.com/antonagestam/collectfast#installation
|
||||||
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS # noqa F405
|
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS # noqa F405
|
||||||
AWS_PRELOAD_METADATA = True
|
AWS_PRELOAD_METADATA = True
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- if cookiecutter.use_sentry == 'y' -%}
|
|
||||||
# Sentry
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
SENTRY_DSN = env('SENTRY_DSN')
|
|
||||||
SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
|
|
||||||
|
|
||||||
sentry_logging = LoggingIntegration(
|
|
||||||
level=DJANGO_SENTRY_LOG_LEVEL, # Capture info and above as breadcrumbs
|
|
||||||
event_level=None # Send no events from log messages
|
|
||||||
)
|
|
||||||
|
|
||||||
sentry_sdk.init(
|
|
||||||
dsn="SENTRY_DSN",
|
|
||||||
integrations=[sentry_logging, DjangoIntegration()]
|
|
||||||
)
|
|
||||||
{%- else %}
|
|
||||||
# LOGGING
|
# LOGGING
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
||||||
|
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
||||||
|
# more details on how to customize your logging configuration.
|
||||||
|
{%- if cookiecutter.use_sentry == 'n' -%}
|
||||||
# A sample logging configuration. The only tangible logging
|
# A sample logging configuration. The only tangible logging
|
||||||
# performed by this configuration is to send an email to
|
# performed by this configuration is to send an email to
|
||||||
# the site admins on every HTTP 500 error when DEBUG=False.
|
# the site admins on every HTTP 500 error when DEBUG=False.
|
||||||
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
|
||||||
# more details on how to customize your logging configuration.
|
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
|
@ -246,7 +229,57 @@ LOGGING = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{% else %}
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': True,
|
||||||
|
'formatters': {
|
||||||
|
'verbose': {
|
||||||
|
'format': '%(levelname)s %(asctime)s %(module)s '
|
||||||
|
'%(process)d %(thread)d %(message)s'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'verbose'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'django.db.backends': {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'handlers': ['console'],
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
# Errors logged by the SDK itself
|
||||||
|
'sentry_sdk': {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'handlers': ['console'],
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
'django.security.DisallowedHost': {
|
||||||
|
'level': 'ERROR',
|
||||||
|
'handlers': ['console'],
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sentry
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
SENTRY_DSN = env('SENTRY_DSN')
|
||||||
|
SENTRY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
|
||||||
|
|
||||||
|
sentry_logging = LoggingIntegration(
|
||||||
|
level=SENTRY_LOGLEVEL, # Capture info and above as breadcrumbs
|
||||||
|
event_level=None, # Send no events from log messages
|
||||||
|
)
|
||||||
|
|
||||||
|
sentry_sdk.init(
|
||||||
|
dsn=SENTRY_DSN,
|
||||||
|
integrations=[sentry_logging, DjangoIntegration()]
|
||||||
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -22,11 +22,7 @@ from django.core.wsgi import get_wsgi_application
|
||||||
# {{ cookiecutter.project_slug }} directory.
|
# {{ cookiecutter.project_slug }} directory.
|
||||||
app_path = os.path.abspath(os.path.join(
|
app_path = os.path.abspath(os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)), os.pardir))
|
os.path.dirname(os.path.abspath(__file__)), os.pardir))
|
||||||
sys.path.append(os.path.join(app_path, '{{ cookiecutter.project_slug }}'))
|
sys.path.append(os.path.join(app_path, "{{ cookiecutter.project_slug }}"))
|
||||||
{% if cookiecutter.use_sentry == 'y' -%}
|
|
||||||
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
|
|
||||||
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
|
|
||||||
{%- endif %}
|
|
||||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||||
|
@ -37,10 +33,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
|
||||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||||
# setting points here.
|
# setting points here.
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
{% if cookiecutter.use_sentry == 'y' -%}
|
|
||||||
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
|
|
||||||
application = Sentry(application)
|
|
||||||
{%- endif %}
|
|
||||||
# Apply WSGI middleware here.
|
# Apply WSGI middleware here.
|
||||||
# from helloworld.wsgi import HelloWorldApplication
|
# from helloworld.wsgi import HelloWorldApplication
|
||||||
# application = HelloWorldApplication(application)
|
# application = HelloWorldApplication(application)
|
||||||
|
|
|
@ -8,7 +8,7 @@ psycopg2==2.7.4 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
|
||||||
Collectfast==0.6.2 # https://github.com/antonagestam/collectfast
|
Collectfast==0.6.2 # https://github.com/antonagestam/collectfast
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if cookiecutter.use_sentry == "y" %}
|
{%- if cookiecutter.use_sentry == "y" %}
|
||||||
sentry-sdk==0.3.7 # https://docs.sentry.io/quickstart/?platform=python
|
sentry-sdk==0.7.6 # https://github.com/getsentry/sentry-python
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{% if cookiecutter.use_celery == 'y' %}
|
{% if cookiecutter.use_celery == 'y' %}
|
||||||
import os
|
import os
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
|
|
||||||
from django.apps import apps, AppConfig
|
from django.apps import apps, AppConfig
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
@ -26,26 +25,29 @@ class CeleryAppConfig(AppConfig):
|
||||||
def ready(self):
|
def ready(self):
|
||||||
installed_apps = [app_config.name for app_config in apps.get_app_configs()]
|
installed_apps = [app_config.name for app_config in apps.get_app_configs()]
|
||||||
app.autodiscover_tasks(lambda: installed_apps, force=True)
|
app.autodiscover_tasks(lambda: installed_apps, force=True)
|
||||||
{% if cookiecutter.use_sentry == 'y' -%}
|
|
||||||
{% if cookiecutter.use_pycharm == 'y' -%}
|
{% if cookiecutter.use_sentry == 'y' -%}
|
||||||
# Since raven is required in production only,
|
if hasattr(settings, "SENTRY_DSN"):
|
||||||
|
# Celery signal registration
|
||||||
|
{% if cookiecutter.use_pycharm == 'y' -%}
|
||||||
|
# Since Sentry is required in production only,
|
||||||
# imports might (most surely will) be wiped out
|
# imports might (most surely will) be wiped out
|
||||||
# during PyCharm code clean up started
|
# during PyCharm code clean up started
|
||||||
# in other environments.
|
# in other environments.
|
||||||
# @formatter:off
|
# @formatter:off
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from sentry_sdk.integrations.celery import CeleryIntegration
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
||||||
from sentry_sdk.integrations.logging import LoggingIntegration
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||||
{% if cookiecutter.use_pycharm == 'y' -%}
|
{% if cookiecutter.use_pycharm == 'y' -%}
|
||||||
# @formatter:on
|
# @formatter:on
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
sentry_logging = LoggingIntegration(
|
sentry_logging = LoggingIntegration(
|
||||||
level=settings.SENTRY_CELERY_LOGLEVEL, # Capture info and above as breadcrumbs
|
level=settings.SENTRY_LOGLEVEL, # Capture info and above as breadcrumbs
|
||||||
event_level=None # Send no events from log messages
|
event_level=None, # Send no events from log messages
|
||||||
)
|
)
|
||||||
sentry_sdk.init(dsn=settings.SENTRY_DSN, integrations=[sentry_logging, CeleryIntegration()])
|
sentry_sdk.init(dsn=settings.SENTRY_DSN, integrations=[sentry_logging, CeleryIntegration()])
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user