Commit 4ece4664 authored by Dylann Cordel's avatar Dylann Cordel

mobile version

parent 40a27b57
......@@ -2,6 +2,8 @@
from __future__ import unicode_literals
import os
import re
from copy import deepcopy
from shutil import copyfile
from tempfile import mkstemp
......@@ -82,8 +84,31 @@ class GraphvizPlugin(CMSPlugin):
via_files = []
stylesheet = None
if style:
style = getattr(settings, 'CMS_GRAPHVIZ_STYLES', {}).get(style, None)
if style and style in getattr(settings, 'CMS_GRAPHVIZ_STYLES', {}):
styles = deepcopy(settings.CMS_GRAPHVIZ_STYLES[style])
if version == cls.VERSION_DESKTOP and 'desktop' in styles:
style = styles['desktop']
if '_inherit' in styles['desktop']:
if 'mobile' in styles:
style = styles['mobile']
for k, v in styles['desktop'].items():
if k not in style or type(v) is not dict:
style[k] = v
else:
style[k].update(v)
elif version == cls.VERSION_MOBILE and 'mobile' in styles:
style = styles['mobile']
if '_inherit' in styles['mobile']:
if 'desktop' in styles:
style = styles['desktop']
for k, v in styles['mobile'].items():
if k not in style or type(v) is not dict:
style[k] = v
else:
style[k].update(v)
else:
style = {}
if 'graph_attr' in style:
for attr, value in style['graph_attr'].items():
if attr == 'stylesheet':
......@@ -100,7 +125,11 @@ class GraphvizPlugin(CMSPlugin):
g.node_attr[attr] = value
if attr == 'shape' and value and value != 'ellipse':
# fix bug : it adds shape="" which means ellipse...
g = AGraph(g.string().replace('shape=""', 'shape="'+ value +'"'))
g = AGraph(g.string().replace('shape=""', 'shape="%s"' % value))
if 'edge_attr' in style:
for attr, value in style['edge_attr'].items():
g.edge_attr[attr] = value
if 'nodes' in style:
for node_id, attrs in style['nodes'].items():
......@@ -116,18 +145,24 @@ class GraphvizPlugin(CMSPlugin):
# value = os.path.basename(new_value[1])
value = new_value[1]
node.attr[attr] = value
# fix bug : it adds attribute="" some times...
g_string = re.sub(r'[a-z]*="",?', '', g.string()).replace('[]', '')
if via_files:
dot_file = list(mkstemp('.dot'))
dot_file.append(None)
via_files.append(dot_file)
with open(dot_file[1], 'w') as f:
f.write(g.string())
f.write(g_string)
g = AGraph(dot_file[1])
else:
g = AGraph(g_string)
if display_type in (cls.DISPLAY_TYPE_PNG, cls.DISPLAY_TYPE_SVG):
output = g.draw(prog='dot', format=display_type)
else:
output = graph
if via_files:
if display_type == cls.DISPLAY_TYPE_SVG and stylesheet:
from lxml import etree
......@@ -151,7 +186,7 @@ class GraphvizPlugin(CMSPlugin):
return self.graph_image
@property
def graph_mobile(self):
def mobile_graph(self):
if self.display_type == self.DISPLAY_TYPE_DOT:
return self.mobile_graph_dot
return self.mobile_graph_image
......@@ -3,12 +3,12 @@
{% endif %}
<div class="graphviz">
{% if instance.display_type == instance.DISPLAY_TYPE_SVG %}
{% if instance.graph %}
<div class="large">{{ instance.graph.read|safe }}</div>
{% endif %}
{% if instance.mobile_graph %}
<div class="mobile">{{ instance.mobile_graph.read|safe }}</div>
{% endif %}
{% if instance.graph %}
<div class="large">{{ instance.graph.read|safe }}</div>
{% endif %}
{% elif instance.display_type == instance.DISPLAY_TYPE_PNG %}
<img class="large" src="{{ instance.graph.url }}" alt="{{ instance.name }}" />
{% if instance.mobile_graph %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment