Projet

Général

Profil

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

Benjamin Dauvergne, 07 janvier 2017 20:59

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()
......
255 255
                    'categories', 'settings', 'management', 'submission'):
256 256
                menu_items[-1]['icon'] = k.strip('/')
257 257
        return menu_items
258

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

  
270
        substvars = get_publisher().substitutions.get_context_variables()
271

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