web/views/workflow.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 Dec 2009 17:17:43 +0100
changeset 3998 94cc7cad3d2d
parent 3890 d7a270f50f54
parent 3957 4a71754bf5eb
child 4004 c52619c738a5
permissions -rw-r--r--
backport stable into default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
     1
"""workflow views:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
     2
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
     3
* IWorkflowable views and forms
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
     4
* workflow entities views (State, Transition, TrInfo)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
:organization: Logilab
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1739
diff changeset
     7
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1739
diff changeset
     9
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
__docformat__ = "restructuredtext en"
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1721
diff changeset
    12
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2005
diff changeset
    14
from logilab.mtconverter import xml_escape
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    15
from logilab.common.graph import escape, GraphGenerator, DotBackend
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 795
diff changeset
    16
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    17
from cubicweb import Unauthorized, view
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
    18
from cubicweb.selectors import (implements, has_related_entities, one_line_rset,
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
    19
                                relation_possible, match_form_params,
3948
24a25b676671 make wfhistory non selectable for entities without record in its workflow history
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3920
diff changeset
    20
                                entity_implements, score_entity)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    21
from cubicweb.interfaces import IWorkflowable
2438
576f4d51f826 [cleanup] fix deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2381
diff changeset
    22
from cubicweb.view import EntityView
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    23
from cubicweb.schema import display_name
3262
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    24
from cubicweb.web import uicfg, stdmsgs, action, component, form, action
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    25
from cubicweb.web import formfields as ff, formwidgets as fwdgs
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
    26
from cubicweb.web.views import TmpFileViewMixin, forms, primary, autoform
3306
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    27
3487
2e705d9fdaf1 [views] workflow primary view: do not show states and transitions in side boxes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3350
diff changeset
    28
_pvs = uicfg.primaryview_section
2e705d9fdaf1 [views] workflow primary view: do not show states and transitions in side boxes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3350
diff changeset
    29
_pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden')
2e705d9fdaf1 [views] workflow primary view: do not show states and transitions in side boxes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3350
diff changeset
    30
_pvs.tag_object_of(('*', 'state_of', 'Workflow'), 'hidden')
2e705d9fdaf1 [views] workflow primary view: do not show states and transitions in side boxes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3350
diff changeset
    31
_pvs.tag_object_of(('*', 'transition_of', 'Workflow'), 'hidden')
2e705d9fdaf1 [views] workflow primary view: do not show states and transitions in side boxes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3350
diff changeset
    32
3262
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    33
_abaa = uicfg.actionbox_appearsin_addmenu
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    34
_abaa.tag_subject_of(('BaseTransition', 'condition', 'RQLExpression'), False)
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    35
_abaa.tag_subject_of(('State', 'allowed_transition', 'BaseTransition'), False)
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    36
_abaa.tag_object_of(('SubWorkflowExitPoint', 'destination_state', 'State'),
12ffb1e95771 uicfg tweaks for wf
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3228
diff changeset
    37
                    False)
3306
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    38
_abaa.tag_object_of(('State', 'state_of', 'Workflow'), True)
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    39
_abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True)
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    40
_abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    41
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    42
_afs = uicfg.autoform_section
3659
993997b4b41d 3.6 update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3524
diff changeset
    43
_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
993997b4b41d 3.6 update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3524
diff changeset
    44
_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
993997b4b41d 3.6 update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3524
diff changeset
    45
_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
3306
bf50dc056edd [wf] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3304
diff changeset
    46
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    47
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    48
# IWorkflowable views #########################################################
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    49
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    50
class ChangeStateForm(forms.CompositeEntityForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    51
    __regid__ = 'changestate'
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    52
1995
ec95eaa2b711 turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    53
    form_renderer_id = 'base' # don't want EntityFormRenderer
3805
ad0b38e1a4eb [web ui] rename form buttons to ok/cancel where workflow change state
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3513
diff changeset
    54
    form_buttons = [fwdgs.SubmitButton(),
ad0b38e1a4eb [web ui] rename form buttons to ok/cancel where workflow change state
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3513
diff changeset
    55
                    fwdgs.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    56
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    57
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    58
class ChangeStateFormView(form.FormViewMixIn, view.EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    59
    __regid__ = 'statuschange'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    60
    title = _('status change')
3335
3c035436ca65 statuschange form view only works w/ one entity, fix selector accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3307
diff changeset
    61
    __select__ = (one_line_rset() & implements(IWorkflowable)
3c035436ca65 statuschange form view only works w/ one entity, fix selector accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3307
diff changeset
    62
                  & match_form_params('treid'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    64
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    65
        entity = self.cw_rset.get_entity(row, col)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    66
        transition = self._cw.entity_from_eid(self._cw.form['treid'])
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    67
        form = self.get_form(entity, transition)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    68
        self.w(form.error_message())
3998
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890 3957
diff changeset
    69
        self.w(u'<h4>%s %s</h4>\n' % (self._cw._(transition.name),
1305
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
    70
                                      entity.view('oneline')))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    71
        msg = _('status will change from %(st1)s to %(st2)s') % {
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    72
            'st1': entity.printable_state,
3998
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890 3957
diff changeset
    73
            'st2': self._cw._(transition.destination().name)}
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    74
        self.w(u'<p>%s</p>\n' % msg)
3953
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3948
diff changeset
    75
        self.w(form.render(formvalues=dict(wf_info_for=entity.eid,
19aefd78f61b [forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3948
diff changeset
    76
                                           by_transition=transition.eid)))
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    77
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    78
    def redirectpath(self, entity):
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    79
        return entity.rest_path()
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    80
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    81
    def get_form(self, entity, transition, **kwargs):
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    82
        # XXX used to specify both rset/row/col and entity in case implements
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    83
        # selector (and not entity_implements) is used on custom form
3998
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890 3957
diff changeset
    84
        form = self._cw.vreg['forms'].select(
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890 3957
diff changeset
    85
            'changestate', self._cw, entity=entity, transition=transition,
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    86
            redirect_path=self.redirectpath(entity), **kwargs)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    87
        trinfo = self._cw.vreg['etypes'].etype_class('TrInfo')(self._cw)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    88
        trinfo.eid = self._cw.varmaker.next()
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    89
        subform = self._cw.vreg['forms'].select('edition', self._cw, entity=trinfo,
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    90
                                            mainform=False)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    91
        subform.field_by_name('by_transition').widget = fwdgs.HiddenInput()
3513
c002f6488631 [form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3487
diff changeset
    92
        form.add_subform(subform)
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    93
        return form
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    94
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    95
2440
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
    96
class WFHistoryView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    97
    __regid__ = 'wfhistory'
3948
24a25b676671 make wfhistory non selectable for entities without record in its workflow history
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3920
diff changeset
    98
    __select__ = relation_possible('wf_info_for', role='object') & \
24a25b676671 make wfhistory non selectable for entities without record in its workflow history
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3920
diff changeset
    99
                 score_entity(lambda x: x.workflow_history)
3998
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890 3957
diff changeset
   100
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   101
    title = _('Workflow history')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   102
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   103
    def cell_call(self, row, col, view=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   104
        _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   105
        eid = self.cw_rset[row][col]
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   106
        sel = 'Any FS,TS,WF,D'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   107
        rql = ' ORDERBY D DESC WHERE WF wf_info_for X,'\
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   108
              'WF from_state FS, WF to_state TS, WF comment C,'\
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   109
              'WF creation_date D'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   110
        if self._cw.vreg.schema.eschema('CWUser').has_perm(self._cw, 'read'):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   111
            sel += ',U,C'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   112
            rql += ', WF owned_by U?'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   113
            displaycols = range(5)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   114
            headers = (_('from_state'), _('to_state'), _('comment'), _('date'),
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   115
                       _('CWUser'))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   116
        else:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   117
            sel += ',C'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   118
            displaycols = range(4)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   119
            headers = (_('from_state'), _('to_state'), _('comment'), _('date'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   120
        rql = '%s %s, X eid %%(x)s' % (sel, rql)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   121
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   122
            rset = self._cw.execute(rql, {'x': eid}, 'x')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   123
        except Unauthorized:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   124
            return
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   125
        if rset:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   126
            self.wview('table', rset, title=_(self.title), displayactions=False,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   127
                       displaycols=displaycols, headers=headers)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   128
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   129
2440
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   130
class WFHistoryVComponent(component.EntityVComponent):
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   131
    """display the workflow history for entities supporting it"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   132
    __regid__ = 'wfhistory'
