From 9568099a801c9473f52598a8ba7ff5f648c331d9 Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Tue, 9 Feb 2016 22:35:07 +0100 Subject: [PATCH] Tidy context generation. Signed-off-by: Chris Lamb --- django_slack/api.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/django_slack/api.py b/django_slack/api.py index 900dd51..75f7f38 100644 --- a/django_slack/api.py +++ b/django_slack/api.py @@ -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': { @@ -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