I reply (again;) to myself. In order to customize flash messages, I
upgraded to TG 2.3.4.
The fact is that I actually patched tg/flash.py to allow unescaped
messages. The patch is on _render_static_version() method
def _render_static_version(self, container_id):
payload = self.pop_payload()
if not payload:
return ''
# HACK - THIS IS A PATCH
if payload.get('no_escape'):
payload['message'] = payload.get('message','')
else:
payload['message'] = escape(payload.get('message',''))
payload['container_id'] = container_id
return self.static_template.substitute(payload)
Would you be interested to integrate this into the TG2 source code,
Alessandro ? If so, what is the way to propose a patch ?
Le mardi 21 octobre 2014 13:37:49 UTC+2, lebouquetin a écrit :
>
> Thanks for the explanation.
>
> I have an issue with flash templates: links are now converted in text
> (instead of being interpreted). Is there a way to fix this ?
>
> For information, my flash template is defined like this :
>
> base_config['flash.template'] = '''
> <div>${message}</div
> '''
>
> Should I use a template instead ? Then how ?
>
> Thanks
>
> Le mardi 21 octobre 2014 11:51:46 UTC+2, lebouquetin a écrit :
>>
>> I reply to myself. I found the right documentation :
>> http://turbogears.readthedocs.org/en/latest/turbogears/webflash.html#customizing-flash
>>
>> Something I do not understand is that we have some base_config parameters
>> through attributes and some others through dict-like access. What is the
>> difference ?
>>
>> Damien
>>
>>
>> Le mardi 21 octobre 2014 11:41:21 UTC+2, lebouquetin a écrit :
>>>
>>> Hi Alessandro,
>>>
>>> I'm trying to customize the flash templates according to the release
>>> 2.3.4 documentation :
>>> http://turbogears.readthedocs.org/en/latest/reference/config-options.html#flash-messages
>>>
>>> In my app_cfg.py I added the following line :
>>>
>>> base_config.flash.template = '<div id="${container_id}">AGAGA <div
>>> class="${status}">${message}</div></div>'
>>>
>>> which result in error when running turbogears:
>>>
>>> File "/home/damien/proj/tracim-app/pod/pod/pod/config/middleware.py",
>>> line 4, in <module>
>>> from pod.config.app_cfg import base_config
>>> File "/home/damien/proj/tracim-app/pod/pod/pod/config/app_cfg.py",
>>> line 47, in <module>
>>> base_config.flash.template = '<div id="${container_id}">AGAGA <div
>>> class="${status}">${message}</div></div>'
>>> File
>>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/tg/util.py",
>>>
>>> line 21, in __getattr__
>>> return get_partial_dict(name, self, Bunch)
>>> File
>>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/tg/configuration/utils.py",
>>>
>>> line 42, in get_partial_dict
>>> raise AttributeError
>>> AttributeError
>>>
>>> What am I doing wrong ?
>>>
>>> Thanks for your answer.
>>>
>>> Damien
>>>
>>>
>>> Le lundi 15 septembre 2014 17:14:31 UTC+2, Alessandro Molina a écrit :
>>>>
>>>> Next release is planned for end of September, in worst case October.
>>>>
>>>> All features are there, I just need to update documentation to
>>>> automatically retrieve configuration options from source code and test
>>>> changes on a few big real world projects to ensure backward compatibility.
>>>>
>>>> On Mon, Sep 15, 2014 at 3:42 PM, lebouquetin <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Alessandro,
>>>>>
>>>>> I'm working on TG2.3.3 and want to customize flash message templates.
>>>>> I see that you have commit this feature at the end of july...
>>>>> My question is : should I hack TG2 or should I wait for the next
>>>>> release ? (if you already planned it)
>>>>>
>>>>> Thanks
>>>>>
>>>>> Damien
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "TurboGears" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at http://groups.google.com/group/turbogears.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.