diff -r 3e1d2ab5f8c0 -r a25859917ccc web/views/owl.py --- a/web/views/owl.py Thu Jun 18 21:01:55 2009 +0200 +++ b/web/views/owl.py Fri Jun 19 14:42:04 2009 +0200 @@ -6,14 +6,14 @@ :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses """ __docformat__ = "restructuredtext en" +_ = unicode from logilab.mtconverter import TransformError, xml_escape from cubicweb.view import StartupView, EntityView +from cubicweb.selectors import none_rset, match_view from cubicweb.web.action import Action -from cubicweb.selectors import none_rset, match_view - -_ = unicode +from cubicweb.web.views import schema OWL_CARD_MAP = {'1': '', '?': '1', @@ -55,8 +55,6 @@ OWL_CLOSING_ROOT = u'' -DEFAULT_SKIP_RELS = frozenset(('is', 'is_instance_of', 'identity', - 'owned_by', 'created_by')) class OWLView(StartupView): """This view export in owl format schema database. It is the TBOX""" @@ -69,36 +67,36 @@ skipmeta = int(self.req.form.get('skipmeta', True)) if writeprefix: self.w(OWL_OPENING_ROOT % {'appid': self.schema.name}) - self.visit_schema(skipmeta=skipmeta) + self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ()) if writeprefix: self.w(OWL_CLOSING_ROOT) - def visit_schema(self, skiprels=DEFAULT_SKIP_RELS, skipmeta=True): + def should_display_rschema(self, rschema): + return not rschema in self.skiptypes and ( + rschema.has_local_role('read') or + rschema.has_perm(self.req, 'read')): + + def visit_schema(self, skiptypes): """get a layout for a whole schema""" - entities = sorted([eschema for eschema in self.schema.entities() - if not eschema.is_final()]) - if skipmeta: - entities = [eschema for eschema in entities - if not eschema.meta] + self.skiptypes = skiptypes + entities = sorted(eschema for eschema in self.schema.entities() + if not eschema.is_final() or eschema in skiptypes) self.w(u'') for eschema in entities: - self.visit_entityschema(eschema, skiprels) + self.visit_entityschema(eschema) self.w(u'') - self.visit_property_schema(eschema, skiprels) + self.visit_property_schema(eschema) self.w(u'') self.visit_property_object_schema(eschema) - def visit_entityschema(self, eschema, skiprels=()): + def visit_entityschema(self, eschema): """get a layout for an entity OWL schema""" self.w(u''% eschema) self.w(u'') for rschema, targetschemas, role in eschema.relation_definitions(): - if rschema.type in skiprels: - continue - if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): + if not self.should_display_rschema(rschema): continue for oeschema in targetschemas: - label = rschema.type if role == 'subject': card = rschema.rproperty(eschema, oeschema, 'cardinality')[0] else: @@ -110,58 +108,44 @@ %s - -''' % (label, cardtag)) +''' % (rschema, cardtag)) self.w(u'') - for rschema, aschema in eschema.attribute_definitions(): - if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): - continue - aname = rschema.type - if aname == 'eid': + if not self.should_display_rschema(rschema): continue self.w(u''' -''' - % aname) +''' % rschema) self.w(u'') - def visit_property_schema(self, eschema, skiprels=()): + def visit_property_schema(self, eschema): """get a layout for property entity OWL schema""" for rschema, targetschemas, role in eschema.relation_definitions(): - if rschema.type in skiprels: - continue - if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): + if not self.should_display_rschema(rschema): continue for oeschema in targetschemas: label = rschema.type self.w(u''' - -''' % (label, eschema, oeschema.type)) +''' % (label, eschema, oeschema.type)) def visit_property_object_schema(self, eschema): for rschema, aschema in eschema.attribute_definitions(): - if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): - continue - aname = rschema.type - if aname == 'eid': + if not self.should_display_rschema(rschema): continue self.w(u''' -''' - % (aname, eschema, OWL_TYPE_MAP[aschema.type])) +''' % (aname, eschema, OWL_TYPE_MAP[aschema.type])) class OWLABOXView(EntityView): '''This view represents a part of the ABOX for a given entity.''' - id = 'owlabox' title = _('owlabox') templatable = False @@ -173,8 +157,8 @@ self.cell_call(i, 0) self.w(OWL_CLOSING_ROOT) - def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS): - self.wview('owlaboxitem', self.rset, row=row, col=col, skiprels=skiprels) + def cell_call(self, row, col): + self.wview('owlaboxitem', self.rset, row=row, col=col) class OWLABOXItemView(EntityView): @@ -183,13 +167,13 @@ templatable = False content_type = 'application/xml' # 'text/xml' - def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS): + def cell_call(self, row, col): entity = self.complete_entity(row, col) eschema = entity.e_schema self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid)) self.w(u'') for rschema, aschema in eschema.attribute_definitions(): - if rschema.type in skiprels: + if rschema.meta: continue if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): continue @@ -204,7 +188,7 @@ pass self.w(u'') for rschema, targetschemas, role in eschema.relation_definitions(): - if rschema.type in skiprels: + if rschema.meta: continue if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): continue