# HG changeset patch # User Sylvain Thénault # Date 1248354428 -7200 # Node ID 44b2eea35efabc194615025c7bb16fcd89115609 # Parent 85be7a811afe0bb3df3b3d4e761677f2bfe9388c move all schema related views where they belong (eg not startup), fix schema graph views diff -r 85be7a811afe -r 44b2eea35efa web/views/schema.py --- a/web/views/schema.py Thu Jul 23 13:35:06 2009 +0200 +++ b/web/views/schema.py Thu Jul 23 15:07:08 2009 +0200 @@ -10,37 +10,178 @@ from itertools import cycle from logilab.mtconverter import xml_escape -from yams import schema2dot as s2d +from yams import BASE_TYPES, schema2dot as s2d -from cubicweb.selectors import implements, yes +from cubicweb.selectors import implements, yes, match_user_groups from cubicweb.schema import META_RELATIONS_TYPES, SCHEMA_TYPES from cubicweb.schemaviewer import SchemaViewer from cubicweb.view import EntityView, StartupView from cubicweb.common import tags, uilib -from cubicweb.web import action -from cubicweb.web.views import TmpFileViewMixin, primary, baseviews, tabs -from cubicweb.web.facet import AttributeFacet +from cubicweb.web import action, facet +from cubicweb.web.views import TmpFileViewMixin +from cubicweb.web.views import primary, baseviews, tabs, management -SKIP_TYPES = set() -SKIP_TYPES.update(META_RELATIONS_TYPES) -SKIP_TYPES.update(SCHEMA_TYPES) +ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES +SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RELATIONS_TYPES +SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo', + 'CWUser', 'CWGroup', + 'CWCache', 'CWProperty', 'CWPermission', + 'ExternalUri'))) def skip_types(req): if int(req.form.get('skipmeta', True)): return SKIP_TYPES - return () + return ALWAYS_SKIP_TYPES + +# global schema view ########################################################### + +class SchemaView(tabs.TabsMixin, StartupView): + id = 'schema' + title = _('application schema') + tabs = [_('schema-text'), _('schema-image')] + default_tab = 'schema-text' + + def call(self): + """display schema information""" + self.req.add_js('cubicweb.ajax.js') + self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css')) + self.w(u'

%s

' % _('Schema of the data model')) + self.render_tabs(self.tabs, self.default_tab) + + +class SchemaTabImageView(StartupView): + id = 'schema-image' -class ViewSchemaAction(action.Action): - id = 'schema' - __select__ = yes() + def call(self): + self.w(_(u'
This schema of the data model excludes the ' + u'meta-data, but you can also display a complete ' + u'schema with meta-data.
') + % xml_escape(self.build_url('view', vid='schemagraph', skipmeta=0))) + self.w(u'%s\n' % ( + xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)), + self.req._("graphical representation of the application'schema"))) + + +class SchemaTabTextView(StartupView): + id = 'schema-text' + + def call(self): + rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, ' + 'X final FALSE') + self.wview('table', rset, displayfilter=True) + + +class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): + id = 'schema-security' + __select__ = StartupView.__select__ & match_user_groups('managers') - title = _("site schema") - category = 'siteactions' - order = 30 + def call(self, display_relations=True): + self.req.add_css('cubicweb.acl.css') + skiptypes = skip_types(self.req) + formparams = {} + formparams['sec'] = self.id + if not skiptypes: + formparams['skipmeta'] = u'0' + schema = self.schema + # compute entities + entities = sorted(eschema for eschema in schema.entities() + if not (eschema.is_final() or eschema in skiptypes)) + # compute relations + if display_relations: + relations = sorted(rschema for rschema in schema.relations() + if not (rschema.is_final() + or rschema in skiptypes + or rschema in META_RELATIONS_TYPES)) + else: + relations = [] + # index + _ = self.req._ + self.w(u'
') + self.w(u'

%s

' % _('index').capitalize()) + self.w(u'

%s

' % _('Entities').capitalize()) + ents = [] + for eschema in sorted(entities): + url = xml_escape(self.build_url('schema', **formparams)) + ents.append(u'
%s (%s)' % ( + url, eschema.type, eschema.type, _(eschema.type))) + self.w(u', '.join(ents)) + self.w(u'

%s

' % (_('relations').capitalize())) + rels = [] + for rschema in sorted(relations): + url = xml_escape(self.build_url('schema', **formparams)) + rels.append(u'%s (%s), ' % ( + url , rschema.type, rschema.type, _(rschema.type))) + self.w(u', '.join(ents)) + # entities + self.display_entities(entities, formparams) + # relations + if relations: + self.display_relations(relations, formparams) + self.w(u'
') - def url(self): - return self.build_url(self.id) + def display_entities(self, entities, formparams): + _ = self.req._ + self.w(u'') + self.w(u'

%s

' % _('permissions for entities').capitalize()) + for eschema in entities: + self.w(u'
' % (eschema.type, eschema.type)) + self.w(u'

