Updated SVG image renderer
authorThierry Florac <tflorac@ulthar.net>
Wed, 23 Sep 2020 16:44:12 +0200
changeset 212 9d0a2eaf976c
parent 211 aca9fe23b773
child 213 bf210dd1df2f
Updated SVG image renderer
src/pyams_file/image.py
--- a/src/pyams_file/image.py	Tue Sep 08 12:22:26 2020 +0200
+++ b/src/pyams_file/image.py	Wed Sep 23 16:44:12 2020 +0200
@@ -293,18 +293,19 @@
     else:
         options['style'] = ''
     options['css_class'] = css_class
-    svg = image.data
-    if alt:
-        svg = PyQuery(svg)
-        g = PyQuery('<g></g>')
-        g.append(PyQuery('<title />').text(alt))
-        for child in svg.children():
-            g.append(child)
-        svg.empty().append(g)
-        svg = svg.outer_html()
-    if img_class:
-        svg.attr('class', img_class)
-    options['svg'] = svg
+    if alt or img_class:
+        svg = PyQuery(image.data)
+        if alt:
+            g = PyQuery('<g></g>')
+            g.append(PyQuery('<title />').text(alt))
+            for child in svg.children():
+                g.append(child)
+            svg.empty().append(g)
+        if img_class:
+            svg.attr('class', img_class)
+        options['svg'] = svg.outer_html()
+    else:
+        options['svg'] = image.data
     return render('templates/svg-render.pt', options, request)