69 self.w(OWL_OPENING_ROOT % {'appid': self._cw.vreg.schema.name}) |
69 self.w(OWL_OPENING_ROOT % {'appid': self._cw.vreg.schema.name}) |
70 self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ()) |
70 self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ()) |
71 if writeprefix: |
71 if writeprefix: |
72 self.w(OWL_CLOSING_ROOT) |
72 self.w(OWL_CLOSING_ROOT) |
73 |
73 |
|
74 <<<<<<< /home/syt/src/fcubicweb/cubicweb/web/views/owl.py |
74 def should_display_rschema(self, rschema): |
75 def should_display_rschema(self, rschema): |
75 return not rschema in self.skiptypes and ( |
76 return not rschema in self.skiptypes and ( |
76 rschema.has_local_role('read') or |
77 rschema.has_local_role('read') or |
77 rschema.has_perm(self._cw, 'read')) |
78 rschema.has_perm(self._cw, 'read')) |
|
79 ======= |
|
80 def should_display_rschema(self, eschema, rschema, tschemas, role): |
|
81 return rschema.may_have_permissions('read', self.req, eschema, role) |
|
82 >>>>>>> /tmp/owl.py~other.-maWGS |
78 |
83 |
79 def visit_schema(self, skiptypes): |
84 def visit_schema(self, skiptypes): |
80 """get a layout for a whole schema""" |
85 """get a layout for a whole schema""" |
81 self.skiptypes = skiptypes |
86 self.skiptypes = skiptypes |
82 entities = sorted(eschema for eschema in self._cw.vreg.schema.entities() |
87 entities = sorted(eschema for eschema in self._cw.vreg.schema.entities() |
92 def visit_entityschema(self, eschema): |
97 def visit_entityschema(self, eschema): |
93 """get a layout for an entity OWL schema""" |
98 """get a layout for an entity OWL schema""" |
94 self.w(u'<owl:Class rdf:ID="%s">'% eschema) |
99 self.w(u'<owl:Class rdf:ID="%s">'% eschema) |
95 self.w(u'<!-- relations -->') |
100 self.w(u'<!-- relations -->') |
96 for rschema, targetschemas, role in eschema.relation_definitions(): |
101 for rschema, targetschemas, role in eschema.relation_definitions(): |
97 if not self.should_display_rschema(rschema): |
102 if not self.should_display_rschema(eschema, rschema, targetschemas, role): |
98 continue |
103 continue |
99 for oeschema in targetschemas: |
104 for oeschema in targetschemas: |
100 if role == 'subject': |
105 if role == 'subject': |
101 card = rschema.rproperty(eschema, oeschema, 'cardinality')[0] |
106 card = rschema.rproperty(eschema, oeschema, 'cardinality')[0] |
102 else: |
107 else: |
110 </owl:Restriction> |
115 </owl:Restriction> |
111 </rdfs:subClassOf>''' % (rschema, cardtag)) |
116 </rdfs:subClassOf>''' % (rschema, cardtag)) |
112 |
117 |
113 self.w(u'<!-- attributes -->') |
118 self.w(u'<!-- attributes -->') |
114 for rschema, aschema in eschema.attribute_definitions(): |
119 for rschema, aschema in eschema.attribute_definitions(): |
115 if not self.should_display_rschema(rschema): |
120 if not self.should_display_rschema(eschema, rschema, (aschema,), 'subject'): |
116 continue |
121 continue |
117 self.w(u'''<rdfs:subClassOf> |
122 self.w(u'''<rdfs:subClassOf> |
118 <owl:Restriction> |
123 <owl:Restriction> |
119 <owl:onProperty rdf:resource="#%s"/> |
124 <owl:onProperty rdf:resource="#%s"/> |
120 <rdf:type rdf:resource="&owl;FunctionalProperty"/> |
125 <rdf:type rdf:resource="&owl;FunctionalProperty"/> |
123 self.w(u'</owl:Class>') |
128 self.w(u'</owl:Class>') |
124 |
129 |
125 def visit_property_schema(self, eschema): |
130 def visit_property_schema(self, eschema): |
126 """get a layout for property entity OWL schema""" |
131 """get a layout for property entity OWL schema""" |
127 for rschema, targetschemas, role in eschema.relation_definitions(): |
132 for rschema, targetschemas, role in eschema.relation_definitions(): |
128 if not self.should_display_rschema(rschema): |
133 if not self.should_display_rschema(eschema, rschema, targetschemas, role): |
129 continue |
134 continue |
130 for oeschema in targetschemas: |
135 for oeschema in targetschemas: |
131 self.w(u'''<owl:ObjectProperty rdf:ID="%s"> |
136 self.w(u'''<owl:ObjectProperty rdf:ID="%s"> |
132 <rdfs:domain rdf:resource="#%s"/> |
137 <rdfs:domain rdf:resource="#%s"/> |
133 <rdfs:range rdf:resource="#%s"/> |
138 <rdfs:range rdf:resource="#%s"/> |
134 </owl:ObjectProperty>''' % (rschema, eschema, oeschema.type)) |
139 </owl:ObjectProperty>''' % (rschema, eschema, oeschema.type)) |
135 |
140 |
136 def visit_property_object_schema(self, eschema): |
141 def visit_property_object_schema(self, eschema): |
137 for rschema, aschema in eschema.attribute_definitions(): |
142 for rschema, aschema in eschema.attribute_definitions(): |
138 if not self.should_display_rschema(rschema): |
143 if not self.should_display_rschema(eschema, rschema, (aschema,), 'subject'): |
139 continue |
144 continue |
140 self.w(u'''<owl:DatatypeProperty rdf:ID="%s"> |
145 self.w(u'''<owl:DatatypeProperty rdf:ID="%s"> |
141 <rdfs:domain rdf:resource="#%s"/> |
146 <rdfs:domain rdf:resource="#%s"/> |
142 <rdfs:range rdf:resource="%s"/> |
147 <rdfs:range rdf:resource="%s"/> |
143 </owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type])) |
148 </owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type])) |
172 self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid)) |
177 self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid)) |
173 self.w(u'<!--attributes-->') |
178 self.w(u'<!--attributes-->') |
174 for rschema, aschema in eschema.attribute_definitions(): |
179 for rschema, aschema in eschema.attribute_definitions(): |
175 if rschema.meta: |
180 if rschema.meta: |
176 continue |
181 continue |
177 if not (rschema.has_local_role('read') or rschema.has_perm(self._cw, 'read')): |
182 rdef = rschema.rdef(eschema, aschema) |
|
183 if not rdef.may_have_permission('read', self._cw): |
178 continue |
184 continue |
179 aname = rschema.type |
185 aname = rschema.type |
180 if aname == 'eid': |
186 if aname == 'eid': |
181 continue |
187 continue |
182 try: |
188 try: |
187 pass |
193 pass |
188 self.w(u'<!--relations -->') |
194 self.w(u'<!--relations -->') |
189 for rschema, targetschemas, role in eschema.relation_definitions(): |
195 for rschema, targetschemas, role in eschema.relation_definitions(): |
190 if rschema.meta: |
196 if rschema.meta: |
191 continue |
197 continue |
192 if not (rschema.has_local_role('read') or rschema.has_perm(self._cw, 'read')): |
198 for tschema in targetschemas: |
|
199 rdef = rschema.role_rdef(eschema, tschema, role) |
|
200 if rdef.may_have_permission('read', self.req): |
|
201 break |
|
202 else: |
|
203 # no read perms to any relation of this type. Skip. |
193 continue |
204 continue |
194 if role == 'object': |
205 if role == 'object': |
195 attr = 'reverse_%s' % rschema.type |
206 attr = 'reverse_%s' % rschema.type |
196 else: |
207 else: |
197 attr = rschema.type |
208 attr = rschema.type |