diff -r 495862266785 -r 6b46d73823f5 web/views/schema.py
--- a/web/views/schema.py Wed Sep 23 19:26:38 2009 +0200
+++ b/web/views/schema.py Wed Sep 23 19:40:19 2009 +0200
@@ -44,8 +44,8 @@
def call(self):
"""display schema information"""
- self.req.add_js('cubicweb.ajax.js')
- self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
+ self._cw.add_js('cubicweb.ajax.js')
+ self._cw.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
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))
+ url = xml_escape(self._cw.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))
+ url = xml_escape(self._cw.build_url('schema', **formparams))
rels.append(u'
%s (%s), ' % (
url , rschema.type, rschema.type, _(rschema.type)))
self.w(u', '.join(ents))
@@ -121,18 +121,18 @@
self.w(u'
')
def display_entities(self, entities, formparams):
- _ = self.req._
+ _ = self._cw._
self.w(u'')
- self.schema_definition(eschema, link=False)
+ self._cw.schema_definition(eschema, link=False)
# display entity attributes only if they have some permissions modified
modified_attrs = []
for attr, etype in eschema.attribute_definitions():
@@ -144,19 +144,19 @@
self.w(u'
')
for attr in modified_attrs:
self.w(u'
%s (%s)
' % (attr.type, _(attr.type)))
- self.schema_definition(attr, link=False)
+ self._cw.schema_definition(attr, link=False)
self.w(u'')
def display_relations(self, relations, formparams):
- _ = self.req._
+ _ = self._cw._
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')
+ url = xml_escape(self._cw.build_url('schema', **formparams) + '#index')
self.w(u'' % (
- url, self.req.external_resource('UP_ICON'), _('up')))
+ url, self._cw.external_resource('UP_ICON'), _('up')))
self.w(u'
')
self.w(u'
')
subjects = [str(subj) for subj in rschema.subjects()]
@@ -168,7 +168,7 @@
_('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._cw.schema_definition(rschema, link=False)
self.w(u'
')
@@ -176,9 +176,9 @@
__regid__ = 'schema-block'
def call(self):
- viewer = SchemaViewer(self.req)
- layout = viewer.visit_schema(self.schema, display_relations=True,
- skiptypes=skip_types(self.req))
+ viewer = SchemaViewer(self._cw)
+ layout = viewer.visit_schema(self._cw.schema, display_relations=True,
+ skiptypes=skip_types(self._cw))
self.w(uilib.ureport_as_html(layout))
@@ -200,7 +200,7 @@
__select__ = implements('CWEType')
def cell_call(self, row, col, **kwargs):
- entity = self.rset.get_entity(row, col)
+ entity = self.cw_rset.get_entity(row, col)
final = entity.final
if final:
self.w(u'
')
@@ -228,9 +228,9 @@
__select__ = EntityView.__select__ & implements('CWEType')
def cell_call(self, row, col):
- entity = self.rset.get_entity(row, col)
+ entity = self.cw_rset.get_entity(row, col)
self.w(u'%s
' % _('Attributes'))
- rset = self.req.execute('Any N,F,D,I,J,DE,A '
+ rset = self._cw.execute('Any N,F,D,I,J,DE,A '
'ORDERBY AA WHERE A is CWAttribute, '
'A ordernum AA, A defaultval D, '
'A description DE, '
@@ -241,7 +241,7 @@
{'x': entity.eid})
self.wview('editable-table', rset, 'null', displayfilter=True)
self.w(u'%s
' % _('Relations'))
- rset = self.req.execute(
+ rset = self._cw.execute(
'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN '
'WHERE A is CWRelation, A description D, A composite K?, '
'A relation_type R, R name RN, A to_entity TT, TT name TTN, '
@@ -249,7 +249,7 @@
{'x': entity.eid})
self.wview('editable-table', rset, 'null', displayfilter=True,
displaycols=range(6), mainindex=5)
- rset = self.req.execute(
+ rset = self._cw.execute(
'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN '
'WHERE A is CWRelation, A description D, A composite K?, '
'A relation_type R, R name RN, A from_entity TT, TT name TTN, '
@@ -264,11 +264,11 @@
__select__ = EntityView.__select__ & implements('CWEType')
def cell_call(self, row, col):
- entity = self.rset.get_entity(row, col)
+ entity = self.cw_rset.get_entity(row, col)
url = entity.absolute_url(vid='schemagraph')
self.w(u'' % (
xml_escape(url),
- xml_escape(self.req._('graphical schema for %s') % entity.name)))
+ xml_escape(self._cw._('graphical schema for %s') % entity.name)))
class CWETypeSPermView(EntityView):
@@ -276,24 +276,24 @@
__select__ = EntityView.__select__ & implements('CWEType')
def cell_call(self, row, col):
- entity = self.rset.get_entity(row, col)
+ entity = self.cw_rset.get_entity(row, col)
self.w(u'%s
' % _('Add permissions'))
- rset = self.req.execute('Any P WHERE X add_permission P, '
+ rset = self._cw.execute('Any P WHERE X add_permission P, '
'X eid %(x)s',
{'x': entity.eid})
self.wview('outofcontext', rset, 'null')
self.w(u'%s
' % _('Read permissions'))
- rset = self.req.execute('Any P WHERE X read_permission P, '
+ rset = self._cw.execute('Any P WHERE X read_permission P, '
'X eid %(x)s',
{'x': entity.eid})
self.wview('outofcontext', rset, 'null')
self.w(u'%s
' % _('Update permissions'))
- rset = self.req.execute('Any P WHERE X update_permission P, '
+ rset = self._cw.execute('Any P WHERE X update_permission P, '
'X eid %(x)s',
{'x': entity.eid})
self.wview('outofcontext', rset, 'null')
self.w(u'%s
' % _('Delete permissions'))
- rset = self.req.execute('Any P WHERE X delete_permission P, '
+ rset = self._cw.execute('Any P WHERE X delete_permission P, '
'X eid %(x)s',
{'x': entity.eid})
self.wview('outofcontext', rset, 'null')
@@ -305,10 +305,10 @@
has_related_entities('workflow_of', 'object'))
def cell_call(self, row, col):
- entity = self.rset.get_entity(row, col)
+ entity = self.cw_rset.get_entity(row, col)
if entity.default_workflow:
wf = entity.default_workflow[0]
- self.w(u'%s (%s)
' % (wf.name, self.req._('default')))
+ self.w(u'%s (%s)
' % (wf.name, self._cw._('default')))
self.wf_image(wf)
for altwf in entity.reverse_workflow_of:
if altwf.eid == wf.eid:
@@ -319,7 +319,7 @@
def wf_image(self, wf):
self.w(u'' % (
xml_escape(wf.absolute_url(vid='wfgraph')),
- xml_escape(self.req._('graphical representation of %s') % wf.name)))
+ xml_escape(self._cw._('graphical representation of %s') % wf.name)))
# CWRType ######################################################################
@@ -331,12 +331,12 @@
def render_entity_attributes(self, entity):
super(CWRTypeSchemaView, self).render_entity_attributes(entity)
- rschema = self.vreg.schema.rschema(entity.name)
- viewer = SchemaViewer(self.req)
+ rschema = self._cw.vreg.schema.rschema(entity.name)
+ viewer = SchemaViewer(self._cw)
layout = viewer.visit_relationschema(rschema)
self.w(uilib.ureport_as_html(layout))
if not rschema.is_final():
- msg = self.req._('graphical schema for %s') % entity.name
+ msg = self._cw._('graphical schema for %s') % entity.name
self.w(tags.img(src=entity.absolute_url(vid='schemagraph'),
alt=msg))
@@ -345,18 +345,18 @@
class RestrictedSchemaVisitorMixIn(object):
def __init__(self, req, *args, **kwargs):
- self.req = req
+ self._cw = req
super(RestrictedSchemaVisitorMixIn, self).__init__(*args, **kwargs)
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')))
+ or rschema.has_perm(self._cw, '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')))
+ or rschema.has_perm(self._cw, 'read')))
class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor):
@@ -377,9 +377,9 @@
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))
+ print 'skipedtypes', skip_types(self._cw)
+ visitor = FullSchemaVisitor(self._cw, self._cw.schema,
+ skiptypes=skip_types(self._cw))
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
@@ -390,10 +390,10 @@
def _generate(self, tmpfile):
"""display schema information for an entity"""
- entity = self.rset.get_entity(self.row, self.col)
- eschema = self.vreg.schema.eschema(entity.name)
- visitor = OneHopESchemaVisitor(self.req, eschema,
- skiptypes=skip_types(self.req))
+ entity = self.cw_rset.get_entity(self.cw_row, self.cw_col)
+ eschema = self._cw.vreg.schema.eschema(entity.name)
+ visitor = OneHopESchemaVisitor(self._cw, eschema,
+ skiptypes=skip_types(self._cw))
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
@@ -402,9 +402,9 @@
def _generate(self, tmpfile):
"""display schema information for an entity"""
- entity = self.rset.get_entity(self.row, self.col)
- rschema = self.vreg.schema.rschema(entity.name)
- visitor = OneHopRSchemaVisitor(self.req, rschema)
+ entity = self.cw_rset.get_entity(self.cw_row, self.cw_col)
+ rschema = self._cw.vreg.schema.rschema(entity.name)
+ visitor = OneHopRSchemaVisitor(self._cw, rschema)
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
@@ -424,4 +424,4 @@
order = 30
def url(self):
- return self.build_url(self.id)
+ return self._cw.build_url(self.__regid__)