2440
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   133
    __select__ = WFHistoryView.__select__ & component.EntityVComponent.__select__
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   134
    context = 'navcontentbottom'
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   135
    title = _('Workflow history')
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   136
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   137
    def cell_call(self, row, col, view=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   138
        self.wview('wfhistory', self.cw_rset, row=row, col=col, view=view)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   139
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   140
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   141
# workflow actions #############################################################
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   142
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   143
class WorkflowActions(action.Action):
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   144
    """fill 'workflow' sub-menu of the actions box"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   145
    __regid__ = 'workflow'
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   146
    __select__ = (action.Action.__select__ & one_line_rset() &
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   147
                  relation_possible('in_state'))
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   148
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   149
    submenu = _('workflow')
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   150
    order = 10
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   151
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   152
    def fill_menu(self, box, menu):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   153
        entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   154
        menu.label = u'%s: %s' % (self._cw._('state'), entity.printable_state)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   155
        menu.append_anyway = True
3228
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   156
        super(WorkflowActions, self).fill_menu(box, menu)
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   157
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   158
    def actual_actions(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   159
        entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
3228
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   160
        hastr = False
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   161
        for tr in entity.possible_transitions():
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   162
            url = entity.absolute_url(vid='statuschange', treid=tr.eid)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   163
            yield self.build_action(self._cw._(tr.name), url)
3228
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   164
            hastr = True
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   165
        # don't propose to see wf if user can't pass any transition
3228
7b05b2709439 [actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3220
diff changeset
   166
        if hastr:
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   167
            wfurl = entity.current_workflow.absolute_url()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   168
            yield self.build_action(self._cw._('view workflow'), wfurl)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   169
        if entity.workflow_history:
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   170
            wfurl = entity.absolute_url(vid='wfhistory')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   171
            yield self.build_action(self._cw._('view history'), wfurl)
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   172
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   173
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   174
# workflow entity types views ##################################################
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   175
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   176
_pvs = uicfg.primaryview_section
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   177
_pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   178
_pvs.tag_object_of(('*', 'state_of', 'Workflow'), 'hidden')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   179
_pvs.tag_object_of(('*', 'transition_of', 'Workflow'), 'hidden')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   180
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   181
_abaa = uicfg.actionbox_appearsin_addmenu
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   182
_abaa.tag_subject_of(('BaseTransition', 'condition', 'RQLExpression'), False)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   183
_abaa.tag_subject_of(('State', 'allowed_transition', 'BaseTransition'), False)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   184
_abaa.tag_object_of(('SubWorkflowExitPoint', 'destination_state', 'State'),
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   185
                    False)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   186
_abaa.tag_object_of(('State', 'state_of', 'Workflow'), True)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   187
_abaa.tag_object_of(('BaseTransition', 'transition_of', 'Workflow'), False)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   188
_abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   189
_abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   190
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   191
class WorkflowPrimaryView(primary.PrimaryView):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   192
    __select__ = implements('Workflow')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   193
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   194
    def render_entity_attributes(self, entity):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   195
        self.w(entity.view('reledit', rtype='description'))
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   196
        self.w(u'<img src="%s" alt="%s"/>' % (
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   197
            xml_escape(entity.absolute_url(vid='wfgraph')),
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   198
            xml_escape(self.req._('graphical workflow for %s') % entity.name)))
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   199
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   200
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   201
class CellView(view.EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   202
    __regid__ = 'cell'
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 688
diff changeset
   203
    __select__ = implements('TrInfo')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   204
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
    def cell_call(self, row, col, cellvid=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   206
        self.w(self.cw_rset.get_entity(row, col).view('reledit', rtype='comment'))
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   207
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   208
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   209
class StateInContextView(view.EntityView):
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   210
    """convenience trick, State's incontext view should not be clickable"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   211
    __regid__ = 'incontext'
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   212
    __select__ = implements('State')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   213
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   214
    def cell_call(self, row, col):
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   215
        self.w(xml_escape(self._cw.view('textincontext', self.cw_rset,
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   216
                                        row=row, col=col)))
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   217
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   218
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   219
# workflow entity types edition ################################################
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   220
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   221
_afs = uicfg.autoform_section
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   222
_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'generated')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   223
_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'generated')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   224
_afs.tag_object_of(('State', 'allowed_transition', '*'), 'primary')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   225
_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'primary')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   226
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   227
def workflow_items_for_relation(req, wfeid, wfrelation, targetrelation):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   228
    wf = req.entity_from_eid(wfeid)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   229
    rschema = req.vreg.schema[targetrelation]
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   230
    return sorted((e.view('combobox'), e.eid)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   231
                  for e in getattr(wf, 'reverse_%s' % wfrelation)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   232
                  if rschema.has_perm(req, 'add', toeid=e.eid))
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   233
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   234
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   235
class TransitionEditionForm(autoform.AutomaticEntityForm):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   236
    __select__ = entity_implements('Transition')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   237
