Projet

Général

Profil

0001-misc-force-str-on-gettext-strings-used-with-Template.patch

Frédéric Péters, 19 avril 2022 07:55

Télécharger (17,8 ko)

Voir les différences:

Subject: [PATCH 1/5] misc: force str() on gettext strings used with TemplateIO
 (#64295)

Lazy gettext strings from Django have a __radd__ method in 3.2 and this
makes adding to TemplateIO raise a TypeError (unsupported operand type(s)
for +: 'TemplateIO' and 'str')
 wcs/admin/fields.py               |  2 +-
 wcs/admin/forms.py                | 15 +++++++++------
 wcs/admin/roles.py                |  2 +-
 wcs/admin/settings.py             |  2 +-
 wcs/admin/users.py                | 15 ++++++++-------
 wcs/admin/utils.py                |  4 ++--
 wcs/admin/workflows.py            | 20 +++++++++++++-------
 wcs/backoffice/management.py      | 10 ++++++----
 wcs/fields.py                     |  4 ++--
 wcs/forms/common.py               |  9 +++++----
 wcs/forms/preview.py              |  2 +-
 wcs/qommon/admin/emails.py        |  2 +-
 wcs/qommon/errors.py              |  2 +-
 wcs/qommon/form.py                |  2 +-
 wcs/qommon/ident/franceconnect.py |  4 ++--
 wcs/wf/wscall.py                  |  4 ++--
 wcs/workflows.py                  |  4 ++--
 17 files changed, 58 insertions(+), 45 deletions(-)
wcs/admin/fields.py
489 489
                    current_page_no += 1
490 490
                if str(field.id) == self.page_id:
491 491
                    r += ' - '
492
                    r += _('page %d') % current_page_no
492
                    r += str(_('page %d') % current_page_no)
493 493
                    r += ' - '
494 494
                    r += field.label
495 495
        r += htmltext('</h2>')
wcs/admin/forms.py
216 216
        if hasattr(self.objectdef, 'disabled') and self.objectdef.disabled:
217 217
            r = TemplateIO(html=True)
218 218
            r += htmltext('<div class="warningnotice">')
219
            r += _('This form is currently disabled.')
219
            r += str(_('This form is currently disabled.'))
220 220
            if hasattr(self.objectdef, 'disabled_redirection') and self.objectdef.disabled_redirection:
221 221
                r += htmltext(' (<a href="%s">') % self.objectdef.disabled_redirection
222
                r += _('redirection')
222
                r += str(_('redirection'))
223 223
                r += htmltext('</a>)')
224 224
            r += htmltext(' <a href="../enable?back=fields">%s</a>') % _('Enable')
225 225
            r += htmltext('</div>')
......
1165 1165
            self.html_top(title=self.formdef.name)
1166 1166
            r = TemplateIO(html=True)
1167 1167
            r += htmltext('<p>')
1168
            r += _('From %(here)s to %(there)s') % {
1169
                'here': self.formdef.workflow.name,
1170
                'there': new_workflow.name,
1171
            }
1168
            r += str(
1169
                _('From %(here)s to %(there)s')
1170
                % {
1171
                    'here': self.formdef.workflow.name,
1172
                    'there': new_workflow.name,
1173
                }
1174
            )
1172 1175
            r += htmltext('</p>')
1173 1176
            r += form.render()
1174 1177
            return r.getvalue()
wcs/admin/roles.py
115 115
                r += htmltext('<p>%s</p>') % self.role.details
116 116

  
117 117
            if self.role.emails:
118
                r += _('Emails:')
118
                r += str(_('Emails:'))
119 119
                r += htmltext('<ul>')
120 120
                for email in self.role.emails:
121 121
                    r += htmltext('<li>%s</li>') % email
wcs/admin/settings.py
403 403
            r += htmltext('</ul>')
404 404
        else:
405 405
            r += htmltext('<div class="infonotice"><p>')
406
            r += _('There are no file type defined at the moment.')
406
            r += str(_('There are no file type defined at the moment.'))
407 407
            r += htmltext('</p></div>')
408 408

  
409 409
        r += htmltext('<h3>%s</h3>') % _('New file type')
wcs/admin/users.py
134 134

  
135 135
        if self.user.deleted_timestamp:
136 136
            r += htmltext('<div class="warningnotice">')
137
            r += _('Marked as deleted on %(date)s.') % {
138
                'date': misc.localstrftime(self.user.deleted_timestamp)
139
            }
137
            r += str(
138
                _('Marked as deleted on %(date)s.')
139
                % {'date': misc.localstrftime(self.user.deleted_timestamp)}
140
            )
140 141
            r += htmltext('</div>')
141 142

  
142 143
        r += htmltext('<div class="splitcontent-left">')
......
193 194
                except KeyError:
194 195
                    # removed role ?
195 196
                    r += htmltext('<li><em>')
196
                    r += _('Unknown role (%s)') % k
197
                    r += str(_('Unknown role (%s)') % k)
197 198
                    r += htmltext('</em></li>')
198 199
            r += htmltext('</ul></div>')
199 200
            r += htmltext('</div>')
......
218 219
                        label = pid
219 220
                    federation = identity.getFederation(pid)
220 221
                    r += htmltext('<li>')
221
                    r += _('Account federated with %s') % label
222
                    r += str(_('Account federated with %s') % label)
222 223
                    r += htmltext('<br />')
223 224
                    if federation.localNameIdentifier:
224
                        r += _("local: ") + federation.localNameIdentifier.content
225
                        r += str(_("local: ") + federation.localNameIdentifier.content)
225 226
                    if federation.remoteNameIdentifier:
226
                        r += _("remote: ") + federation.remoteNameIdentifier.content
227
                        r += str(_("remote: ") + federation.remoteNameIdentifier.content)
227 228
                    r += htmltext('</li>')
228 229
                r += htmltext('</ul></div>')
229 230

  
wcs/admin/utils.py
33 33
            if get_request().user and str(get_request().user.id) != user_id:
34 34
                warning_class = 'recent'
35 35
        r += htmltext('<p class="last-modification %s">') % warning_class
36
        r += _('Last Modification:')
36
        r += str(_('Last Modification:'))
37 37
        r += ' '
38 38
        r += localstrftime(timestamp)
39 39
        r += ' '
40 40
        if user_id:
41 41
            try:
42
                r += _('by %s') % get_publisher().user_class.get(user_id).display_name
42
                r += str(_('by %s') % get_publisher().user_class.get(user_id).display_name)
43 43
            except KeyError:
44 44
                pass
45 45
        r += htmltext('</p>')
wcs/admin/workflows.py
803 803
            r = TemplateIO(html=True)
804 804
            r += htmltext('<h2>%s %s</h2>') % (_('Deleting Status:'), self.status.name)
805 805
            r += htmltext('<p>')
806
            r += _(
807
                '''There are forms set to this status, they need to be changed before
806
            r += str(
807
                _(
808
                    '''There are forms set to this status, they need to be changed before
808 809
                 this status can be deleted.'''
810
                )
809 811
            )
810 812
            r += htmltext('</p>')
811 813

  
......
1336 1338
                r += htmltext('<ul id="items-list" class="biglist readonly">')
1337 1339
            else:
1338 1340
                r += htmltext('<p class="items">')
1339
                r += _('Use drag and drop with the handles to reorder items.')
1341
                r += str(_('Use drag and drop with the handles to reorder items.'))
1340 1342
                r += htmltext('</p>')
1341 1343
                r += htmltext('<ul id="items-list" class="biglist sortable">')
1342 1344
            for item in self.action.items:
......
1431 1433
        r = TemplateIO(html=True)
1432 1434
        if self.workflow.is_default():
1433 1435
            r += htmltext('<p>')
1434
            r += _(
1435
                '''This is the default workflow, you cannot edit it but you can
1436
            r += str(
1437
                _(
1438
                    '''This is the default workflow, you cannot edit it but you can
1436 1439
                 duplicate it to base your own workflow on it.'''
1440
                )
1437 1441
            )
1438 1442
            r += htmltext('</p>')
1439 1443
        else:
......
1636 1640

  
1637 1641
        if self.workflow.is_default():
1638 1642
            r += htmltext('<p>')
1639
            r += _(
1640
                '''This is the default workflow, you cannot edit it but you can
1643
            r += str(
1644
                _(
1645
                    '''This is the default workflow, you cannot edit it but you can
1641 1646
                 duplicate it to base your own workflow on it.'''
1647
                )
1642 1648
            )
1643 1649
            r += htmltext('</p>')
1644 1650
        elif self.workflow.is_readonly():
wcs/backoffice/management.py
514 514
                    klass = 'badge'
515 515
                r += htmltext('<p class="details %s">' % klass)
516 516
                if no_pending:
517
                    r += _('%(pending)s open on %(total)s') % {'pending': no_pending, 'total': no_total}
517
                    r += str(_('%(pending)s open on %(total)s') % {'pending': no_pending, 'total': no_total})
518 518
                else:
519 519
                    r += ngettext('%(total)s item', '%(total)s items', no_total) % {'total': no_total}
520 520
                r += htmltext('</p>')
......
2935 2935
        r = TemplateIO(html=True)
2936 2936
        if get_session() and get_session().is_anonymous_submitter(self.filled):
2937 2937
            r += htmltext('<div class="infonotice">')
2938
            r += _(
2939
                'This form has been accessed via its tracking code, it is '
2940
                'therefore displayed like you were also its owner.'
2938
            r += str(
2939
                _(
2940
                    'This form has been accessed via its tracking code, it is '
2941
                    'therefore displayed like you were also its owner.'
2942
                )
2941 2943
            )
2942 2944
            r += htmltext('</div>')
2943 2945
        r += super().receipt(*args, **kwargs)
wcs/fields.py
1326 1326
            r += htmltext('<tr>')
1327 1327
            r += htmltext('<td class="label">')
1328 1328
            if o is True:
1329
                r += _('Yes')
1329
                r += str(_('Yes'))
1330 1330
                value = True
1331 1331
            else:
1332
                r += _('No')
1332
                r += str(_('No'))
1333 1333
                value = False
1334 1334
            r += htmltext('</td>')
1335 1335
            no = len([None for x in values if self.convert_value_from_str(x.data.get(self.id)) is value])
wcs/forms/common.py
249 249
        endpoint_status = self.formdef.workflow.get_endpoint_status()
250 250
        r += htmltext('<p>')
251 251
        if self.filled.status in ['wf-%s' % x.id for x in endpoint_status]:
252
            r += _('Your case has been handled by:')
252
            r += str(_('Your case has been handled by:'))
253 253
        else:
254
            r += _('Your case is handled by:')
254
            r += str(_('Your case is handled by:'))
255 255
        r += htmltext('</p>')
256 256
        r += htmltext('<p id="receiver">')
257 257
        r += htmltext(handling_role.details.replace('\n', '<br />'))
......
629 629
                    visitor_users.append('%s (%s)' % (visitor_name, time_ago))
630 630
                if visitor_users:
631 631
                    r += htmltext('<div id="lock-notice" class="infonotice"><p>')
632
                    r += _('Be warned forms of this user are also being looked at by: %s.') % ', '.join(
633
                        visitor_users
632
                    r += str(
633
                        _('Be warned forms of this user are also being looked at by: %s.')
634
                        % ', '.join(visitor_users)
634 635
                    )
635 636
                    r += ' '
636 637
                    r += htmltext('</p>')
wcs/forms/preview.py
41 41
        self.html_top(self.formdef.name)
42 42
        r = TemplateIO(html=True)
43 43
        r += htmltext('<div class="warningnotice"><p>')
44
        r += _('This was only a preview: form was not actually submitted.')
44
        r += str(_('This was only a preview: form was not actually submitted.'))
45 45
        r += htmltext(' <a href=".">%s</a>') % _('Start another preview.')
46 46
        r += htmltext('</p></div>')
47 47
        return r.getvalue()
wcs/qommon/admin/emails.py
153 153
            if mail_redirection:
154 154
                r += htmltext('<div class="infonotice">')
155 155
                r += htmltext('<p>')
156
                r += _('Warning: all emails are sent to <%s>') % mail_redirection
156
                r += str(_('Warning: all emails are sent to <%s>') % mail_redirection)
157 157
                r += htmltext(' <a href="../debug_options">%s</a>') % _('Debug Options')
158 158
                r += htmltext('</p>')
159 159
                r += htmltext('</div>')
wcs/qommon/errors.py
91 91
        r = TemplateIO(html=True)
92 92

  
93 93
        r += htmltext('<p>')
94
        r += _('A fatal error happened. It has been recorded and will be available to administrators.')
94
        r += str(_('A fatal error happened. It has been recorded and will be available to administrators.'))
95 95
        if self.logged_error:
96 96
            r += ' (id:%s)' % self.logged_error.id
97 97
        r += htmltext('</p>')
wcs/qommon/form.py
456 456
        r += htmltext('<tr>\n')
457 457
        for widget in self.get_widgets():
458 458
            r += htmltext('<th scope="col">')
459
            r += widget.get_title()
459
            r += str(widget.get_title())
460 460
            r += htmltext('</th>')
461 461
        r += htmltext('</tr>\n')
462 462
        return r.getvalue()
wcs/qommon/ident/franceconnect.py
237 237
        r += htmltext('<h2>%s</h2>') % self.title
238 238
        fc_callback = pub.get_frontoffice_url() + '/ident/fc/callback'
239 239
        r += htmltext('<p>')
240
        r += _('Callback URL is %s.') % fc_callback
240
        r += str(_('Callback URL is %s.') % fc_callback)
241 241
        r += htmltext('</p>')
242 242
        r += htmltext('<p>')
243
        r += _('Logout callback URL is %s.') % get_publisher().get_frontoffice_url()
243
        r += str(_('Logout callback URL is %s.') % get_publisher().get_frontoffice_url())
244 244
        r += htmltext('</p>')
245 245
        r += htmltext('<p>')
246 246
        r += htmltext(
wcs/wf/wscall.py
70 70
        r += htmltext('<div class="ws-error">')
71 71
        r += htmltext('<h4 class="foldable folded">')
72 72
        if self.label:
73
            r += _('Error during webservice call "%s"') % self.label
73
            r += str(_('Error during webservice call "%s"') % self.label)
74 74
        else:
75
            r += _('Error during webservice call')
75
            r += str(_('Error during webservice call'))
76 76
        r += htmltext('</h4>')
77 77
        r += htmltext('<div>')
78 78
        r += htmltext('<p>%s</p>\n') % self.summary
wcs/workflows.py
2371 2371
            return getattr(self, 'get_%s_parameter_view_value' % parameter)()
2372 2372
        value = getattr(self, parameter)
2373 2373
        if isinstance(value, bool):
2374
            return _('Yes') if value else _('No')
2374
            return str(_('Yes') if value else _('No'))
2375 2375
        elif hasattr(widget, 'options') and value:
2376 2376
            for option in widget.options:
2377 2377
                if isinstance(option, tuple):
2378 2378
                    if option[0] == value:
2379
                        return option[1]
2379
                        return str(option[1])
2380 2380
                else:
2381 2381
                    if option == value:
2382 2382
                        return option
2383
-