%s (%s) ' % (eschema.type, _(eschema.type))) + url = xml_escape(self.build_url('schema', **formparams) + '#index') + self.w(u'%s' % ( + url, self.req.external_resource('UP_ICON'), _('up'))) + self.w(u'

') + self.w(u'
') + self.schema_definition(eschema, link=False) + # display entity attributes only if they have some permissions modified + modified_attrs = [] + for attr, etype in eschema.attribute_definitions(): + if self.has_schema_modified_permissions(attr, attr.ACTIONS): + modified_attrs.append(attr) + if modified_attrs: + self.w(u'

%s

' % _('attributes with modified permissions:').capitalize()) + self.w(u'
') + self.w(u'
') + for attr in modified_attrs: + self.w(u'

%s (%s)

' % (attr.type, _(attr.type))) + self.schema_definition(attr, link=False) + self.w(u'
') + def display_relations(self, relations, formparams): + _ = self.req._ + self.w(u'') + self.w(u'

%s

' % _('permissions for relations').capitalize()) + for rschema in relations: + self.w(u'
' % (rschema.type, rschema.type)) + self.w(u'

%s (%s) ' % (rschema.type, _(rschema.type))) + url = xml_escape(self.build_url('schema', **formparams) + '#index') + self.w(u'%s' % ( + url, self.req.external_resource('UP_ICON'), _('up'))) + self.w(u'

') + self.w(u'
') + subjects = [str(subj) for subj in rschema.subjects()] + self.w(u'
%s %s (%s)
' % ( + _('subject_plural:'), + ', '.join(str(subj) for subj in rschema.subjects()), + ', '.join(_(str(subj)) for subj in rschema.subjects()))) + self.w(u'
%s %s (%s)
' % ( + _('object_plural:'), + ', '.join(str(obj) for obj in rschema.objects()), + ', '.join(_(str(obj)) for obj in rschema.objects()))) + self.schema_definition(rschema, link=False) + self.w(u'
') + + +class SchemaUreportsView(StartupView): + id = 'schema-block' + + def call(self): + viewer = SchemaViewer(self.req) + layout = viewer.visit_schema(self.schema, display_relations=True, + skiptypes=skip_types(self.req)) + self.w(uilib.ureport_as_html(layout)) + + +# CWAttribute / CWRelation ##################################################### class CWRDEFPrimaryView(primary.PrimaryView): __select__ = implements('CWAttribute', 'CWRelation') @@ -196,11 +337,13 @@ def should_display_schema(self, rschema): return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema) - and rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')) + and (rschema.has_local_role('read') + or rschema.has_perm(self.req, 'read'))) def should_display_attr(self, rschema): return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema) - and rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')) + and (rschema.has_local_role('read') + or rschema.has_perm(self.req, 'read'))) class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor): @@ -221,10 +364,12 @@ def _generate(self, tmpfile): """display global schema information""" + print 'skipedtypes', skip_types(self.req) visitor = FullSchemaVisitor(self.req, self.schema, skiptypes=skip_types(self.req)) s2d.schema2dot(outputfile=tmpfile, visitor=visitor) + class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): id = 'schemagraph' __select__ = implements('CWEType') @@ -238,6 +383,7 @@ skiptypes=skip_types(self.req)) s2d.schema2dot(outputfile=tmpfile, visitor=visitor) + class CWRTypeSchemaImageView(CWETypeSchemaImageView): __select__ = implements('CWRType') @@ -248,9 +394,21 @@ visitor = OneHopRSchemaVisitor(self.req, rschema) s2d.schema2dot(outputfile=tmpfile, visitor=visitor) -### facets + +# misc: facets, actions ######################################################## + +class CWFinalFacet(facet.AttributeFacet): + id = 'cwfinal-facet' + __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType') + rtype = 'final' -class CWFinalFacet(AttributeFacet): - id = 'cwfinal-facet' - __select__ = AttributeFacet.__select__ & implements('CWEType', 'CWRType') - rtype = 'final' +class ViewSchemaAction(action.Action): + id = 'schema' + __select__ = yes() + + title = _("site schema") + category = 'siteactions' + order = 30 + + def url(self): + return self.build_url(self.id) diff -r 85be7a811afe -r 44b2eea35efa web/views/startup.py --- a/web/views/startup.py Thu Jul 23 13:35:06 2009 +0200 +++ b/web/views/startup.py Thu Jul 23 15:07:08 2009 +0200 @@ -14,10 +14,8 @@ from cubicweb.view import StartupView from cubicweb.selectors import match_user_groups, implements -from cubicweb.schema import META_RELATIONS_TYPES, display_name -from cubicweb.common.uilib import ureport_as_html +from cubicweb.schema import display_name from cubicweb.web import ajax_replace_url, uicfg, httpcache -from cubicweb.web.views import tabs, management, schema as schemamod class ManageView(StartupView): id = 'manage' @@ -163,154 +161,3 @@ def display_folders(self): return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0] -class SchemaView(tabs.TabsMixin, StartupView): - id = 'schema' - title = _('application schema') - tabs = [_('schema-text'), _('schema-image')] - default_tab = 'schema-text' - - def call(self): - """display schema information""" - self.req.add_js('cubicweb.ajax.js') - self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css')) - self.w(u'

