Esempio n. 1
0
def show(request, diag):
    tree = diagparser.parse(diagparser.tokenize(bz2.decompress(
                base64.b64decode(diag.replace('-', '/'))).decode('utf-8')))
    diagram = builder.ScreenNodeBuilder.build(tree)
    response = HttpResponse(mimetype='image/png')
    draw = DiagramDraw.DiagramDraw('PNG', diagram, response, antialias=False, font=settings.FONT)
    draw.draw()
    draw.save()
    return response
def nwdiag_generate_image(source):
    import nwdiag
    from nwdiag import diagparser, builder, DiagramDraw

    try:
        tree = diagparser.parse(source)
        diagram = builder.ScreenNodeBuilder.build(tree)
        draw = DiagramDraw.DiagramDraw('SVG', diagram)
        draw.draw()

        svg = draw.save('').decode('utf-8')
        etype = None
        error = None
    except Exception, e:
        svg = ''
        etype = e.__class__.__name__
        error = str(e)