web/views/workflow.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 01 Dec 2009 08:43:37 +0100
branchstable
changeset 3953 19aefd78f61b
parent 3948 24a25b676671
child 3957 4a71754bf5eb
permissions -rw-r--r--
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None) to fix a pitfall in form_render prototype: there is no way to distinguish between arguments that should be given to build_context from arguments that should be given to the renderer. This was problematic for instance with inlined form where a 'title' argument is given for the renderer, but is also used as default value for field whose name is 'title'...
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
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    28
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    29
# IWorkflowable views #########################################################
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    30
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    31
class ChangeStateForm(forms.CompositeEntityForm):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    32
    id = 'changestate'
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    33
1995
ec95eaa2b711 turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    34
    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
    35
    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
    36
                    fwdgs.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    37
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    38
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    39
class ChangeStateFormView(form.FormViewMixIn, view.EntityView):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    40
    id = 'statuschange'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    41
    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
    42
    __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
    43
                  & match_form_params('treid'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    45
    def cell_call(self, row, col):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
    46
        entity = self.rset.get_entity(row, col)
2680
66472d85d548 [R] use req.entity_from_eid
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2506
diff changeset
    47
        transition = self.req.entity_from_eid(self.req.form['treid'])
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    48
        form = self.get_form(entity, transition)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    49
        self.w(form.error_message())
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    50
        self.w(u'<h4>%s %s</h4>\n' % (self.req._(transition.name),
1305
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
    51
                                      entity.view('oneline')))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    52
        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
    53
            'st1': entity.printable_state,
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    54
            'st2': self.req._(transition.destination().name)}
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    55
        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
    56
        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
    57
                                           by_transition=transition.eid)))
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    58
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    59
    def redirectpath(self, entity):
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    60
        return entity.rest_path()
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    61
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    62
    def get_form(self, entity, transition, **kwargs):
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    63
        # 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
    64
        # selector (and not entity_implements) is used on custom form
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    65
        form = self.vreg['forms'].select(
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    66
            'changestate', self.req, entity=entity, transition=transition,
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    67
            redirect_path=self.redirectpath(entity), **kwargs)
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    68
        trinfo = self.vreg['etypes'].etype_class('TrInfo')(self.req)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    69
        self.initialize_varmaker()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    70
        trinfo.eid = self.varmaker.next()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    71
        subform = self.vreg['forms'].select('edition', self.req, entity=trinfo,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    72
                                            mainform=False)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2726
diff changeset
    73
        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
    74
        form.add_subform(subform)
3920
366b30a6f9f6 refactor to ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3868
diff changeset
    75
        return form
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    76
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    77
2440
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
    78
