Can't access to message object in notifier template

Issue #12 resolved
Dmitriy Akinin
created an issue

Postman and notification sends variables with the same names in templates:

postman ( {{{ if notification: notification.send(users=[user], label=label, extra_context={'message': object, 'action': action}) }}}

notification ( {{{ body = render_to_string("notification/email_body.txt", { "message": messages["full.txt"], }, context) }}}

Comments (7)

  1. Patrick Samson repo owner

    Can you explain why you gave up this issue? After investigations, I believe your report is valid.

    The Postman message object is available for the rendering of some of the Notification templates, such as 'full.txt'. But it is probably no more for the rendering of 'email_subject.txt' and 'email_body.txt' because of the name conflict.

    Can you confirm that?

    I plan to avoid this clash and be safer, by renaming my variables like so:

    notification.send(users=[user], label=label, extra_context={'pm_message': object, 'pm_action': action})

  2. Dmitriy Akinin reporter

    This name conflict problem occurs only in email_body.txt and email_subject.txt notification templates:

    context = Context({
        "recipient": user,
        "sender": sender,
        "notice": ugettext(notice_type.display),
        "notices_url": notices_url,
        "current_site": current_site,
    # Postman vars insert in context here:
    # Here is basic templates (full.html, full.txt, notice.html, short.txt) render :
    messages = get_formatted_messages(formats, label, context) 
    # And here notification replaces 'message' var:
    subject = "".join(render_to_string("notification/email_subject.txt", {
        "message": messages["short.txt"],
    }, context).splitlines())
    body = render_to_string("notification/email_body.txt", {
        "message": messages["full.txt"],
    }, context)

    So, vars renaming is a good idea anyway to have access them in email_body.txt and email_subject.txt.

  3. Log in to comment