3.6 update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 13 Oct 2009 18:20:05 +0200
changeset 3659 993997b4b41d
parent 3658 d8f2ec7e91fa
child 3660 7b41a6ba7400
3.6 update
hooks/syncschema.py
req.py
server/hook.py
server/migractions.py
web/views/basecomponents.py
web/views/basecontrollers.py
web/views/basetemplates.py
web/views/workflow.py
--- a/hooks/syncschema.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/hooks/syncschema.py	Tue Oct 13 18:20:05 2009 +0200
@@ -356,11 +356,11 @@
                            table, column, ex)
         # final relations are not infered, propagate
         try:
-            eschema = self.schema.eschema(rdef.subject)
+            eschema = self._cw.vreg.schema.eschema(rdef.subject)
         except KeyError:
             return # entity type currently being added
         # propagate attribute to children classes
-        rschema = self.schema.rschema(rdef.name)
+        rschema = self._cw.vreg.schema.rschema(rdef.name)
         # if relation type has been inserted in the same transaction, its final
         # attribute is still set to False, so we've to ensure it's False
         rschema.final = True
--- a/req.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/req.py	Tue Oct 13 18:20:05 2009 +0200
@@ -11,6 +11,7 @@
 from datetime import time, datetime, timedelta
 
 from logilab.common.decorators import cached
+from logilab.common.deprecation import deprecated
 
 from cubicweb import Unauthorized, RegistryException, typed_eid
 from cubicweb.rset import ResultSet