3868
161a5f7d1190 oops, fix wf entity types vocabulary while in creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3867
diff changeset
   238
    def workflow_states_for_relation(self, targetrelation):
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   239
        eids = self.edited_entity.linked_to('transition_of', 'subject')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   240
        if eids:
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   241
            return workflow_items_for_relation(self.req, eids[0], 'state_of',
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   242
                                               targetrelation)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   243
        return []
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   244
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   245
    def subject_destination_state_vocabulary(self, rtype, limit=None):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   246
        if not self.edited_entity.has_eid():
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   247
            return self.workflow_states_for_relation('destination_state')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   248
        return self.subject_relation_vocabulary(rtype, limit)
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   249
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   250
    def object_allowed_transition_vocabulary(self, rtype, limit=None):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   251
        if not self.edited_entity.has_eid():
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   252
            return self.workflow_states_for_relation('allowed_transition')
3957
4a71754bf5eb oops, this is an object relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3953
diff changeset
   253
        return self.object_relation_vocabulary(rtype, limit)
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   254
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   255
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   256
class StateEditionForm(autoform.AutomaticEntityForm):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   257
    __select__ = entity_implements('State')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   258
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   259
    def subject_allowed_transition_vocabulary(self, rtype, limit=None):
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   260
        if not self.edited_entity.has_eid():
