Use graphviz to display the workflows admin pages header
This commit is contained in:
parent
9b12cef712
commit
2e91965bfa
|
@ -15,6 +15,9 @@
|
|||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
from StringIO import StringIO
|
||||
from subprocess import Popen, PIPE
|
||||
import textwrap
|
||||
|
||||
from quixote import redirect, get_publisher
|
||||
from quixote.directory import Directory
|
||||
|
@ -30,6 +33,47 @@ from wcs.formdata import Evolution
|
|||
from wcs.admin.forms import ET, indent
|
||||
|
||||
|
||||
def graphviz(workflow, url_prefix='', select=None, svg=True,
|
||||
include=False):
|
||||
out = StringIO()
|
||||
print >>out, 'digraph main {'
|
||||
# print >>out, 'graph [ rankdir=LR ];'
|
||||
print >>out, 'node [shape=box,style=filled];'
|
||||
print >>out, 'edge [];'
|
||||
for status in workflow.possible_status:
|
||||
i = status.id
|
||||
print >>out, 'status%s' % i,
|
||||
print >>out, '[label="%s"' % status.name,
|
||||
if select == str(i):
|
||||
print >>out, ',color=salmon'
|
||||
print >>out, ' URL="%sstatus/%s"];' % (url_prefix, i)
|
||||
|
||||
for status in workflow.possible_status:
|
||||
i = status.id
|
||||
for item in status.items:
|
||||
if getattr(item, 'status', None):
|
||||
next_id = item.status
|
||||
else:
|
||||
next_id = status.id
|
||||
print >>out, 'status%s -> status%s' % (i, next_id)
|
||||
url = 'status/%s/items/%s/' % (i, item.id)
|
||||
label = textwrap.fill(item.render_as_line().replace('"', '\\"'), 20)
|
||||
label = label.replace('\n', '\\n')
|
||||
print >>out, '[label="%s"' % label,
|
||||
if select == '%s-%s' % (i, item.id):
|
||||
print >>out, ',color=salmon,fontcolor=salmon'
|
||||
print >>out, ',URL="%s%s"]' % (url_prefix, url)
|
||||
print >>out, '}'
|
||||
out = out.getvalue()
|
||||
if svg:
|
||||
process = Popen(['dot', '-Tsvg', '/dev/stdin'], stdin=PIPE, stdout=PIPE)
|
||||
out, err = process.communicate(out)
|
||||
if include:
|
||||
i = out.index('<svg')
|
||||
out = out[i:]
|
||||
return out
|
||||
|
||||
|
||||
class WorkflowUI:
|
||||
def __init__(self, workflow):
|
||||
self.workflow = workflow
|
||||
|
@ -162,6 +206,9 @@ class WorkflowStatusPage(Directory):
|
|||
'%s - %s</h2>' % (self.workflow.name, self.status.name)
|
||||
get_session().display_message()
|
||||
|
||||
htmltext(graphviz(self.workflow, url_prefix='../../', include=True,
|
||||
select='%s' % self.status.id))
|
||||
|
||||
'<div class="bo-block">'
|
||||
if not self.status.items:
|
||||
'<p>%s</p>' % _('There are not yet any items in this status.')
|
||||
|
@ -400,6 +447,8 @@ class WorkflowPage(Directory):
|
|||
'<div class="bo-block">'
|
||||
'<h3>%s</h3>' % _('Possible Status')
|
||||
|
||||
htmltext(graphviz(self.workflow, include=True))
|
||||
|
||||
if not self.workflow.possible_status:
|
||||
'<p>%s</p>' % _('There are not yet any status defined in this workflow.')
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue