Skip to content

Commit

Permalink
Do not create a Context instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Feb 9, 2016
1 parent 55f2eb2 commit fe72b2d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 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,9 @@
def slack_message(template, context=None, attachments=None, fail_silently=app_settings.FAIL_SILENTLY):
data = {}

context = Context(context or {})
context['settings'] = settings
context_base = {'settings': settings}
if context:
context_base.update(context)

for k, v in {
'text': {
Expand Down Expand Up @@ -58,9 +58,11 @@ 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, {
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 fe72b2d

Please sign in to comment.