# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1238152980 -3600 # Node ID 96747df28a1f1c98fd72cd5bb4244f06f47df9f2 # Parent 7dac5aeafb86aaeb51fa06c65d1e80dc9d2199c2 backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one diff -r 7dac5aeafb86 -r 96747df28a1f common/mixins.py --- a/common/mixins.py Fri Mar 27 12:20:47 2009 +0100 +++ b/common/mixins.py Fri Mar 27 12:23:00 2009 +0100 @@ -7,6 +7,7 @@ """ __docformat__ = "restructuredtext en" +from logilab.common.deprecation import obsolete from logilab.common.decorators import cached from cubicweb.selectors import implements @@ -217,26 +218,6 @@ """return the latest transition information for this entity""" return self.reverse_wf_info_for[-1] - # specific vocabulary methods ############################################# - - def subject_in_state_vocabulary(self, rschema, limit=None): - """vocabulary method for the in_state relation, looking for - relation's object entities (i.e. self is the subject) according - to initial_state, state_of and next_state relation - """ - if not self.has_eid() or not self.in_state: - # get the initial state - rql = 'Any S where S state_of ET, ET name %(etype)s, ET initial_state S' - rset = self.req.execute(rql, {'etype': str(self.e_schema)}) - if rset: - return [(rset.get_entity(0, 0).view('combobox'), rset[0][0])] - return [] - results = [] - for tr in self.in_state[0].transitions(self): - state = tr.destination_state[0] - results.append((state.view('combobox'), state.eid)) - return sorted(results) - # __method methods ######################################################## def set_state(self, params=None): @@ -247,6 +228,13 @@ self.change_state(int(params.pop('state')), params.get('trcomment'), params.get('trcommentformat')) self.req.set_message(self.req._('__msg state changed')) + + # specific vocabulary methods ############################################# + + @obsolete('use EntityFieldsForm.object_relation_vocabulary') + def subject_in_state_vocabulary(self, rschema, limit=None): + from cubicweb.web.form import EntityFieldsForm + return EntityFieldsForm(entity=self).subject_in_state_vocabulary(rtype, limit) diff -r 7dac5aeafb86 -r 96747df28a1f web/form.py --- a/web/form.py Fri Mar 27 12:20:47 2009 +0100 +++ b/web/form.py Fri Mar 27 12:23:00 2009 +0100 @@ -556,6 +556,24 @@ res.append((entity.view('combobox'), entity.eid)) return res + def subject_in_state_vocabulary(self, rschema, limit=None): + """vocabulary method for the in_state relation, looking for + relation's object entities (i.e. self is the subject) according + to initial_state, state_of and next_state relation + """ + if not self.has_eid() or not self.in_state: + # get the initial state + rql = 'Any S where S state_of ET, ET name %(etype)s, ET initial_state S' + rset = self.req.execute(rql, {'etype': str(self.e_schema)}) + if rset: + return [(rset.get_entity(0, 0).view('combobox'), rset[0][0])] + return [] + results = [] + for tr in self.in_state[0].transitions(self): + state = tr.destination_state[0] + results.append((state.view('combobox'), state.eid)) + return sorted(results) + class CompositeForm(FieldsForm): """form composed for sub-forms"""