web/views/owl.py
author Rémi Cardona <remi.cardona@logilab.fr>
Tue, 15 Sep 2015 16:56:57 +0200
changeset 10609 e2d8e81bfe68
parent 8190 2a3c1b787688
child 10666 7f6b5f023884
permissions -rw-r--r--
[py3k] import range using six.moves
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
984
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    18
"""produces some Ontology Web Language schema and views
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    19
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    20
"""
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    21
__docformat__ = "restructuredtext en"
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    22
_ = unicode
984
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    23
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8190
diff changeset
    24
from six.moves import range
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8190
diff changeset
    25
814
c0bee055c594 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 674
diff changeset
    26
from logilab.mtconverter import TransformError, xml_escape
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    27
984
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 939
diff changeset
    28
from cubicweb.view import StartupView, EntityView
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7460
diff changeset
    29
from cubicweb.predicates import none_rset, match_view
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    30
from cubicweb.web.action import Action
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    31
from cubicweb.web.views import schema
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    32
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
    33
OWL_CARD_MAP = {'1': '<rdf:type rdf:resource="&owl;FunctionalProperty"/>',
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    34
                '?': '<owl:maxCardinality rdf:datatype="&xsd;int">1</owl:maxCardinality>',
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    35
                '+': '<owl:minCardinality rdf:datatype="&xsd;int">1</owl:minCardinality>',
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    36
                '*': ''
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    37
                }
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    38
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    39
OWL_TYPE_MAP = {'String': 'xsd:string',
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    40
                'Bytes': 'xsd:byte',
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    41
                'Password': 'xsd:byte',
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    42
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    43
                'Boolean': 'xsd:boolean',
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    44
                'Int': 'xsd:int',
7460
2455cdbeadca [schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
    45
                'BigInt': 'xsd:int',
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    46
                'Float': 'xsd:float',
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    47
                'Decimal' : 'xsd:decimal',
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    48
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    49
                'Date':'xsd:date',
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    50
                'Datetime': 'xsd:dateTime',
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    51
                'TZDatetime': 'xsd:dateTime',
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    52
                'Time': 'xsd:time',
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    53
                'TZTime': 'xsd:time',
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    54
                'Interval': 'xsd:duration'
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    55
                }
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    56
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    57
OWL_OPENING_ROOT = u'''<?xml version="1.0" encoding="UTF-8"?>
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    58
<!DOCTYPE rdf:RDF [
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    59
        <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    60
        <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
    61
]>
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    62
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    63
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    64
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    65
    xmlns:owl="http://www.w3.org/2002/07/owl#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    66
    xmlns="http://logilab.org/owl/ontologies/%(appid)s#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    67
    xmlns:%(appid)s="http://logilab.org/owl/ontologies/%(appid)s#"
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    68
    xmlns:base="http://logilab.org/owl/ontologies/%(appid)s">
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
    69
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    70
  <owl:Ontology rdf:about="">
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    71
    <rdfs:comment>
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
    72
    %(appid)s Cubicweb OWL Ontology
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    73
    </rdfs:comment>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    74
  </owl:Ontology>'''
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    75
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    76
OWL_CLOSING_ROOT = u'</rdf:RDF>'
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    77
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    78
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    79
class OWLView(StartupView):
551
44ec4836cc1a comments fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 550
diff changeset
    80
    """This view export in owl format schema database. It is the TBOX"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2295
diff changeset
    81
    __regid__ = 'owl'
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    82
    title = _('owl')
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
    83
    templatable = False
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    84
    content_type = 'application/xml' # 'text/xml'
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    85
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    86
    def call(self, writeprefix=True):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    87
        skipmeta = int(self._cw.form.get('skipmeta', True))
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    88
        if writeprefix:
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
    89
            self.w(OWL_OPENING_ROOT % {'appid': self._cw.vreg.schema.name})
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    90
        self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ())
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    91
        if writeprefix:
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    92
            self.w(OWL_CLOSING_ROOT)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
    93
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
    94
    def should_display_rschema(self, eschema, rschema, role):
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    95
        return not rschema in self.skiptypes and (
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
    96
            rschema.may_have_permission('read', self._cw, eschema, role))
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    97
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    98
    def visit_schema(self, skiptypes):
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
    99
        """get a layout for a whole schema"""
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   100
        self.skiptypes = skiptypes
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   101
        entities = sorted(eschema for eschema in self._cw.vreg.schema.entities()
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2295
diff changeset
   102
                          if not eschema.final or eschema in skiptypes)
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   103
        self.w(u'<!-- classes definition -->')
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   104
        for eschema in entities:
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   105
            self.visit_entityschema(eschema)
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   106
            self.w(u'<!-- property definition -->')
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   107
            self.visit_property_schema(eschema)
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   108
            self.w(u'<!-- datatype property -->')
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   109
            self.visit_property_object_schema(eschema)
674
8580f1632055 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 585
diff changeset
   110
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   111
    def visit_entityschema(self, eschema):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   112
        """get a layout for an entity OWL schema"""
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   113
        self.w(u'<owl:Class rdf:ID="%s">'% eschema)
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   114
        self.w(u'<!-- relations -->')
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   115
        for rschema, targetschemas, role in eschema.relation_definitions():
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
   116
            if not self.should_display_rschema(eschema, rschema, role):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   117
                continue
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   118
            for oeschema in targetschemas:
4157
f7830377b215 yams api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4093
diff changeset
   119
                card = rschema.role_rdef(eschema, oeschema, role).role_cardinality(role)
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   120
                cardtag = OWL_CARD_MAP[card]
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   121
                if cardtag:
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   122
                    self.w(u'''<rdfs:subClassOf>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   123
 <owl:Restriction>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   124
  <owl:onProperty rdf:resource="#%s"/>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   125
  %s
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   126
 </owl:Restriction>
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   127
</rdfs:subClassOf>''' % (rschema, cardtag))
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   128
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   129
        self.w(u'<!-- attributes -->')
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   130
        for rschema, aschema in eschema.attribute_definitions():
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
   131
            if not self.should_display_rschema(eschema, rschema, 'subject'):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   132
                continue
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   133
            self.w(u'''<rdfs:subClassOf>
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   134
  <owl:Restriction>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   135
   <owl:onProperty rdf:resource="#%s"/>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   136
   <rdf:type rdf:resource="&owl;FunctionalProperty"/>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   137
  </owl:Restriction>
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   138
</rdfs:subClassOf>''' % rschema)
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   139
        self.w(u'</owl:Class>')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   140
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   141
    def visit_property_schema(self, eschema):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   142
        """get a layout for property entity OWL schema"""
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   143
        for rschema, targetschemas, role in eschema.relation_definitions():
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
   144
            if not self.should_display_rschema(eschema, rschema, role):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   145
                continue
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   146
            for oeschema in targetschemas:
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   147
                self.w(u'''<owl:ObjectProperty rdf:ID="%s">
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   148
 <rdfs:domain rdf:resource="#%s"/>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   149
 <rdfs:range rdf:resource="#%s"/>
2295
4bad4fb08f2e fix name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2186
diff changeset
   150
</owl:ObjectProperty>''' % (rschema, eschema, oeschema.type))
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   151
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   152
    def visit_property_object_schema(self, eschema):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   153
        for rschema, aschema in eschema.attribute_definitions():
4093
61b482fe826a nicer fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4091
diff changeset
   154
            if not self.should_display_rschema(eschema, rschema, 'subject'):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   155
                continue
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   156
            self.w(u'''<owl:DatatypeProperty rdf:ID="%s">
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   157
  <rdfs:domain rdf:resource="#%s"/>
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   158
  <rdfs:range rdf:resource="%s"/>
2295
4bad4fb08f2e fix name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2186
diff changeset
   159
</owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type]))
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
   160
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   161
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   162
class OWLABOXView(EntityView):
550
2300370b8edd refactoring OWLView (TBOX+ABOX) and OWLABOXView (pseudo-ABOX for a given entity). By now OWLView is using (for cost advantage) OWLABOXLightView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 537
diff changeset
   163
    '''This view represents a part of the ABOX for a given entity.'''
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2295
diff changeset
   164
    __regid__ = 'owlabox'
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   165
    title = _('owlabox')
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   166
    templatable = False
537
f16da6c874da small corrections
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 517
diff changeset
   167
    content_type = 'application/xml' # 'text/xml'
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   168
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   169
    def call(self):
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   170
        self.w(OWL_OPENING_ROOT % {'appid': self._cw.vreg.schema.name})
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8190
diff changeset
   171
        for i in range(self.cw_rset.rowcount):
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   172
            self.cell_call(i, 0)
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   173
        self.w(OWL_CLOSING_ROOT)
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   174
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   175
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   176
        self.wview('owlaboxitem', self.cw_rset, row=row, col=col)
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   177
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   178
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   179
class OWLABOXItemView(EntityView):
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   180
    '''This view represents a part of the ABOX for a given entity.'''
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2295
diff changeset
   181
    __regid__ = 'owlaboxitem'
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   182
    templatable = False
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   183
    content_type = 'application/xml' # 'text/xml'
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   184
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   185
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   186
        entity = self.cw_rset.complete_entity(row, col)
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   187
        eschema = entity.e_schema
516
56fd73de1f06 owl cleanup
sylvain.thenault@logilab.fr
parents: 512
diff changeset
   188
        self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   189
        self.w(u'<!--attributes-->')
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   190
        for rschema, aschema in eschema.attribute_definitions():
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   191
            if rschema.meta:
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   192
                continue
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   193
            rdef = rschema.rdef(eschema, aschema)
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3733 3877
diff changeset
   194
            if not rdef.may_have_permission('read', self._cw):
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   195
                continue
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   196
            aname = rschema.type
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   197
            if aname == 'eid':
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   198
                continue
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   199
            try:
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   200
                attr = entity.printable_value(aname, format='text/plain')
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   201
                if attr:
814
c0bee055c594 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 674
diff changeset
   202
                    self.w(u'<%s>%s</%s>' % (aname, xml_escape(attr), aname))
585
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   203
            except TransformError:
23c2f934b669 refactoring owl view (now corresponding to tbox) and owlabox view
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 552
diff changeset
   204
                pass
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   205
        self.w(u'<!--relations -->')
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   206
        for rschema, targetschemas, role in eschema.relation_definitions():
2126
a25859917ccc stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   207
            if rschema.meta:
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   208
                continue
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   209
            for tschema in targetschemas:
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   210
                rdef = rschema.role_rdef(eschema, tschema, role)
4073
03681ba6da0b cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4003
diff changeset
   211
                if rdef.may_have_permission('read', self._cw):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3733 3877
diff changeset
   212
                    break
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3733 3877
diff changeset
   213
            else:
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3733 3877
diff changeset
   214
                # no read perms to any relation of this type. Skip.
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   215
                continue
516
56fd73de1f06 owl cleanup
sylvain.thenault@logilab.fr
parents: 512
diff changeset
   216
            if role == 'object':
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   217
                attr = 'reverse_%s' % rschema.type
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   218
            else:
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   219
                attr = rschema.type
517
sylvain.thenault@logilab.fr
parents: 516
diff changeset
   220
            for x in getattr(entity, attr):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   221
                self.w(u'<%s>%s %s</%s>' % (attr, x.__regid__, x.eid, attr))
516
56fd73de1f06 owl cleanup
sylvain.thenault@logilab.fr
parents: 512
diff changeset
   222
        self.w(u'</%s>'% eschema)
502
7882941d3530 owl module has two views : OWLView (TBOX) and OWLABOXView (more or less ABOX. indeed, it layout ABOX information only for an specific entity and not all entities)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff changeset
   223
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   224
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   225
class DownloadOWLSchemaAction(Action):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2295
diff changeset
   226
    __regid__ = 'download_as_owl'
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   227
    __select__ = none_rset() & match_view('schema')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   228
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   229
    category = 'mainactions'
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   230
    title = _('download schema as owl')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1263
diff changeset
   231
1263
01152fffd593 backport default branch
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   232
    def url(self):
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   233
        return self._cw.build_url('view', vid='owl')