web/views/owl.py
changeset 3451 6b46d73823f5
parent 3377 dd9d292b6a6d
child 3460 e4843535db25
equal deleted inserted replaced
3448:495862266785 3451:6b46d73823f5
    62     title = _('owl')
    62     title = _('owl')
    63     templatable = False
    63     templatable = False
    64     content_type = 'application/xml' # 'text/xml'
    64     content_type = 'application/xml' # 'text/xml'
    65 
    65 
    66     def call(self, writeprefix=True):
    66     def call(self, writeprefix=True):
    67         skipmeta = int(self.req.form.get('skipmeta', True))
    67         skipmeta = int(self._cw.form.get('skipmeta', True))
    68         if writeprefix:
    68         if writeprefix:
    69             self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
    69             self.w(OWL_OPENING_ROOT % {'appid': self._cw.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     def should_display_rschema(self, rschema):
    74     def should_display_rschema(self, rschema):
    75         return not rschema in self.skiptypes and (
    75         return not rschema in self.skiptypes and (
    76             rschema.has_local_role('read') or
    76             rschema.has_local_role('read') or
    77             rschema.has_perm(self.req, 'read'))
    77             rschema.has_perm(self._cw, 'read'))
    78 
    78 
    79     def visit_schema(self, skiptypes):
    79     def visit_schema(self, skiptypes):
    80         """get a layout for a whole schema"""
    80         """get a layout for a whole schema"""
    81         self.skiptypes = skiptypes
    81         self.skiptypes = skiptypes
    82         entities = sorted(eschema for eschema in self.schema.entities()
    82         entities = sorted(eschema for eschema in self._cw.schema.entities()
    83                           if not eschema.is_final() or eschema in skiptypes)
    83                           if not eschema.is_final() or eschema in skiptypes)
    84         self.w(u'<!-- classes definition -->')
    84         self.w(u'<!-- classes definition -->')
    85         for eschema in entities:
    85         for eschema in entities:
    86             self.visit_entityschema(eschema)
    86             self.visit_entityschema(eschema)
    87             self.w(u'<!-- property definition -->')
    87             self.w(u'<!-- property definition -->')
   149     title = _('owlabox')
   149     title = _('owlabox')
   150     templatable = False
   150     templatable = False
   151     content_type = 'application/xml' # 'text/xml'
   151     content_type = 'application/xml' # 'text/xml'
   152 
   152 
   153     def call(self):
   153     def call(self):
   154         self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
   154         self.w(OWL_OPENING_ROOT % {'appid': self._cw.schema.name})
   155         for i in xrange(self.rset.rowcount):
   155         for i in xrange(self.cw_rset.rowcount):
   156             self.cell_call(i, 0)
   156             self.cell_call(i, 0)
   157         self.w(OWL_CLOSING_ROOT)
   157         self.w(OWL_CLOSING_ROOT)
   158 
   158 
   159     def cell_call(self, row, col):
   159     def cell_call(self, row, col):
   160         self.wview('owlaboxitem', self.rset, row=row, col=col)
   160         self.wview('owlaboxitem', self.cw_rset, row=row, col=col)
   161 
   161 
   162 
   162 
   163 class OWLABOXItemView(EntityView):
   163 class OWLABOXItemView(EntityView):
   164     '''This view represents a part of the ABOX for a given entity.'''
   164     '''This view represents a part of the ABOX for a given entity.'''
   165     __regid__ = 'owlaboxitem'
   165     __regid__ = 'owlaboxitem'
   166     templatable = False
   166     templatable = False
   167     content_type = 'application/xml' # 'text/xml'
   167     content_type = 'application/xml' # 'text/xml'
   168 
   168 
   169     def cell_call(self, row, col):
   169     def cell_call(self, row, col):
   170         entity = self.complete_entity(row, col)
   170         entity = self.cw_rset.complete_entity(row, col)
   171         eschema = entity.e_schema
   171         eschema = entity.e_schema
   172         self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
   172         self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
   173         self.w(u'<!--attributes-->')
   173         self.w(u'<!--attributes-->')
   174         for rschema, aschema in eschema.attribute_definitions():
   174         for rschema, aschema in eschema.attribute_definitions():
   175             if rschema.meta:
   175             if rschema.meta:
   176                 continue
   176                 continue
   177             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
   177             if not (rschema.has_local_role('read') or rschema.has_perm(self._cw, 'read')):
   178                 continue
   178                 continue
   179             aname = rschema.type
   179             aname = rschema.type
   180             if aname == 'eid':
   180             if aname == 'eid':
   181                 continue
   181                 continue
   182             try:
   182             try:
   187                 pass
   187                 pass
   188         self.w(u'<!--relations -->')
   188         self.w(u'<!--relations -->')
   189         for rschema, targetschemas, role in eschema.relation_definitions():
   189         for rschema, targetschemas, role in eschema.relation_definitions():
   190             if rschema.meta:
   190             if rschema.meta:
   191                 continue
   191                 continue
   192             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
   192             if not (rschema.has_local_role('read') or rschema.has_perm(self._cw, 'read')):
   193                 continue
   193                 continue
   194             if role == 'object':
   194             if role == 'object':
   195                 attr = 'reverse_%s' % rschema.type
   195                 attr = 'reverse_%s' % rschema.type
   196             else:
   196             else:
   197                 attr = rschema.type
   197                 attr = rschema.type
   198             for x in getattr(entity, attr):
   198             for x in getattr(entity, attr):
   199                 self.w(u'<%s>%s %s</%s>' % (attr, x.id, x.eid, attr))
   199                 self.w(u'<%s>%s %s</%s>' % (attr, x.__regid__, x.eid, attr))
   200         self.w(u'</%s>'% eschema)
   200         self.w(u'</%s>'% eschema)
   201 
   201 
   202 
   202 
   203 class DownloadOWLSchemaAction(Action):
   203 class DownloadOWLSchemaAction(Action):
   204     __regid__ = 'download_as_owl'
   204     __regid__ = 'download_as_owl'