Skip to content

Commit

Permalink
Tidy context generation.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lamb <[email protected]>
  • Loading branch information
lamby committed Feb 9, 2016
1 parent 5ae098d commit 9568099
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions django_slack/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

def slack_message(template, context=None, attachments=None, fail_silently=app_settings.FAIL_SILENTLY):
data = {}

# 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)
context = dict(context or {}, settings=settings)

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

0 comments on commit 9568099

Please sign in to comment.