3.6 updates
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 13 Oct 2009 15:59:05 +0200
changeset 3655 af86ab65a282
parent 3654 e4bed64e0ad7
child 3656 9ba2e3253a88
3.6 updates
cwvreg.py
req.py
web/controller.py
web/uicfg.py
web/views/autoform.py
web/views/basetemplates.py
web/views/wdoc.py
--- a/cwvreg.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/cwvreg.py	Tue Oct 13 15:59:05 2009 +0200
@@ -174,12 +174,13 @@
 
 class ViewsRegistry(CWRegistry):
 
-    def main_template(self, req, oid='main-template', **kwargs):
+    def main_template(self, req, oid='main-template', rset=None, **kwargs):
         """display query by calling the given template (default to main),
         and returning the output as a string instead of requiring the [w]rite
         method as argument
         """
-        res = self.render(oid, req, **kwargs)
+        obj = self.select(oid, req, rset=rset, **kwargs)
+        res = obj.render(**kwargs)
         if isinstance(res, unicode):
             return res.encode(req.encoding)
         assert isinstance(res, str)
--- a/req.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/req.py	Tue Oct 13 15:59:05 2009 +0200
@@ -12,7 +12,7 @@
 
 from logilab.common.decorators import cached
 
-from cubicweb import Unauthorized, typed_eid
+from cubicweb import Unauthorized, RegistryException, typed_eid
 from cubicweb.rset import ResultSet
 from cubicweb.utils import ustrftime, strptime, todate, todatetime
 
@@ -254,8 +254,12 @@
     def view(self, __vid, rset=None, __fallback_oid=None, __registry='views',
              **kwargs):
         """shortcut to self.vreg.view method avoiding to pass the request"""
-        return self.vreg[__registry].render(__vid, self, __fallback_oid,
-                                            rset=rset, **kwargs)
+        try:
+            view =  self.vreg[__registry].select(__vid, self, rset=rset, **kwargs)
+        except RegistryException:
+            view =  self.vreg[__registry].select(__fallback_oid, self,
+                                                 rset=rset, **kwargs)
+        return view.render(**kwargs)
 
     def format_date(self, date, date_format=None, time=False):
         """return a string for a date time according to instance's
--- a/web/controller.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/web/controller.py	Tue Oct 13 15:59:05 2009 +0200
@@ -89,12 +89,12 @@
         # XXX assigning to self really necessary?
         self.cw_rset = None
         if rql:
-            self.req.ensure_ro_rql(rql)
+            self._cw.ensure_ro_rql(rql)
             if not isinstance(rql, unicode):
-                rql = unicode(rql, self.req.encoding)
-            pp = self.vreg['components'].select_or_none('magicsearch', self.req)
+                rql = unicode(rql, self._cw.encoding)
+            pp = self._cw.vreg['components'].select_or_none('magicsearch', self._cw)
             if pp is not None:
-                self.cw_rset = pp.process_query(rql, self.req)
+                self.cw_rset = pp.process_query(rql)
         return self.cw_rset
 
     def check_expected_params(self, params):
@@ -103,7 +103,7 @@
         """
         missing = []
         for param in params:
