merge stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 17 Nov 2009 11:48:36 +0100
branchstable
changeset 3871 983acb2b303b
parent 3870 a6b029aa0f44 (current diff)
parent 3868 161a5f7d1190 (diff)
child 3872 8b1b9179f100
child 3875 c2bd7922cdaf
merge
--- a/server/sources/rql2sql.py	Tue Nov 17 11:47:58 2009 +0100
+++ b/server/sources/rql2sql.py	Tue Nov 17 11:48:36 2009 +0100
@@ -171,8 +171,11 @@
             for invvar, vartype in invariants[id(sol)].iteritems():
                 sol[invvar] = vartype
         for sol in existssols:
-            for invvar, vartype in invariants[id(sol)].iteritems():
-                sol[invvar] = vartype
+            try:
+                for invvar, vartype in invariants[id(sol)].iteritems():
+                    sol[invvar] = vartype
+            except KeyError:
+                continue
     if len(newsols) > 1:
         if rewrite_unstable_outer_join(rqlst, newsols, unstable, schema):
             # remove variables extracted to subqueries from solutions
--- a/web/views/urlrewrite.py	Tue Nov 17 11:47:58 2009 +0100
+++ b/web/views/urlrewrite.py	Tue Nov 17 11:48:36 2009 +0100
@@ -149,7 +149,9 @@
 
 def rgx_action(rql=None, args=None, cachekey=None, argsgroups=(), setuser=False,
                form=None, formgroups=(), transforms={}, controller=None):
-    def do_build_rset(inputurl, uri, req, schema):
+    def do_build_rset(inputurl, uri, req, schema,
+                      cachekey=cachekey # necessary to avoid UnboundLocalError
+                      ):
         if rql:
             kwargs = args and args.copy() or {}
             if argsgroups:
@@ -162,7 +164,7 @@
                         kwargs[key] = transforms[key](value)
                     except KeyError:
                         kwargs[key] = value
-                    if key in cachekey:
+                    if cachekey is not None and key in cachekey:
                         kwargs[key] = typed_eid(value)
             if setuser:
                 kwargs['u'] = req.user.eid
--- a/web/views/workflow.py	Tue Nov 17 11:47:58 2009 +0100
+++ b/web/views/workflow.py	Tue Nov 17 11:48:36 2009 +0100
@@ -16,32 +16,14 @@
 
 from cubicweb import Unauthorized, view
 from cubicweb.selectors import (implements, has_related_entities, one_line_rset,
-                                relation_possible, match_form_params)
+                                relation_possible, match_form_params,
+                                entity_implements)
 from cubicweb.interfaces import IWorkflowable
 from cubicweb.view import EntityView
 from cubicweb.schema import display_name
 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, forms, primary
-
-_pvs = uicfg.primaryview_section
-_pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden')
-_pvs.tag_object_of(('*', 'state_of', 'Workflow'), 'hidden')
-_pvs.tag_object_of(('*', 'transition_of', 'Workflow'), 'hidden')
-
-_abaa = uicfg.actionbox_appearsin_addmenu
-_abaa.tag_subject_of(('BaseTransition', 'condition', 'RQLExpression'), False)
-_abaa.tag_subject_of(('State', 'allowed_transition', 'BaseTransition'), False)
-_abaa.tag_object_of(('SubWorkflowExitPoint', 'destination_state', 'State'),
-                    False)
-_abaa.tag_object_of(('State', 'state_of', 'Workflow'), True)
-_abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True)
-_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')
+from cubicweb.web.views import TmpFileViewMixin, forms, primary, autoform
 
 
 # IWorkflowable views #########################################################
@@ -170,6 +152,31 @@
 
 # workflow entity types views ##################################################
 
+_pvs = uicfg.primaryview_section
+_pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden')
+_pvs.tag_object_of(('*', 'state_of', 'Workflow'), 'hidden')
+_pvs.tag_object_of(('*', 'transition_of', 'Workflow'), 'hidden')
+
+_abaa = uicfg.actionbox_appearsin_addmenu
+_abaa.tag_subject_of(('BaseTransition', 'condition', 'RQLExpression'), False)
+_abaa.tag_subject_of(('State', 'allowed_transition', 'BaseTransition'), False)
+_abaa.tag_object_of(('SubWorkflowExitPoint', 'destination_state', 'State'),
+                    False)
+_abaa.tag_object_of(('State', 'state_of', 'Workflow'), True)
+_abaa.tag_object_of(('BaseTransition', 'transition_of', 'Workflow'), False)
+_abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True)
+_abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
+
+class WorkflowPrimaryView(primary.PrimaryView):
+    __select__ = implements('Workflow')
+
+    def render_entity_attributes(self, entity):
+        self.w(entity.view('reledit', rtype='description'))
+        self.w(u'<img src="%s" alt="%s"/>' % (
+            xml_escape(entity.absolute_url(vid='wfgraph')),
+            xml_escape(self.req._('graphical workflow for %s') % entity.name)))
+
+
 class CellView(view.EntityView):
     id = 'cell'
     __select__ = implements('TrInfo')
@@ -188,14 +195,53 @@
                                      row=row, col=col)))
 
 
-class WorkflowPrimaryView(primary.PrimaryView):
-    __select__ = implements('Workflow')
+# workflow entity types edition ################################################
+
+_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(('State', 'allowed_transition', '*'), 'primary')
+
+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))
+
+
+class TransitionEditionForm(autoform.AutomaticEntityForm):
+    __select__ = entity_implements('Transition')
 
-    def render_entity_attributes(self, entity):
-        self.w(entity.view('reledit', rtype='description'))
-        self.w(u'<img src="%s" alt="%s"/>' % (
-            xml_escape(entity.absolute_url(vid='wfgraph')),
-            xml_escape(self.req._('graphical workflow for %s') % entity.name)))
+    def workflow_states_for_relation(self, targetrelation):
+        eids = self.edited_entity.linked_to('transition_of', 'subject')
+        if eids:
+            return workflow_items_for_relation(self.req, 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.subject_relation_vocabulary(rtype, limit)
+
+
+class StateEditionForm(autoform.AutomaticEntityForm):
+    __select__ = entity_implements('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.req, eids[0], 'transition_of',
+                                                   'allowed_transition')
+        return []
 
 
 # workflow images ##############################################################