class WFHistoryView(EntityView):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    79
    id = '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
    80
    __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
    81
                 score_entity(lambda x: x.workflow_history)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    82
    title = _('Workflow history')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    83
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    84
    def cell_call(self, row, col, view=None):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    85
        _ = self.req._
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    86
        eid = self.rset[row][col]
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    87
        sel = 'Any FS,TS,WF,D'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    88
        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
    89
              '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
    90
              'WF creation_date D'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
    91
        if self.vreg.schema.eschema('CWUser').has_perm(self.req, 'read'):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    92
            sel += ',U,C'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    93
            rql += ', WF owned_by U?'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    94
            displaycols = range(5)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    95
            headers = (_('from_state'), _('to_state'), _('comment'), _('date'),
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    96
                       _('CWUser'))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    97
        else:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    98
            sel += ',C'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    99
            displaycols = range(4)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   100
            headers = (_('from_state'), _('to_state'), _('comment'), _('date'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   101
        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
   102
        try:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   103
            rset = self.req.execute(rql, {'x': eid}, 'x')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   104
        except Unauthorized:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   105
            return
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   106
        if rset:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   107
            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
   108
                       displaycols=displaycols, headers=headers)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   109
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   110
2440
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   111
class WFHistoryVComponent(component.EntityVComponent):
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   112
    """display the workflow history for entities supporting it"""
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   113
    id = 'wfhistory'
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   114
    __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
   115
    context = 'navcontentbottom'
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   116
    title = _('Workflow history')
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   117
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   118
    def cell_call(self, row, col, view=None):
8e6b83e3b6b5 #343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2438
diff changeset
   119
        self.wview('wfhistory', self.rset, row=row, col=col, view=view)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   120
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   121
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   122
# workflow actions #############################################################
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   123
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   124
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
   125
    """fill 'workflow' sub-menu of the actions box"""
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   126
    id = 'workflow'
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   127
    __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
   128
                  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
   129
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   130
    submenu = _('workflow')
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   131
    order = 10
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   132
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   133
    def fill_menu(self, box, menu):
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   134
        entity = self.rset.get_entity(self.row or 0, self.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
   135
        menu.label = u'%s: %s' % (self.req._('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
   136
        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
   137
        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
   138
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
   139
    def actual_actions(self):
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
   140
        entity = self.rset.get_entity(self.row or 0, self.col or 0)
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
   141
        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
   142
        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
   143
            url = entity.absolute_url(vid='statuschange', treid=tr.eid)
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
   144
            yield self.build_action(self.req._(tr.name), url)
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
   145
            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
   146
        # 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
   147
        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
   148
            wfurl = entity.current_workflow.absolute_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
   149
            yield self.build_action(self.req._('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
   150
        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
   151
            wfurl = entity.absolute_url(vid='wfhistory')
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
   152
            yield self.build_action(self.req._('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
   153
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   154
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3216
diff changeset
   155
# workflow entity types views ##################################################
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   156
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
   157
_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
   158
_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
   159
_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
   160
_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
   161
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   162
_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
   163
_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
   164
_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
   165
_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
   166
                    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
   167
_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
   168
_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
   169
_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
   170
_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
   171
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   172
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
   173
    __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
   174
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   175
    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
   176
        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
   177
        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
   178
            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
   179
            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
   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
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   182
class CellView(view.EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
    id = 'cell'
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 688
diff changeset
   184
    __select__ = implements('TrInfo')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   185
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
    def cell_call(self, row, col, cellvid=None):
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   187
        self.w(self.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
   188
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   189
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   190
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
   191
    """convenience trick, State's incontext view should not be clickable"""
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   192
    id = 'incontext'
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   193
    __select__ = implements('State')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   194
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   195
    def cell_call(self, row, col):
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2005
diff changeset
   196
        self.w(xml_escape(self.view('textincontext', self.rset,
795
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   197
                                     row=row, col=col)))
63f4f81e19f1 restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 728
diff changeset
   198
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   199
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
   200
# 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
   201
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   202
_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
   203
_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
   204
_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
   205
_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
   206
_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
   207
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   208
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
   209
    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
   210
    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
   211
    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
   212
                  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
   213
                  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
   214
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   215
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   216
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
   217
    __select__ = entity_implements('Transition')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   218
3868
161a5f7d1190 oops, fix wf entity types vocabulary while in creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3867
diff changeset
   219
    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
   220
        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
   221
        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
   222
            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
   223
                                               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
   224
        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
   225
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
    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
   227
        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
   228
            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
   229
        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
   230
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
    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
   232
        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
   233
            return self.workflow_states_for_relation('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
   234
        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
   235
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
06ac8f00a99f fix vocabulary for destination_state/allowed_transitions when creating state or transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3805
diff changeset
   237
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
   238
    __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
   239
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
    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
   241
        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
   242
            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
   243
            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
   244
                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
   245
                                                   '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
   246
        return []
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   247
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   248
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
   249
# workflow images ##############################################################
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   250
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   251
class WorkflowDotPropsHandler(object):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   252
    def __init__(self, req):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   253
        self._ = req._
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   254
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   255
    def node_properties(self, stateortransition):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   256
        """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
   257
        props = {'label': stateortransition.printable_value('name'),
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   258
                 'fontname': 'Courier'}
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   259
        if hasattr(stateortransition, 'state_of'):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   260
            props['shape'] = 'box'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   261
            props['style'] = 'filled'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   262
            if stateortransition.reverse_initial_state:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   263
                props['color'] = '#88CC88'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   264
        else:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   265
            props['shape'] = 'ellipse'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   266
            descr = []
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   267
            tr = stateortransition
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   268
            if tr.require_group:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   269
                descr.append('%s %s'% (
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   270
                    self._('groups:'),
3307
d1230b89d887 [wf graph] translate group names as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3306
diff changeset
   271
                    ','.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
   272
            if tr.condition:
3216
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   273
                descr.append('%s %s'% (
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   274
                    self._('condition:'),
4a006fce6023 [wf graph] fix display of condition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3215
diff changeset
   275
                    ' | '.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
   276
            if descr:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   277
                props['label'] += escape('\n'.join(descr))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   278
        return props
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   279
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   280
    def edge_properties(self, transition, fromstate, tostate):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   281
        return {'label': '', 'dir': 'forward',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   282
                'color': 'black', 'style': 'filled'}
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   283
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   284
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   285
class WorkflowVisitor:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   286
    def __init__(self, entity):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   287
        self.entity = entity
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   288
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   289
    def nodes(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   290
        for state in self.entity.reverse_state_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   291
            state.complete()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   292
            yield state.eid, state
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   293
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   294
        for transition in self.entity.reverse_transition_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   295
            transition.complete()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   296
            yield transition.eid, transition
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   297
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   298
    def edges(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   299
        for transition in self.entity.reverse_transition_of:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   300
            for incomingstate in transition.reverse_allowed_transition:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   301
                yield incomingstate.eid, transition.eid, transition
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   302
            yield transition.eid, transition.destination().eid, transition
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
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
   305
class WorkflowImageView(TmpFileViewMixin, view.EntityView):
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
   306
    id = 'wfgraph'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   307
    content_type = 'image/png'
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
   308
    __select__ = implements('Workflow')
1504
c6051f141807 register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   309
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   310
    def _generate(self, tmpfile):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   311
        """display schema information for an entity"""
3220
11b6016e3970 cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3219
diff changeset
   312
        entity = self.rset.get_entity(self.row, self.col)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   313
        visitor = WorkflowVisitor(entity)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   314
        prophdlr = WorkflowDotPropsHandler(self.req)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   315
        generator = GraphGenerator(DotBackend('workflow', 'LR',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   316
                                              ratio='compress', size='30,12'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   317
        return generator.generate(visitor, prophdlr, tmpfile)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 984
diff changeset
   318