22 |
22 |
23 from itertools import cycle |
23 from itertools import cycle |
24 |
24 |
25 import tempfile |
25 import tempfile |
26 import os, os.path as osp |
26 import os, os.path as osp |
|
27 import codecs |
27 |
28 |
28 from logilab.common.graph import GraphGenerator, DotBackend |
29 from logilab.common.graph import GraphGenerator, DotBackend |
29 from logilab.common.ureports import Section, Table |
30 from logilab.common.ureports import Section, Table |
30 from logilab.common.registry import yes |
31 from logilab.common.registry import yes |
31 from logilab.mtconverter import xml_escape |
32 from logilab.mtconverter import xml_escape |
38 WORKFLOW_TYPES, INTERNAL_TYPES) |
39 WORKFLOW_TYPES, INTERNAL_TYPES) |
39 from cubicweb.utils import make_uid |
40 from cubicweb.utils import make_uid |
40 from cubicweb.view import EntityView, StartupView |
41 from cubicweb.view import EntityView, StartupView |
41 from cubicweb import tags, uilib |
42 from cubicweb import tags, uilib |
42 from cubicweb.web import action, facet, schemaviewer |
43 from cubicweb.web import action, facet, schemaviewer |
43 from cubicweb.web.views import TmpFileViewMixin |
|
44 from cubicweb.web.views import uicfg, primary, baseviews, tabs, tableview, ibreadcrumbs |
44 from cubicweb.web.views import uicfg, primary, baseviews, tabs, tableview, ibreadcrumbs |
45 |
45 |
46 ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES |
46 ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES |
47 SKIP_TYPES = (ALWAYS_SKIP_TYPES | META_RTYPES | SYSTEM_RTYPES | WORKFLOW_TYPES |
47 SKIP_TYPES = (ALWAYS_SKIP_TYPES | META_RTYPES | SYSTEM_RTYPES | WORKFLOW_TYPES |
48 | INTERNAL_TYPES) |
48 | INTERNAL_TYPES) |
623 |
623 |
624 class SchemaGraphView(StartupView): |
624 class SchemaGraphView(StartupView): |
625 __regid__ = 'schemagraph' |
625 __regid__ = 'schemagraph' |
626 |
626 |
627 def call(self, etype=None, rtype=None, alt=''): |
627 def call(self, etype=None, rtype=None, alt=''): |
|
628 if 'MSIE 8' in self._cw.useragent(): |
|
629 return |
628 schema = self._cw.vreg.schema |
630 schema = self._cw.vreg.schema |
629 if etype: |
631 if etype: |
630 assert rtype is None |
632 assert rtype is None |
631 visitor = OneHopESchemaVisitor(self._cw, schema.eschema(etype), |
633 visitor = OneHopESchemaVisitor(self._cw, schema.eschema(etype), |
632 skiptypes=skip_types(self._cw)) |
634 skiptypes=skip_types(self._cw)) |
650 additionnal_param={ |
652 additionnal_param={ |
651 'overlap':'false', |
653 'overlap':'false', |
652 'splines':'true', |
654 'splines':'true', |
653 'sep':'0.2', |
655 'sep':'0.2', |
654 })) |
656 })) |
655 # map file |
657 # svg image file |
656 pmap, mapfile = tempfile.mkstemp(".map") |
658 fd, tmpfile = tempfile.mkstemp('.svg') |
657 os.close(pmap) |
|
658 # image file |
|
659 fd, tmpfile = tempfile.mkstemp('.png') |
|
660 os.close(fd) |
659 os.close(fd) |
661 generator.generate(visitor, prophdlr, tmpfile, mapfile) |
660 generator.generate(visitor, prophdlr, tmpfile) |
662 filekeyid = make_uid() |
661 with codecs.open(tmpfile, 'rb', encoding='utf-8') as svgfile: |
663 self._cw.session.data[filekeyid] = tmpfile |
662 self.w(svgfile.read()) |
664 self.w(u'<img src="%s" alt="%s" usemap="#schema" />' % ( |
|
665 xml_escape(self._cw.build_url(vid='tmppng', tmpfile=filekeyid)), |
|
666 xml_escape(self._cw._(alt)))) |
|
667 stream = open(mapfile, 'r').read() |
|
668 stream = stream.decode(self._cw.encoding) |
|
669 self.w(stream) |
|
670 os.unlink(mapfile) |
|
671 |
663 |
672 # breadcrumbs ################################################################## |
664 # breadcrumbs ################################################################## |
673 |
665 |
674 class CWRelationIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
666 class CWRelationIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
675 __select__ = is_instance('CWRelation') |
667 __select__ = is_instance('CWRelation') |