%s

' % _('Schema of the data model')) - self.render_tabs(self.tabs, self.default_tab) - - -class SchemaTabImageView(StartupView): - id = 'schema-image' - - def call(self): - self.w(_(u'
This schema of the data model excludes the ' - u'meta-data, but you can also display a complete ' - u'schema with meta-data.
') - % xml_escape(self.build_url('view', vid='schemagraph', withmeta=1))) - self.w(u'%s\n' % ( - xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)), - self.req._("graphical representation of the application'schema"))) - - -class SchemaTabTextView(StartupView): - id = 'schema-text' - - def call(self): - rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, ' - 'X final FALSE') - self.wview('table', rset, displayfilter=True) - - -class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): - id = 'schema-security' - __select__ = StartupView.__select__ & match_user_groups('managers') - - def call(self, display_relations=True): - self.req.add_css('cubicweb.acl.css') - skiptypes = schemamod.skip_types(self.req) - formparams = {} - formparams['sec'] = self.id - if not skiptypes: - formparams['skipmeta'] = u'0' - schema = self.schema - # compute entities - entities = sorted(eschema for eschema in schema.entities() - if not (eschema.is_final() or eschema in skiptypes)) - # compute relations - if display_relations: - relations = sorted(rschema for rschema in schema.relations() - if not (rschema.is_final() - or rschema in skiptypes - or rschema in META_RELATIONS_TYPES)) - else: - relations = [] - # index - _ = self.req._ - self.w(u'
') - self.w(u'

%s

' % _('index').capitalize()) - self.w(u'

%s

' % _('Entities').capitalize()) - ents = [] - for eschema in sorted(entities): - url = xml_escape(self.build_url('schema', **formparams)) - ents.append(u'
%s (%s)' % ( - url, eschema.type, eschema.type, _(eschema.type))) - self.w(u', '.join(ents)) - self.w(u'

%s

' % (_('relations').capitalize())) - rels = [] - for rschema in sorted(relations): - url = xml_escape(self.build_url('schema', **formparams)) - rels.append(u'%s (%s), ' % ( - url , rschema.type, rschema.type, _(rschema.type))) - self.w(u', '.join(ents)) - # entities - self.display_entities(entities, formparams) - # relations - if relations: - self.display_relations(relations, formparams) - self.w(u'
') - - def display_entities(self, entities, formparams): - _ = self.req._ - self.w(u'') - self.w(u'

%s

' % _('permissions for entities').capitalize()) - for eschema in entities: - self.w(u'
' % (eschema.type, eschema.type)) - self.w(u'

%s (%s) ' % (eschema.type, _(eschema.type))) - url = xml_escape(self.build_url('schema', **formparams) + '#index') - self.w(u'%s' % ( - url, self.req.external_resource('UP_ICON'), _('up'))) - self.w(u'

') - self.w(u'
') - self.schema_definition(eschema, link=False) - # display entity attributes only if they have some permissions modified - modified_attrs = [] - for attr, etype in eschema.attribute_definitions(): - if self.has_schema_modified_permissions(attr, attr.ACTIONS): - modified_attrs.append(attr) - if modified_attrs: - self.w(u'

%s

' % _('attributes with modified permissions:').capitalize()) - self.w(u'
') - self.w(u'
') - for attr in modified_attrs: - self.w(u'

%s (%s)

' % (attr.type, _(attr.type))) - self.schema_definition(attr, link=False) - self.w(u'
') - - def display_relations(self, relations, formparams): - _ = self.req._ - self.w(u'') - self.w(u'

%s

' % _('permissions for relations').capitalize()) - for rschema in relations: - self.w(u'
' % (rschema.type, rschema.type)) - self.w(u'

%s (%s) ' % (rschema.type, _(rschema.type))) - url = xml_escape(self.build_url('schema', **formparams) + '#index') - self.w(u'%s' % ( - url, self.req.external_resource('UP_ICON'), _('up'))) - self.w(u'

') - self.w(u'
') - subjects = [str(subj) for subj in rschema.subjects()] - self.w(u'
%s %s (%s)
' % ( - _('subject_plural:'), - ', '.join(str(subj) for subj in rschema.subjects()), - ', '.join(_(str(subj)) for subj in rschema.subjects()))) - self.w(u'
%s %s (%s)
' % ( - _('object_plural:'), - ', '.join(str(obj) for obj in rschema.objects()), - ', '.join(_(str(obj)) for obj in rschema.objects()))) - self.schema_definition(rschema, link=False) - self.w(u'
') - - -class SchemaUreportsView(StartupView): - id = 'schematext' - - def call(self): - from cubicweb.schemaviewer import SchemaViewer - if int(self.req.form.get('skipmeta', True)): - skip = schema.SKIP_TYPES - else: - skip = () - viewer = SchemaViewer(self.req) - layout = viewer.visit_schema(self.schema, display_relations=True, - skiptypes=skip) - self.w(ureport_as_html(layout)) - -