-            if not self.req.form.get(param):
+            if not self._cw.form.get(param):
                 missing.append(param)
         if missing:
             raise RequestError('missing required parameter(s): %s'
@@ -123,7 +123,7 @@
         redirect_info = set()
         eidtypes = tuple(eidtypes)
         for eid, etype in eidtypes:
-            entity = self.req.entity_from_eid(eid, etype)
+            entity = self._cw.entity_from_eid(eid, etype)
             path, params = entity.after_deletion_path()
             redirect_info.add( (path, tuple(params.iteritems())) )
             entity.delete()
@@ -133,22 +133,22 @@
         else:
             self._after_deletion_path = iter(redirect_info).next()
         if len(eidtypes) > 1:
-            self.req.set_message(self.req._('entities deleted'))
+            self._cw.set_message(self._cw._('entities deleted'))
         else:
-            self.req.set_message(self.req._('entity deleted'))
+            self._cw.set_message(self._cw._('entity deleted'))
 
     def delete_relations(self, rdefs):
         """delete relations from the repository"""
         # FIXME convert to using the syntax subject:relation:eids
-        execute = self.req.execute
+        execute = self._cw.execute
         for subj, rtype, obj in rdefs:
             rql = 'DELETE X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype
             execute(rql, {'x': subj, 'y': obj}, ('x', 'y'))
-        self.req.set_message(self.req._('relations deleted'))
+        self._cw.set_message(self._cw._('relations deleted'))
 
     def insert_relations(self, rdefs):
         """insert relations into the repository"""
-        execute = self.req.execute
+        execute = self._cw.execute
         for subj, rtype, obj in rdefs:
             rql = 'SET X %s Y where X eid %%(x)s, Y eid %%(y)s' % rtype
             execute(rql, {'x': subj, 'y': obj}, ('x', 'y'))
@@ -160,11 +160,11 @@
         """
         newparams = {}
         # sets message if needed
-        if self.req.message:
-            newparams['__message'] = self.req.message
-        if self.req.form.has_key('__action_apply'):
+        if self._cw.message:
+            newparams['__message'] = self._cw.message
+        if self._cw.form.has_key('__action_apply'):
             self._return_to_edition_view(newparams)
-        if self.req.form.has_key('__action_cancel'):
+        if self._cw.form.has_key('__action_cancel'):
             self._return_to_lastpage(newparams)
         else:
             self._return_to_original_view(newparams)
@@ -173,7 +173,7 @@
     def _return_to_original_view(self, newparams):
         """validate-button case"""
         # transforms __redirect[*] parameters into regular form parameters
-        newparams.update(redirect_params(self.req.form))
+        newparams.update(redirect_params(self._cw.form))
         # find out if we have some explicit `rql` needs
         rql = newparams.pop('rql', None)
         # if rql is needed (explicit __redirectrql or multiple deletions for
@@ -181,9 +181,9 @@
         if rql:
             path = 'view'
             newparams['rql'] = rql
-        elif '__redirectpath' in self.req.form:
+        elif '__redirectpath' in self._cw.form:
             # if redirect path was explicitly specified in the form, use it
-            path = self.req.form['__redirectpath']
+            path = self._cw.form['__redirectpath']
             if self._edited_entity and path != self._edited_entity.rest_path():
                 # XXX may be here on modification? if yes the message should be
                 # modified where __createdpath is detected (cw.web.request)
@@ -199,18 +199,18 @@
         else:
             path = 'view'
         url = self._cw.build_url(path, **newparams)
-        url = append_url_params(url, self.req.form.get('__redirectparams'))
+        url = append_url_params(url, self._cw.form.get('__redirectparams'))
         raise Redirect(url)
 
 
     def _return_to_edition_view(self, newparams):
         """apply-button case"""
-        form = self.req.form
+        form = self._cw.form
         if self._edited_entity:
             path = self._edited_entity.rest_path()
             newparams.pop('rql', None)
         # else, fallback on the old `view?rql=...` url form
-        elif 'rql' in self.req.form:
+        elif 'rql' in self._cw.form:
             path = 'view'
             newparams['rql'] = form['rql']
         else:
@@ -232,13 +232,13 @@
         __redirectpath is specifying that place if found, else we look in the
         request breadcrumbs for the last visited page.
         """
-        if '__redirectpath' in self.req.form:
+        if '__redirectpath' in self._cw.form:
             # if redirect path was explicitly specified in the form, use it
-            path = self.req.form['__redirectpath']
+            path = self._cw.form['__redirectpath']
             url = self._cw.build_url(path, **newparams)
-            url = append_url_params(url, self.req.form.get('__redirectparams'))
+            url = append_url_params(url, self._cw.form.get('__redirectparams'))
         else:
-            url = self.req.last_visited_page()
+            url = self._cw.last_visited_page()
         raise Redirect(url)
 
 
--- a/web/uicfg.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/web/uicfg.py	Tue Oct 13 15:59:05 2009 +0200
@@ -63,7 +63,7 @@
 :autoform_section:
    where to display a relation in entity form, according to form type.
    `tag_attribute`, `tag_subject_of` and `tag_object_of` methods for this
-   relation tags expect two arguments additionaly to the relation key: a
+    relation tags expect two arguments additionaly to the relation key: a
    `formtype` and a `section`.
 
    formtype may be one of:
--- a/web/views/autoform.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/web/views/autoform.py	Tue Oct 13 15:59:05 2009 +0200
@@ -360,35 +360,46 @@
 
 ## default form ui configuration ##############################################
 
+_afs = uicfg.autoform_section
 # use primary and not generated for eid since it has to be an hidden
-uicfg.autoform_section.tag_attribute(('*', 'eid'), 'primary')
-uicfg.autoform_section.tag_attribute(('*', 'description'), 'secondary')
-uicfg.autoform_section.tag_attribute(('*', 'creation_date'), 'metadata')
-uicfg.autoform_section.tag_attribute(('*', 'modification_date'), 'metadata')
-uicfg.autoform_section.tag_attribute(('*', 'cwuri'), 'metadata')
-uicfg.autoform_section.tag_attribute(('*', 'has_text'), 'generated')
-uicfg.autoform_section.tag_subject_of(('*', 'in_state', '*'), 'generated')
-uicfg.autoform_section.tag_subject_of(('*', 'owned_by', '*'), 'metadata')
-uicfg.autoform_section.tag_subject_of(('*', 'created_by', '*'), 'metadata')
-uicfg.autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated')
-uicfg.autoform_section.tag_subject_of(('*', 'by_transition', '*'), 'primary')
-uicfg.autoform_section.tag_object_of(('*', 'by_transition', '*'), 'generated')
-uicfg.autoform_section.tag_object_of(('*', 'from_state', '*'), 'generated')
-uicfg.autoform_section.tag_object_of(('*', 'to_state', '*'), 'generated')
-uicfg.autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'primary')
-uicfg.autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated')
-uicfg.autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated')
-uicfg.autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated')
-uicfg.autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary')
-uicfg.autoform_section.tag_attribute(('CWEType', 'final'), 'generated')
-uicfg.autoform_section.tag_attribute(('CWRType', 'final'), 'generated')
-uicfg.autoform_section.tag_attribute(('CWUser', 'firstname'), 'secondary')
-uicfg.autoform_section.tag_attribute(('CWUser', 'surname'), 'secondary')
-uicfg.autoform_section.tag_attribute(('CWUser', 'last_login_time'), 'metadata')
-uicfg.autoform_section.tag_subject_of(('CWUser', 'in_group', '*'), 'primary')
-uicfg.autoform_section.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'metadata')
-uicfg.autoform_section.tag_attribute(('Bookmark', 'path'), 'primary')
-uicfg.autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic')
+_afs.tag_attribute(('*', 'eid'), 'main', 'attributes')
+_afs.tag_attribute(('*', 'eid'), 'muledit', 'attributes')
+_afs.tag_attribute(('*', 'description'), 'main', 'attributes')
+_afs.tag_attribute(('*', 'creation_date'), 'main', 'metadata')
+_afs.tag_attribute(('*', 'modification_date'), 'main', 'metadata')
+_afs.tag_attribute(('*', 'cwuri'), 'main', 'metadata')
+_afs.tag_attribute(('*', 'has_text'), 'main', 'hidden')
+_afs.tag_subject_of(('*', 'in_state', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('*', 'owned_by', '*'), 'main', 'metadata')
+_afs.tag_subject_of(('*', 'created_by', '*'), 'main', 'metadata')
+_afs.tag_subject_of(('*', 'require_permission', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('*', 'by_transition', '*'), 'main', 'attributes')
+_afs.tag_subject_of(('*', 'by_transition', '*'), 'muledit', 'attributes')
+_afs.tag_object_of(('*', 'by_transition', '*'), 'main', 'hidden')
+_afs.tag_object_of(('*', 'from_state', '*'), 'main', 'hidden')
+_afs.tag_object_of(('*', 'to_state', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('*', 'wf_info_for', '*'), 'main', 'attributes')
+_afs.tag_subject_of(('*', 'wf_info_for', '*'), 'muledit', 'attributes')
+_afs.tag_object_of(('*', 'wf_info_for', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('*', 'for_user', '*'), 'main', 'hidden')
+_afs.tag_object_of(('*', 'for_user', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('CWPermission', 'require_group', '*'), 'main', 'attributes')
+_afs.tag_subject_of(('CWPermission', 'require_group', '*'), 'muledit', 'attributes')
+_afs.tag_attribute(('CWEType', 'final'), 'main', 'hidden')
+_afs.tag_attribute(('CWRType', 'final'), 'main', 'hidden')
+_afs.tag_attribute(('CWUser', 'firstname'), 'main', 'attributes')
+_afs.tag_attribute(('CWUser', 'surname'), 'main', 'attributes')
+_afs.tag_attribute(('CWUser', 'last_login_time'), 'main', 'metadata')
+_afs.tag_subject_of(('CWUser', 'in_group', '*'), 'main', 'attributes')
+_afs.tag_subject_of(('CWUser', 'in_group', '*'), 'muledit', 'attributes')
+_afs.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'main', 'metadata')
+_afs.tag_attribute(('Bookmark', 'path'), 'main', 'attributes')
+_afs.tag_attribute(('Bookmark', 'path'), 'muledit', 'attributes')
+_afs.tag_subject_of(('*', 'primary_email', '*'), 'main', 'relations')
+_afs.tag_subject_of(('*', 'use_email', '*'), 'main', 'inlined')
+_afs.tag_subject_of(('CWRelation', 'relation_type', '*'), 'main', 'inlined')
+_afs.tag_subject_of(('CWRelation', 'from_entity', '*'), 'main', 'inlined')
+_afs.tag_subject_of(('CWRelation', 'to_entity', '*'), 'main', 'inlined')
 
 uicfg.autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
                                           {'widget': fwdgs.TextInput})
@@ -396,8 +407,3 @@
                                           {'widget': fwdgs.TextInput})
 uicfg.autoform_field_kwargs.tag_subject_of(('TrInfo', 'wf_info_for', '*'),
                                            {'widget': fwdgs.HiddenInput})
-
-uicfg.autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True)
-uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True)
-uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True)
-uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True)
--- a/web/views/basetemplates.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/web/views/basetemplates.py	Tue Oct 13 15:59:05 2009 +0200
@@ -424,11 +424,12 @@
     def call(self, **kwargs):
         req = self._cw
         self.w(u'<div class="footer">')
