backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 01 Jul 2011 12:48:39 +0200
changeset 7599 9cbf4c86f57a
parent 7595 83872394b5d9 (current diff)
parent 7598 781def950a85 (diff)
child 7600 75d208ab8444
backport stable
server/test/unittest_rql2sql.py
--- a/doc/book/en/admin/config.rst	Fri Jul 01 11:51:04 2011 +0200
+++ b/doc/book/en/admin/config.rst	Fri Jul 01 12:48:39 2011 +0200
@@ -190,6 +190,21 @@
   db-encoding=utf8
 
 
+You need to change the default settings on the database by running::
+
+ ALTER DATABASE <databasename> SET READ_COMMITTED_SNAPSHOT ON;
+
+The ALTER DATABASE command above requires some permissions that your
+user may not have. In that case you will have to ask your local DBA to
+run the query for you. 
+
+You can check that the setting is correct by running the following
+query which must return '1'::
+
+   SELECT is_read_committed_snapshot_on 
+     FROM sys.databases WHERE name='<databasename>';
+
+
 
 .. _SQLiteConfiguration:
 
--- a/server/test/unittest_rql2sql.py	Fri Jul 01 11:51:04 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Fri Jul 01 12:48:39 2011 +0200
@@ -210,6 +210,12 @@
 FROM cw_Personne AS _P
 LIMIT 20
 OFFSET 10'''),
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s",
+     '''SELECT _P.cw_eid
+FROM cw_Personne AS _P, travaille_relation AS rel_travaille0
+WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo
+ORDER BY _P.cw_nom
+LIMIT 1'''),
     ]
 
 
@@ -1243,7 +1249,7 @@
 
     def _check(self, rql, sql, varmap=None, args=None):
         if args is None:
-            args = {'text': 'hip hop momo'}
+            args = {'text': 'hip hop momo', 'eid': 12345}
         try:
             union = self._prepare(rql)
             r, nargs, cbs = self.o.generate(union, args,
@@ -1774,6 +1780,48 @@
 FROM cw_EmailAddress AS _O
 WHERE NOT (EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email0 WHERE rel_use_email0.eid_from=1 AND rel_use_email0.eid_to=_O.cw_eid)) AND EXISTS(SELECT 1 FROM use_email_relation AS rel_use_email1 WHERE rel_use_email1.eid_to=_O.cw_eid AND EXISTS(SELECT 1 FROM cw_CWGroup AS _D WHERE rel_use_email1.eid_from=2 AND NOT (EXISTS(SELECT 1 FROM in_group_relation AS rel_in_group2 WHERE rel_in_group2.eid_from=2 AND rel_in_group2.eid_to=_D.cw_eid)) AND _D.cw_name=guests))
 ORDER BY 4 DESC'''),
+
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P travaille S, S eid %(eid)s, P nom N, P nom %(text)s",
+     '''WITH orderedrows AS (
+SELECT
+_L01
+, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber
+FROM (
+SELECT _P.cw_eid AS _L01 FROM  cw_Personne AS _P, travaille_relation AS rel_travaille0
+WHERE rel_travaille0.eid_from=_P.cw_eid AND rel_travaille0.eid_to=12345 AND _P.cw_nom=hip hop momo
+) AS _SQ1 )
+SELECT
+_L01
+FROM orderedrows WHERE
+__RowNumber <= 1'''),
+
+    ("Any P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N",
+     '''WITH orderedrows AS (
+SELECT
+_L01
+, ROW_NUMBER() OVER (ORDER BY _L01) AS __RowNumber
+FROM (
+SELECT _P.cw_eid AS _L01 FROM  cw_Personne AS _P
+) AS _SQ1 )
+SELECT
+_L01
+FROM orderedrows WHERE
+__RowNumber <= 1
+'''),
+
+    ("Any PN, N, P ORDERBY N LIMIT 1 WHERE P is Personne, P nom N, P prenom PN",
+     '''WITH orderedrows AS (
+SELECT
+_L01, _L02, _L03
+, ROW_NUMBER() OVER (ORDER BY _L02) AS __RowNumber
+FROM (
+SELECT _P.cw_prenom AS _L01, _P.cw_nom AS _L02, _P.cw_eid AS _L03 FROM  cw_Personne AS _P
+) AS _SQ1 )
+SELECT
+_L01, _L02, _L03
+FROM orderedrows WHERE
+__RowNumber <= 1
+'''),
             ]
         for t in self._parse(WITH_LIMIT):# + ADVANCED_WITH_LIMIT_OR_ORDERBY):
             yield t
