Skip to content

Commit

Permalink
Merge pull request #31 from percipient/deprecation-warn
Browse files Browse the repository at this point in the history
Do not create a Context instance.
  • Loading branch information
lamby committed Feb 9, 2016
2 parents 55f2eb2 + c9cba23 commit 5ae098d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions django_slack/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

from django.conf import settings
from django.template import Context
from django.template.loader import render_to_string

from . import app_settings
Expand All @@ -12,8 +11,11 @@
def slack_message(template, context=None, attachments=None, fail_silently=app_settings.FAIL_SILENTLY):
data = {}

context = Context(context or {})
context['settings'] = settings
# The context passed into each template.
context_base = {'settings': settings}
# Update this with the passed in context, if provided.
if context is not None:
context_base.update(context)

for k, v in {
'text': {
Expand Down Expand Up @@ -58,9 +60,12 @@ def slack_message(template, context=None, attachments=None, fail_silently=app_se
# Render template if necessary
if v.get('render', True):
try:
val = render_to_string(template, {
# Create a context just for this template.
temp_context = {
'django_slack': 'django_slack/%s' % k,
}, context).strip().encode('utf8', 'ignore')
}
temp_context.update(context_base)
val = render_to_string(template, temp_context).strip().encode('utf8', 'ignore')
except Exception:
if fail_silently:
return
Expand Down

0 comments on commit 5ae098d

Please sign in to comment.