-        actions = self.vreg['actions'].possible_actions(self.req, rset=self.rset)
+        actions = self._cw.vreg['actions'].possible_actions(self._cw,
+                                                            rset=self.cw_rset)
         footeractions = actions.get('footer', ())
         for i, action in enumerate(footeractions):
             self.w(u'<a href="%s">%s</a>' % (action.url(),
-                                             self.req._(action.title)))
+                                             self._cw._(action.title)))
             if i < (len(footeractions) - 1):
                 self.w(u' | ')
         self.w(u'</div>')
--- a/web/views/wdoc.py	Tue Oct 13 12:04:36 2009 +0200
+++ b/web/views/wdoc.py	Tue Oct 13 15:59:05 2009 +0200
@@ -237,7 +237,7 @@
 
 
 class ChangeLogAction(action.Action):
-    id = 'changelog'
+    __regid__ = 'changelog'
     __select__ = yes()
 
     category = 'footer'
@@ -245,11 +245,11 @@
     title = ChangeLogView.title
 
     def url(self):
-        return self.req.build_url('changelog')
+        return self._cw.build_url('changelog')
 
 
 class AboutAction(action.Action):
-    id = 'about'
+    __regid__ = 'about'
     __select__ = yes()
 
     category = 'footer'
@@ -257,5 +257,5 @@
     title = _('about this site')
 
     def url(self):
-        return self.req.build_url('doc/about')
+        return self._cw.build_url('doc/about')