Projet

Général

Profil

0004-add-an-inspect-view-for-global-substitution-variable.patch

Benjamin Dauvergne, 05 janvier 2017 22:19

Télécharger (2,45 ko)

Voir les différences:

Subject: [PATCH 4/4] add an inspect view for global substitution variables

 wcs/backoffice/root.py | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
wcs/backoffice/root.py
39 39

  
40 40

  
41 41
class RootDirectory(BackofficeRootDirectory):
42
    _q_exports = ['', 'pending', 'statistics', ('menu.json', 'menu_json')]
42
    _q_exports = ['', 'pending', 'inspect', 'statistics', ('menu.json', 'menu_json')]
43 43

  
44 44
    bounces = wcs.admin.bounces.BouncesDirectory()
45 45
    categories = wcs.admin.categories.CategoriesDirectory()
......
257 257
                    'categories', 'settings', 'management', 'submission'):
258 258
                menu_items[-1]['icon'] = k.strip('/')
259 259
        return menu_items
260

  
261
    def inspect(self):
262
        charset = get_publisher().site_charset
263
        title = _('Global dict inspector')
264
        get_response().breadcrumb.append(('inspect', title))
265
        html_top('/inspect')
266
        r = TemplateIO(html=True)
267
        r += htmltext('<div class="bo-block">')
268
        r += htmltext('<h2>%s</h2>') % title
269
        r += htmltext('<ul class="biglist form-inspector">')
270
        r += htmltext(' <li><h3>%s</h3></li>') % _('Substitution variables')
271

  
272
        substvars = get_publisher().substitutions.get_context_variables()
273

  
274
        def safe(v):
275
            if isinstance(v, str):
276
                try:
277
                    unicode(v, charset)
278
                except UnicodeDecodeError:
279
                    v = repr(v)
280
            else:
281
                try:
282
                    v = unicode(v).encode(charset)
283
                except:
284
                    v = repr(v)
285
            return v
286
        for k, v in sorted(substvars.items()):
287
            k = safe(k)
288
            r += htmltext('<li><code title="%s">%s</code>') % (k, k)
289
            r += htmltext('  <div class="value"><span>%s</span>') % misc.ellipsize(safe(v), 10000)
290
            if not isinstance(v, basestring):
291
                r += htmltext(' <span class="type">(%r)</span>') % type(v)
292
            r += htmltext('</div>')
293
        r += htmltext('</ul>')
294
        return r.getvalue()
260
-