3868
161a5f7d1190 oops, fix wf entity types vocabulary while in creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3867
diff changeset
   261
            eids = self.edited_entity.linked_to('state_of', 'subject')
3867
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   262
            if eids:
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   263
                return workflow_items_for_relation(self.req, eids[0], 'transition_of',
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   264
                                                   'allowed_transition')
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   265
        return []
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   266
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   267
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   268
# workflow images ##############################################################
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   269
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   270
class WorkflowDotPropsHandler(object):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   271
    def __init__(self, req):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   272
        self._ = req._
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   273
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   274
    def node_properties(self, stateortransition):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   275
        """return default DOT drawing options for a state or transition"""
3304
2b18276b21ab [ui] translate state/tr names in wf image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3262
diff changeset
   276
        props = {'label': stateortransition.printable_value('name'),
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   277
                 'fontname': 'Courier'}
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   278
        if hasattr(stateortransition, 'state_of'):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   279
            props['shape'] = 'box'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   280
            props['style'] = 'filled'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   281
            if stateortransition.reverse_initial_state:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   282
                props['color'] = '#88CC88'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   283
        else:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   284
            props['shape'] = 'ellipse'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   285
            descr = []
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   286
            tr = stateortransition
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   287
            if tr.require_group:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   288
                descr.append('%s %s'% (
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   289
                    self._('groups:'),
3307
d1230b89d887 [wf graph] translate group names as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3306
diff changeset
   290
                    ','.join(g.printable_value('name') for g in tr.require_group)))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   291
            if tr.condition:
3216
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   292
                descr.append('%s %s'% (
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   293
                    self._('condition:'),
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   294
                    ' | '.join(e.expression for e in tr.condition)))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   295
            if descr:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   296
                props['label'] += escape('\n'.join(descr))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   297
        return props
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   298
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   299
    def edge_properties(self, transition, fromstate, tostate):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   300
        return {'label': '', 'dir': 'forward',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   301
                'color': 'black', 'style': 'filled'}
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   302
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   303
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   304
class WorkflowVisitor:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   305
    def __init__(self, entity):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   306
        self.entity = entity
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   307
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   308
    def nodes(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   309
        for state in self.entity.reverse_state_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   310
            state.complete()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   311
            yield state.eid, state
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   312
        for transition in self.entity.reverse_transition_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   313
            transition.complete()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   314
            yield transition.eid, transition
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   315
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   316
    def edges(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   317
        for transition in self.entity.reverse_transition_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   318
            for incomingstate in transition.reverse_allowed_transition:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   319
                yield incomingstate.eid, transition.eid, transition
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   320
            yield transition.eid, transition.destination().eid, transition
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   321
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   322
3215
bf30ab5ba6ee fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   323
class WorkflowImageView(TmpFileViewMixin, view.EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   324
    __regid__ = 'wfgraph'
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   325
    __select__ = implements('Workflow')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   326
    content_type = 'image/png'
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   327
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   328
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   329
        """display schema information for an entity"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   330
        entity = self.cw_rset.get_entity(self.cw_row, self.cw_col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   331
        visitor = WorkflowVisitor(entity)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   332
        prophdlr = WorkflowDotPropsHandler(self._cw)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   333
        generator = GraphGenerator(DotBackend('workflow', 'LR',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   334
                                              ratio='compress', size='30,12'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   335
        return generator.generate(visitor, prophdlr, tmpfile)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   336