From 54e4e76af9056bb59b671edd4b9a535a0fe76b8f Mon Sep 17 00:00:00 2001 From: spookyUnknownUser Date: Sun, 28 Oct 2018 23:57:36 +0200 Subject: [PATCH 1/2] Add sentry example to patterns --- docs/patterns.rst | 48 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/patterns.rst b/docs/patterns.rst index 2a2efa1..2a43477 100644 --- a/docs/patterns.rst +++ b/docs/patterns.rst @@ -156,17 +156,53 @@ settings setup is already done. In fact you can easily do something unrelated to settings, like connecting to a database:: - from configurations import Configuration + from configurations import Configuration - class Prod(Configuration): + class Prod(Configuration): + # ... + + @classmethod + def post_setup(cls): + import mango + mango.connect('enterprise') + +This is also good for things like `django-heroku +`_ and `Sentry +`_. Which require some initialization +to work, but, which you maybe don't want activated on a dev config. + +Intuitively you might want to add this kind of thing like +any other setting:: + + class Prod(Base): # ... + EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" + + sentry_sdk.init("your dsn", integrations=[DjangoIntegration()]) + +But this will still activate sentry even when you're running a Dev +configuration. What you should do, is put this in the ``post_setup`` +function. That way sentry and/or the heroku helper, will only ever +run when Prod is the selected configuration:: + + class Prod(Base): + # ... + + EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" + @classmethod def post_setup(cls): - import mango - mango.connect('enterprise') - - + """ + Heroku + Sentry initialization + """ + super(Prod, cls).post_setup() + sentry_sdk.init( + dsn=os.environ.get("your dsn"), integrations=[DjangoIntegration()] + ) + django_heroku.settings(locals()) + + .. warning:: You could do the same by overriding the ``__init__`` method of your From 6bc31023d2788f69fcac36d2b10f34ff787da3bf Mon Sep 17 00:00:00 2001 From: spookyUnknownUser Date: Mon, 29 Oct 2018 12:47:35 +0200 Subject: [PATCH 2/2] Drop heroku from example It doesn't actually work the way I thought it did. Though sentry still works great! --- docs/patterns.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/patterns.rst b/docs/patterns.rst index 2a43477..791b6ba 100644 --- a/docs/patterns.rst +++ b/docs/patterns.rst @@ -166,8 +166,7 @@ connecting to a database:: import mango mango.connect('enterprise') -This is also good for things like `django-heroku -`_ and `Sentry +This is also good for things like `Sentry `_. Which require some initialization to work, but, which you maybe don't want activated on a dev config. @@ -183,7 +182,7 @@ any other setting:: But this will still activate sentry even when you're running a Dev configuration. What you should do, is put this in the ``post_setup`` -function. That way sentry and/or the heroku helper, will only ever +function. That way sentry will only ever run when Prod is the selected configuration:: class Prod(Base): @@ -194,13 +193,13 @@ run when Prod is the selected configuration:: @classmethod def post_setup(cls): """ - Heroku + Sentry initialization + Sentry initialization """ super(Prod, cls).post_setup() sentry_sdk.init( dsn=os.environ.get("your dsn"), integrations=[DjangoIntegration()] ) - django_heroku.settings(locals()) + .. warning::