Skip to content

Commit

Permalink
Merge pull request #39 from ccnmtl/sentry-js-template
Browse files Browse the repository at this point in the history
Add ctlsettings/sentry_js.html template partial
  • Loading branch information
nikolas authored Oct 10, 2024
2 parents a89bc74 + 3f53e6b commit 1572e11
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
====================
* Added a custom context processor to make settings available in
templates.
* Added 'testing' environment when running tests.
* Added sentry_js.html template partial, to unify the code for this
setup.

0.3.6 (2024-10-09)
====================
Expand Down
1 change: 1 addition & 0 deletions ctlsettings/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ def env(request):
return {
'STAGING_ENV': getattr(settings, 'STAGING_ENV', False),
'ENVIRONMENT': getattr(settings, 'ENVIRONMENT', 'development'),
'SENTRY_KEY': getattr(settings, 'SENTRY_KEY', None),
}
3 changes: 2 additions & 1 deletion ctlsettings/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def common(**kwargs):
}

if 'test' in sys.argv or 'jenkins' in sys.argv:
ENVIRONMENT = 'testing'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
Expand Down Expand Up @@ -110,7 +111,7 @@ def common(**kwargs):
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(base, "templates"),
os.path.join(base, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
Expand Down
26 changes: 26 additions & 0 deletions ctlsettings/templates/ctlsettings/sentry_js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% if SENTRY_KEY %}

<script>
window.sentryOnLoad = function() {
Sentry.init({
environment: '{{ ENVIRONMENT }}'
});

{% if request.user.is_anonymous %}
Sentry.setUser({
email: 'none',
id: 'anonymous'
});
{% else %}
Sentry.setUser({
email: '{{ request.user.email }}',
id: '{{ request.user.username }}'
});
{% endif %}
};
</script>

<script src="https://js.sentry-cdn.com/{{ SENTRY_KEY }}.min.js"
crossorigin="anonymous"></script>

{% endif %}
15 changes: 9 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
url='https://github.com/ccnmtl/ctlsettings',
description='Columbia CTL common Django base settings',
long_description='common settings we use across all our projects',
install_requires = [
install_requires=[
'django-cas-ng',
'django-debug-toolbar',
'coverage',
Expand All @@ -23,9 +23,12 @@
'gunicorn',
'django-impersonate',
],
scripts = [],
license = 'GPL-3.0-or-later',
platforms = ['any'],
package_data = {'' : ['*.*']},
packages = ['ctlsettings'],
scripts=[],
license='GPL-3.0-or-later',
platforms=['any'],
packages=['ctlsettings', 'ctlsettings.templates'],
package_data={
'ctlsettings': ['*.py'],
'ctlsettings.templates': ['*/*.html'],
},
)

0 comments on commit 1572e11

Please sign in to comment.