web/action.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 12 Feb 2014 17:32:49 +0100
changeset 9534 34d9de030564
parent 8190 2a3c1b787688
child 9567 b87c09f853d3
permissions -rw-r--r--
[web/data] Ignore disabled widgets in cw.utils.formContents() (closes #3544492) 17.12.1 Disabled controls : http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.12.1 When set, the disabled attribute has the following effects on an element: * Disabled controls do not receive focus. * Disabled controls are skipped in tabbing navigation. * Disabled controls cannot be successful. The third one is the important one. 17.13.2 Successful controls : http://www.w3.org/TR/REC-html40/interact/forms.html#successful-controls A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. Bottom line, disable widgets should not be part of the names and values lists returned by formContents().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7793
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    18
"""abstract action classes for CubicWeb web client
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    19
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    20
Actions are typically displayed in an action box, but can also be used
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    21
in other parts of the interface (the user menu, the footer, etc.). The
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    22
'order', 'category' and 'title' class attributes control how the action will
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    23
be displayed. The 'submenu' attribute is only used for actions in the
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    24
action box.
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    25
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    26
The most important method from a developper point of view in the
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    27
:meth:'Action.url' method, which returns a URL on which the navigation
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    28
should directed to perform the action.  There are two common ways of
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    29
writing that method:
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    30
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    31
* do nothing special and simply return a URL to the current rset with
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    32
  a special view (with `self._cw.build_url(...)` for instance)
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    33
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    34
* define an inner function `callback_func(req, *args)` which will do
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    35
  the work and call it through `self._cw.user_callback(callback_func,
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    36
  args, msg)`: this method will return a URL which calls the inner
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    37
  function, and displays the message in the web interface when the
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    38
  callback has completed (and report any exception occuring in the
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    39
  callback too)
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    40
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    41
Many examples of the first approach are available in :mod:`cubicweb.web.views.actions`.
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    42
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    43
Here is an example of the second approach:
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    44
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    45
.. sourcecode:: python
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    46
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    47
 from cubicweb.web import action
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    48
 class SomeAction(action.Action):
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    49
     __regid__ = 'mycube_some_action'
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    50
     title = _(some action)
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    51
     __select__ = action.Action.__select__ & is_instance('TargetEntity')
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    52
 
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    53
     def url(self):
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    54
         if self.cw_row is None:
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    55
             eids = [row[0] for row in self.cw_rset]
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    56
         else:
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    57
             eids = (self.cw_rset[self.cw_row][self.cw_col or 0],)
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    58
         def do_action(req, eids):
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    59
             for eid in eids:
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    60
                 entity = req.entity_from_eid(eid, 'TargetEntity')
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    61
                 entity.perform_action()
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    62
         msg = self._cw._('some_action performed')
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    63
         return self._cw.user_callback(do_action, (eids,), msg)
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    64
8a330017ca4d [doc] add some documentation in cubicweb.web.action
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6800
diff changeset
    65
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
__docformat__ = "restructuredtext en"
2698
a6ef9bec755e cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
    68
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
782
01801a10c567 introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 768
diff changeset
    70
from cubicweb import target
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
    71
from cubicweb.predicates import (partial_relation_possible, match_search_state,
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
    72
                                 one_line_rset)
2656
a93ae0f6c0ad R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    73
from cubicweb.appobject import AppObject
653
189877d9547d use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents: 652
diff changeset
    74
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
2656
a93ae0f6c0ad R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    76
class Action(AppObject):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
    """abstract action. Handle the .search_states attribute to match
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    78
    request search state.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    __registry__ = 'actions'
1536
1e695b78d085 match normal search state on action by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    81
    __select__ = match_search_state('normal')
5246
3246b1f88a18 [web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    82
    order = 99
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    category = 'moreactions'
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2698
diff changeset
    84
    # actions in category 'moreactions' can specify a sub-menu in which they should be filed
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2698
diff changeset
    85
    submenu = None
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2698
diff changeset
    86
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
    87
    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
    88
        yield 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
    89
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2698
diff changeset
    90
    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: 2698
diff changeset
    91
        """add action(s) to the given submenu of the given box"""
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
    92
        for action in self.actual_actions():
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    93
            menu.append(box.action_link(action))
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    94
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    95
    def html_class(self):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    96
        if self._cw.selected(self.url()):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    97
            return 'selected'
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    98
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    99
    def build_action(self, title, url, **kwargs):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   100
        return UnregisteredAction(self._cw, title, url, **kwargs)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   101
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def url(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        """return the url associated with this action"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        raise NotImplementedError
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   105
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 254
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
class UnregisteredAction(Action):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   108
    """non registered action, used to build boxes"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    category = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    id = None
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   111
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   112
    def __init__(self, req, title, url, **kwargs):
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   113
        Action.__init__(self, req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        self.title = req._(title)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   115
        self._url = url
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        self.__dict__.update(kwargs)
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   117
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    def url(self):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   119
        return self._url
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
640
8e64f12be69c drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   122
class LinkToEntityAction(Action):
4462
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   123
    """base class for actions consisting to create a new object with an initial
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   124
    relation set to an entity.
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   125
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   126
    Additionaly to EntityAction behaviour, this class is parametrized using
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   127
    .rtype, .role and .target_etype attributes to check if the action apply and
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   128
    if the logged user has access to it (see
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   129
    :class:`~cubicweb.selectors.partial_relation_possible` selector
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   130
    documentation for more information).
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    """
782
01801a10c567 introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 768
diff changeset
   132
    __select__ = (match_search_state('normal') & one_line_rset()
4462
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   133
                  & partial_relation_possible(action='add', strict=True))
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   134
3219
be8cfc00ae04 edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2698
diff changeset
   135
    submenu = 'addrelated'
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   136
    # to be defined in concrete classes
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   137
    target_etype = rtype = None
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
   138
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
    def url(self):
7990
a673d1d9a738 [diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7879
diff changeset
   140
        ttype = self.target_etype
4462
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   141
        entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   142
        linkto = '%s:%s:%s' % (self.rtype, entity.eid, target(self))
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7793
diff changeset
   143
        return self._cw.vreg["etypes"].etype_class(ttype).cw_create_url(self._cw,
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7793
diff changeset
   144
                                  __redirectpath=entity.rest_path(), __linkto=linkto,
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   145
                                  __redirectvid=self._cw.form.get('__redirectvid', ''))
653
189877d9547d use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents: 652
diff changeset
   146