Project

General

Profile

0002-workflows-add-a-to_unicode-option-to-the-context_fro.patch

Benjamin Dauvergne, 12 February 2014 11:36 AM

Download (1.39 KB)

View differences:

Subject: [PATCH 2/4] workflows: add a to_unicode option to the
 context_from_formdata() function

 wcs/workflows.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
wcs/workflows.py
1141 1141
                    fire_and_forget=True)
1142 1142
register_item_class(SendmailWorkflowStatusItem)
1143 1143

  
1144
def context_from_formdata(formdata, process=None):
1144
def context_from_formdata(formdata, process=None, to_unicode=False):
1145 1145
    context = {}
1146 1146
    context.update(get_publisher().substitutions.get_context_variables())
1147 1147
    context['url'] = formdata.get_url()
......
1169 1169
        if isinstance(v, unicode):
1170 1170
            context[k] = v.encode(charset, 'ignore')
1171 1171

  
1172
    if to_unicode:
1173
        for k, v in context.items():
1174
            if isinstance(v, str):
1175
                v = v.decode(charset)
1176
            if isinstance(v, unicode):
1177
                continue
1178
            v = unicode(v)
1179
            context[k] = v
1180

  
1172 1181
    return context
1173 1182

  
1174 1183
def template_on_formdata(formdata, template, process=None):
1175
-