@@ -332,3 +333,13 @@
     def describe(self, eid):
         """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
         raise NotImplementedError
+
+    @property
+    @deprecated('[3.6] use _cw.vreg.config')
+    def config(self):
+        return self.vreg.config
+
+    @property
+    @deprecated('[3.6] use _cw.vreg.schema')
+    def schema(self):
+        return self.vreg.schema
--- a/server/hook.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/server/hook.py	Tue Oct 13 18:20:05 2009 +0200
@@ -199,19 +199,19 @@
     object_relations = None
     accepts = None # subject_relations + object_relations
 
-    def call(self, session, fromeid, rtype, toeid):
-        for eid in (fromeid, toeid):
-            etype = session.describe(eid)[0]
-            if not self.schema.eschema(etype).has_subject_relation(self.rtype):
+    def __call__(self):
+        for eid in (self.eidfrom, self.eidto):
+            etype = self._cw.describe(eid)[0]
+            if not self.schema.eschema(etype).has_subject_relation(self.main_rtype):
                 return
-        if rtype in self.subject_relations:
-            meid, seid = fromeid, toeid
+        if self.rtype in self.subject_relations:
+            meid, seid = self.eidfrom, self.eidto
         else:
-            assert rtype in self.object_relations
-            meid, seid = toeid, fromeid
-        session.unsafe_execute(
+            assert self.rtype in self.object_relations
+            meid, seid = self.eidto, self.eidfrom
+        self._cw.unsafe_execute(
             'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\
-            % (self.rtype, self.rtype, self.rtype),
+            % (self.main_rtype, self.main_rtype, self.main_rtype),
             {'x': meid, 'e': seid}, ('x', 'e'))
 
 
@@ -219,48 +219,46 @@
     """propagate on existing entities when a permission or nosy list is added"""
     events = ('after_add_relation',)
     # to set in concrete class
-    rtype = None
+    main_rtype = None
     subject_relations = None
     object_relations = None
-    accepts = None # (self.rtype,)
 
-    def call(self, session, fromeid, rtype, toeid):
-        eschema = self.schema.eschema(session.describe(fromeid)[0])
-        execute = session.unsafe_execute
+    def __call__(self):
+        eschema = self.schema.eschema(self._cw.describe(self.eidfrom)[0])
+        execute = self._cw.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
                 execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                        'X %s R, NOT R %s P' % (rtype, rel, rtype),
-                        {'x': fromeid, 'p': toeid}, 'x')
+                        'X %s R, NOT R %s P' % (self.rtype, rel, self.rtype),
+                        {'x': self.eidfrom, 'p': self.eidto}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
                 execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                        'R %s X, NOT R %s P' % (rtype, rel, rtype),
-                        {'x': fromeid, 'p': toeid}, 'x')
+                        'R %s X, NOT R %s P' % (self.rtype, rel, self.rtype),
+                        {'x': self.eidfrom, 'p': self.eidto}, 'x')
 
 
 class PropagateSubjectRelationDelHook(Hook):
     """propagate on existing entities when a permission is deleted"""
     events = ('after_delete_relation',)
     # to set in concrete class
-    rtype = None
+    main_rtype = None
     subject_relations = None
     object_relations = None
-    accepts = None # (self.rtype,)
 
-    def call(self, session, fromeid, rtype, toeid):
-        eschema = self.schema.eschema(session.describe(fromeid)[0])
-        execute = session.unsafe_execute
+    def __call__(self):
+        eschema = self.schema.eschema(self._cw.describe(self.eidfrom)[0])
+        execute = self._cw.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
                 execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                        'X %s R' % (rtype, rel),
-                        {'x': fromeid, 'p': toeid}, 'x')
+                        'X %s R' % (self.rtype, rel),
+                        {'x': self.eidfrom, 'p': self.eidto}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
                 execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                        'R %s X' % (rtype, rel),
-                        {'x': fromeid, 'p': toeid}, 'x')
+                        'R %s X' % (self.rtype, rel),
+                        {'x': self.eidfrom, 'p': self.eidto}, 'x')
 
 
 # abstract classes for operation ###############################################
--- a/server/migractions.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/server/migractions.py	Tue Oct 13 18:20:05 2009 +0200
@@ -212,7 +212,7 @@
                 login, pwd = manager_userpasswd()
             while True:
                 try:
-                    self._cnx = repo_connect(self.repo, login, pwd)
+                    self._cnx = repo_connect(self.repo, login, password=pwd)
                     if not 'managers' in self._cnx.user(self.session).groups:
                         print 'migration need an account in the managers group'
                     else:
--- a/web/views/basecomponents.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/web/views/basecomponents.py	Tue Oct 13 18:20:05 2009 +0200
@@ -108,7 +108,7 @@
             self.anon_user_link()
 
     def anon_user_link(self):
-        if self._cw.config['auth-mode'] == 'cookie':
+        if self._cw.vreg.config['auth-mode'] == 'cookie':
             self.w(self._cw._('anonymous'))
             self.w(u'''&#160;[<a class="logout" href="javascript: popupLoginBox();">%s</a>]'''
                    % (self._cw._('i18n_login_popup')))
--- a/web/views/basecontrollers.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/web/views/basecontrollers.py	Tue Oct 13 18:20:05 2009 +0200
@@ -116,13 +116,13 @@
             except Exception, ex:
                 self.exception('while handling __method')
                 req.set_message(req._("error while handling __method: %s") % req._(ex))
-        vid = req.form.get('vid') or vid_from_rset(req, rset, self._cw.schema)
+        vid = req.form.get('vid') or vid_from_rset(req, rset, self._cw.vreg.schema)
         try:
             view = self._cw.vreg['views'].select(vid, req, rset=rset)
         except ObjectNotFound:
             self.warning("the view %s could not be found", vid)
             req.set_message(req._("The view %s could not be found") % vid)
-            vid = vid_from_rset(req, rset, self._cw.schema)
+            vid = vid_from_rset(req, rset, self._cw.vreg.schema)
             view = self._cw.vreg['views'].select(vid, req, rset=rset)
         except NoSelectableObject:
             if rset:
@@ -131,7 +131,7 @@
                 req.set_message(req._("You have no access to this view or it can not "
                                       "be used to display the current data."))
             self.warning("the view %s can not be applied to this query", vid)
-            vid = vid_from_rset(req, rset, self._cw.schema)
+            vid = vid_from_rset(req, rset, self._cw.vreg.schema)
             view = self._cw.vreg['views'].select(vid, req, rset=rset)
         return view, rset
 
@@ -345,7 +345,7 @@
             rset = self._exec(rql)
         else:
             rset = None
-        vid = req.form.get('vid') or vid_from_rset(req, rset, self._cw.schema)
+        vid = req.form.get('vid') or vid_from_rset(req, rset, self._cw.vreg.schema)
         try:
             view = self._cw.vreg['views'].select(vid, req, rset=rset)
         except NoSelectableObject:
--- a/web/views/basetemplates.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/web/views/basetemplates.py	Tue Oct 13 18:20:05 2009 +0200
@@ -58,7 +58,7 @@
         # FIXME Deprecated code ?
         msg = self._cw._('you have been logged out')
         w(u'<h2>%s</h2>\n' % msg)
-        if self._cw.config['anonymous-user']:
+        if self._cw.vreg.config['anonymous-user']:
             indexurl = self._cw.build_url('view', vid='index', __message=msg)
             w(u'<p><a href="%s">%s</a><p>' % (
                 xml_escape(indexurl),
@@ -489,7 +489,7 @@
 
         if message:
             self.display_message()
-        if self._cw.config['auth-mode'] == 'http':
+        if self._cw.vreg.config['auth-mode'] == 'http':
             # HTTP authentication
             pass
         else:
@@ -505,22 +505,28 @@
     def login_form(self, id):
         _ = self._cw._
         self.w(u'<form method="post" action="%s" id="login_form">\n'
-               % xml_escape(login_form_url(self._cw.config, self._cw)))
+               % xml_escape(login_form_url(self._cw.vreg.config, self._cw)))
         self.w(u'<table>\n')
+        self.add_fields()
         self.w(u'<tr>\n')
-        msg = (self._cw.config['allow-email-login'] and _('login or email')) or _('login')
-        self.w(u'<td><label for="__login">%s</label></td>' % msg)
-        self.w(u'<td><input name="__login" id="__login" class="data" type="text" /></td>')
-        self.w(u'</tr><tr>\n')
-        self.w(u'<td><label for="__password" >%s</label></td>' % _('password'))
-        self.w(u'<td><input name="__password" id="__password" class="data" type="password" /></td>\n')
-        self.w(u'</tr><tr>\n')
         self.w(u'<td>&#160;</td><td><input type="submit" class="loginButton right" value="%s" />\n</td>' % _('log in'))
         self.w(u'</tr>\n')
         self.w(u'</table>\n')
         self.w(u'</form>\n')
         self._cw.html_headers.add_onload('jQuery("#__login:visible").focus()')
 
+    def add_fields(self):
+        msg = (self._cw.vreg.config['allow-email-login'] and _('login or email')) or _('login')
+        self.add_field('__login', msg, 'text')
+        self.add_field('__password', self._cw._('password'), 'password')
+
+    def add_field(self, name, label, inputtype):
+        self.w(u'<tr>\n')
+        self.w(u'<td><label for="%s" >%s</label></td>' % (name, label))
+        self.w(u'<td><input name="%s" id="%s" class="data" type="%s" /></td>\n' %
+               (name, name, inputtype))
+        self.w(u'</tr>\n')
+
 
 def login_form_url(config, req):
     if req.https:
--- a/web/views/workflow.py	Tue Oct 13 16:00:09 2009 +0200
+++ b/web/views/workflow.py	Tue Oct 13 18:20:05 2009 +0200
@@ -39,9 +39,9 @@
 _abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
 
 _afs = uicfg.autoform_section
-_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'generated')
-_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'generated')
-_afs.tag_object_of(('State', 'allowed_transition', '*'), 'primary')
+_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
+_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
 
 
 # IWorkflowable views #########################################################