--- a/web/views/workflow.py	Fri Jul 01 11:51:04 2011 +0200
+++ b/web/views/workflow.py	Fri Jul 01 12:48:39 2011 +0200
@@ -39,7 +39,7 @@
 from cubicweb.web import uicfg, stdmsgs, action, component, form, action
 from cubicweb.web import formfields as ff, formwidgets as fwdgs
 from cubicweb.web.views import TmpFileViewMixin
-from cubicweb.web.views import forms, primary, autoform, ibreadcrumbs
+from cubicweb.web.views import forms, primary, ibreadcrumbs
 from cubicweb.web.views.tabs import TabbedPrimaryView, PrimaryTab
 from cubicweb.web.views.dotgraphview import DotGraphView, DotPropsHandler
 
@@ -72,11 +72,7 @@
 _abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
 
 _afs = uicfg.autoform_section
-_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
-_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
-_afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden')
-_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
-
+_affk = uicfg.autoform_field_kwargs
 
 # IWorkflowable views #########################################################
 
@@ -324,51 +320,56 @@
 
 # workflow entity types edition ################################################
 
-_afs = uicfg.autoform_section
+def _wf_items_for_relation(req, wfeid, wfrelation, field):
+    wf = req.entity_from_eid(wfeid)
+    rschema = req.vreg.schema[field.name]
+    param = 'toeid' if field.role == 'subject' else 'fromeid'
+    return sorted((e.view('combobox'), e.eid)
+                  for e in getattr(wf, 'reverse_%s' % wfrelation)
+                  if rschema.has_perm(req, 'add', **{param: e.eid}))
+
+# TrInfo
 _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')
-_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
+_afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden')
+
+# BaseTransition
+# XXX * allowed_transition BaseTransition
+# XXX BaseTransition destination_state *
+
+def transition_states_vocabulary(form, field):
+    entity = form.edited_entity
+    if not entity.has_eid():
+        eids = entity.linked_to('transition_of', 'subject')
+        if not eids:
+            return []
+        return _wf_items_for_relation(form._cw, eids[0], 'state_of', field)
+    return ff.relvoc_unrelated(entity, field.name, field.role)
 
-def workflow_items_for_relation(req, wfeid, wfrelation, targetrelation):
-    wf = req.entity_from_eid(wfeid)
-    rschema = req.vreg.schema[targetrelation]
-    return sorted((e.view('combobox'), e.eid)
-                  for e in getattr(wf, 'reverse_%s' % wfrelation)
-                  if rschema.has_perm(req, 'add', toeid=e.eid))
+_afs.tag_subject_of(('*', 'destination_state', '*'), 'main', 'attributes')
+_affk.tag_subject_of(('*', 'destination_state', '*'),
+                     {'choices': transition_states_vocabulary})
+_afs.tag_object_of(('*', 'allowed_transition', '*'), 'main', 'attributes')
+_affk.tag_object_of(('*', 'allowed_transition', '*'),
+                     {'choices': transition_states_vocabulary})
+
+# State
+
+def state_transitions_vocabulary(form, field):
+    entity = form.edited_entity
+    if not entity.has_eid():
+        eids = entity.linked_to('state_of', 'subject')
+        if eids:
+            return _wf_items_for_relation(form._cw, eids[0], 'transition_of', field)
+        return []
+    return ff.relvoc_unrelated(entity, field.name, field.role)
+
+_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
+_affk.tag_subject_of(('State', 'allowed_transition', '*'),
+                     {'choices': state_transitions_vocabulary})
 
 
-class TransitionEditionForm(autoform.AutomaticEntityForm):
-    __select__ = is_instance('Transition')
-
-    def workflow_states_for_relation(self, targetrelation):
-        eids = self.edited_entity.linked_to('transition_of', 'subject')
-        if eids:
-            return workflow_items_for_relation(self._cw, eids[0], 'state_of',
-                                               targetrelation)
-        return []
-
-    def subject_destination_state_vocabulary(self, rtype, limit=None):
-        if not self.edited_entity.has_eid():
-            return self.workflow_states_for_relation('destination_state')
-        return self.subject_relation_vocabulary(rtype, limit)
-
-    def object_allowed_transition_vocabulary(self, rtype, limit=None):
-        if not self.edited_entity.has_eid():
-            return self.workflow_states_for_relation('allowed_transition')
-        return self.object_relation_vocabulary(rtype, limit)
-
-
-class StateEditionForm(autoform.AutomaticEntityForm):
-    __select__ = is_instance('State')
-
-    def subject_allowed_transition_vocabulary(self, rtype, limit=None):
-        if not self.edited_entity.has_eid():
-            eids = self.edited_entity.linked_to('state_of', 'subject')
-            if eids:
-                return workflow_items_for_relation(self._cw, eids[0], 'transition_of',
-                                                   'allowed_transition')
-        return []
+# adaptaters ###################################################################
 
 class WorkflowIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
     __select__ = is_instance('Workflow')