web/views/reledit.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 04 Oct 2010 18:56:05 +0200
changeset 6389 72ba82a26e05
parent 6329 918dd7448630
child 6582 8eb7883b4223
permissions -rw-r--r--
refactor login box & form to enable easy pluggability * vregistry.selectable: get all selectable object of fixed oid with given context * template headeri, logbox, logform: reorganize a bit the structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     3
#
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     4
# This file is part of CubicWeb.
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     5
#
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
     9
# any later version.
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    10
#
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    14
# details.
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    15
#
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    18
"""the 'reedit' feature (eg edit attribute/relation from primary view)
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    19
"""
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    20
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
import copy
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    22
from warnings import warn
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
from logilab.mtconverter import xml_escape
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    25
from logilab.common.deprecation import deprecated
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
from cubicweb import neg_role
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
from cubicweb.schema import display_name
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5878
diff changeset
    29
from cubicweb.utils import json_dumps
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
from cubicweb.selectors import non_final_entity, match_kwargs
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
from cubicweb.view import EntityView
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
from cubicweb.web import uicfg, stdmsgs
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    33
from cubicweb.web.form import FieldNotFound
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
from cubicweb.web.formwidgets import Button, SubmitButton
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    36
class _DummyForm(object):
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    37
    __slots__ = ('event_args',)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    38
    def form_render(self, **_args):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
        return u''
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
    def render(self, *_args, **_kwargs):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    41
        return u''
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    42
    def append_field(self, *args):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
        pass
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    44
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    45
rctrl = uicfg.reledit_ctrl
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    46
6110
7c419cbe9809 [views/reledit] fix bad role handling in _may_add_related
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5946
diff changeset
    47
class ClickAndEditFormView(EntityView):
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    48
    __regid__ = 'doreledit'
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    49
    __select__ = non_final_entity() & match_kwargs('rtype')
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    50
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    51
    # ui side continuations
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    52
    _onclick = (u"cw.reledit.loadInlineEditionForm('%(formid)s', %(eid)s, '%(rtype)s', '%(role)s', "
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    53
                "'%(divid)s', %(reload)s, '%(vid)s');")
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    54
    _cancelclick = "cw.reledit.cleanupAfterCancel('%s')"
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    55
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    56
    # ui side actions/buttons
5945
846d1fb32aa8 [web/views/reledit] explicitely add the field if the formid is base + line cleanups
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5878
diff changeset
    57
    _addzone = u'<img title="%(msg)s" src="data/plus.png" alt="%(msg)s"/>'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    58
    _addmsg = _('click to add a value')
5945
846d1fb32aa8 [web/views/reledit] explicitely add the field if the formid is base + line cleanups
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5878
diff changeset
    59
    _deletezone = u'<img title="%(msg)s" src="data/cancel.png" alt="%(msg)s"/>'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    60
    _deletemsg = _('click to delete this value')
5945
846d1fb32aa8 [web/views/reledit] explicitely add the field if the formid is base + line cleanups
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5878
diff changeset
    61
    _editzone = u'<img title="%(msg)s" src="data/pen_icon.png" alt="%(msg)s"/>'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    62
    _editzonemsg = _('click to edit this field')
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    63
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    64
    # renderer
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    65
    _form_renderer_id = 'base'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
    def cell_call(self, row, col, rtype=None, role='subject',
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
                  reload=False, # controls reloading the whole page after change
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    69
                                # boolean, eid (to redirect), or
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    70
                                # function taking the subject entity & returning a boolean or an eid
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    71
                  rvid=None,    # vid to be applied to other side of rtype (non final relations only)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    72
                  default_value=None,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    73
                  formid='base'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    74
                  ):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    75
        """display field to edit entity's `rtype` relation on click"""
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    76
        assert rtype
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    77
        assert role in ('subject', 'object'), '%s is not an acceptable role value' % role
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    78
        self._cw.add_css('cubicweb.form.css')
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    79
        self._cw.add_js('cubicweb.reledit.js', 'cubicweb.edition.js')
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    80
        entity = self.cw_rset.get_entity(row, col)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    81
        rschema = self._cw.vreg.schema[rtype]
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    82
        self._rules = rctrl.etype_get(entity.e_schema.type, rschema.type, role, '*')
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    83
        if rvid is not None or default_value is not None:
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    84
            warn('[3.9] specifying rvid/default_value on select is deprecated, '
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    85
                 'reledit_ctrl rtag to control this' % self, DeprecationWarning)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    86
        reload = self._compute_reload(entity, rschema, role, reload)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    87
        divid = self._build_divid(rtype, role, entity.eid)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    88
        if rschema.final:
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    89
            self._handle_attribute(entity, rschema, role, divid, reload)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    90
        else:
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    91
            if self._is_composite():
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    92
                self._handle_composite(entity, rschema, role, divid, reload, formid)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    93
            else:
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    94
                self._handle_relation(entity, rschema, role, divid, reload, formid)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    95
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
    96
    def _handle_attribute(self, entity, rschema, role, divid, reload):
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    97
        rtype = rschema.type
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
    98
        value = entity.printable_value(rtype)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
    99
        if not self._should_edit_attribute(entity, rschema):
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   100
            self.w(value)
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   101
            return
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   102
        display_label, related_entity = self._prepare_form(entity, rtype, role)
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   103
        form, renderer = self._build_form(entity, rtype, role, divid, 'base',
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   104
                                          reload, display_label, related_entity)
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   105
        value = value or self._compute_default_value(rschema, role)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   106
        self.view_form(divid, value, form, renderer)
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   107
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   108
    def _compute_formid_value(self, entity, rschema, role, rvid, formid):
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   109
        related_rset = entity.related(rschema.type, role)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   110
        if related_rset:
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   111
            value = self._cw.view(rvid, related_rset)
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   112
        else:
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   113
            value = self._compute_default_value(rschema, role)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   114
        if not self._should_edit_relation(entity, rschema, role):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   115
            return None, value
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   116
        return formid, value
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   117
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   118
    def _handle_relation(self, entity, rschema, role, divid, reload, formid):
6329
918dd7448630 [reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6289
diff changeset
   119
        rvid = self._rules.get('rvid', 'autolimited')
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   120
        formid, value = self._compute_formid_value(entity, rschema, role, rvid, formid)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   121
        if formid is None:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   122
            return self.w(value)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   123
        rtype = rschema.type
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   124
        display_label, related_entity = self._prepare_form(entity, rtype, role)
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   125
        form, renderer = self._build_form(entity, rtype, role, divid, formid, reload,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   126
                                          display_label, related_entity, dict(vid=rvid))
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   127
        self.view_form(divid, value, form, renderer)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   128
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   129
    def _handle_composite(self, entity, rschema, role, divid, reload, formid):
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   130
        # this is for attribute-like composites (1 target type, 1 related entity at most, for now)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   131
        ttypes = self._compute_ttypes(rschema, role)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   132
        related_rset = entity.related(rschema.type, role)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   133
        add_related = self._may_add_related(related_rset, entity, rschema, role, ttypes)
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   134
        edit_related = self._may_edit_related_entity(related_rset, entity, rschema, role, ttypes)
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   135
        delete_related = edit_related and self._may_delete_related(related_rset, entity, rschema, role)
6329
918dd7448630 [reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6289
diff changeset
   136
        rvid = self._rules.get('rvid', 'autolimited')
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   137
        formid, value = self._compute_formid_value(entity, rschema, role, rvid, formid)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   138
        if formid is None or not (edit_related or add_related):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   139
            # till we learn to handle cases where not (edit_related or add_related)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   140
            self.w(value)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   141
            return
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   142
        rtype = rschema.type
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   143
        ttype = ttypes[0]
6329
918dd7448630 [reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6289
diff changeset
   144
        _fdata = self._prepare_composite_form(entity, rtype, role, edit_related,
918dd7448630 [reledit] drop compute_best_vid method now useless
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6289
diff changeset
   145
                                              add_related and ttype)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   146
        display_label, related_entity = _fdata
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   147
        form, renderer = self._build_form(entity, rtype, role, divid, formid, reload,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   148
                                          display_label, related_entity, dict(vid=rvid))
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   149
        self.view_form(divid, value, form, renderer,
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   150
                       edit_related, add_related, delete_related)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   151
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   152
    def _compute_ttypes(self, rschema, role):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   153
        dual_role = neg_role(role)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   154
        return getattr(rschema, '%ss' % dual_role)()
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   155
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   156
    def _compute_reload(self, entity, rschema, role, reload):
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   157
        ctrl_reload = self._rules.get('reload', reload)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   158
        if callable(ctrl_reload):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   159
            ctrl_reload = ctrl_reload(entity)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   160
        if isinstance(ctrl_reload, int) and ctrl_reload > 1: # not True/False
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   161
            ctrl_reload = self._cw.build_url(ctrl_reload)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   162
        return ctrl_reload
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   163
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   164
    def _compute_default_value(self, rschema, role):
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   165
        default = self._rules.get('novalue_label')
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   166
        if default is None:
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   167
            if self._rules.get('novalue_include_rtype'):
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   168
                default = self._cw._('<%s not specified>') % display_name(
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   169
                    self._cw, rschema.type, role)
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   170
            else:
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   171
                default = self._cw._('<not specified>')
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   172
        return xml_escape(default)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   173
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   174
    def _is_composite(self):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   175
        return self._rules.get('edit_target') == 'related'
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   176
5878
8d1ca4150397 [reledit] fix relation cardinality handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5874
diff changeset
   177
    def _may_add_related(self, related_rset, entity, rschema, role, ttypes):
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   178
        """ ok for attribute-like composite entities """
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   179
        if len(ttypes) > 1: # many etypes: learn how to do it
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   180
            return False
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   181
        rdef = rschema.role_rdef(entity.e_schema, ttypes[0], role)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   182
        card = rdef.role_cardinality(role)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   183
        if related_rset or card not in '?1':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   184
            return False
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   185
        if role == 'subject':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   186
            kwargs = {'fromeid': entity.eid}
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   187
        else:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   188
            kwargs = {'toeid': entity.eid}
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   189
        return rdef.has_perm(self._cw, 'add', **kwargs)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   190
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   191
    def _may_edit_related_entity(self, related_rset, entity, rschema, role, ttypes):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   192
        """ controls the edition of the related entity """
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   193
        if len(ttypes) > 1 or len(related_rset.rows) != 1:
5878
8d1ca4150397 [reledit] fix relation cardinality handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5874
diff changeset
   194
            return False
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   195
        if entity.e_schema.rdef(rschema, role).role_cardinality(role) not in '?1':
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   196
            return False
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   197
        return related_rset.get_entity(0, 0).cw_has_perm('update')
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   198
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   199
    def _may_delete_related(self, related_rset, entity, rschema, role):
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   200
        # we assume may_edit_related, only 1 related entity
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   201
        if not related_rset:
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   202
            return False
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   203
        rentity = related_rset.get_entity(0, 0)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   204
        if role == 'subject':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   205
            kwargs = {'fromeid': entity.eid, 'toeid': rentity.eid}
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   206
        else:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   207
            kwargs = {'fromeid': rentity.eid, 'toeid': entity.eid}
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   208
        # NOTE: should be sufficient given a well built schema/security
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   209
        return rschema.has_perm(self._cw, 'delete', **kwargs)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   210
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   211
    def _build_edit_zone(self):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   212
        return self._editzone % {'msg' : xml_escape(_(self._cw._(self._editzonemsg)))}
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   213
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   214
    def _build_delete_zone(self):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   215
        return self._deletezone % {'msg': xml_escape(self._cw._(self._deletemsg))}
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   216
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   217
    def _build_add_zone(self):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   218
        return self._addzone % {'msg': xml_escape(self._cw._(self._addmsg))}
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   219
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   220
    def _build_divid(self, rtype, role, entity_eid):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   221
        """ builds an id for the root div of a reledit widget """
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   222
        return '%s-%s-%s' % (rtype, role, entity_eid)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   223
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   224
    def _build_args(self, entity, rtype, role, formid, reload,
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   225
                    extradata=None):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   226
        divid = self._build_divid(rtype, role, entity.eid)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   227
        event_args = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'formid': formid,
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   228
                      'reload' : json_dumps(reload),
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   229
                      'role' : role, 'vid' : u''}
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   230
        if extradata:
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   231
            event_args.update(extradata)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   232
        return event_args
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   233
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   234
    def _prepare_form(self, entity, _rtype, role):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   235
        display_label = False
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   236
        related_entity = entity
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   237
        return display_label, related_entity
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   238
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   239
    def _prepare_composite_form(self, entity, rtype, role, edit_related, add_related):
6282
556b1b1a2c5a [reledit] new rtag entry to control apparition of relation label in default value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6264
diff changeset
   240
        display_label = True
5878
8d1ca4150397 [reledit] fix relation cardinality handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5874
diff changeset
   241
        if edit_related and not add_related:
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   242
            related_entity = entity.related(rtype, role).get_entity(0, 0)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   243
        elif add_related:
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   244
            _new_entity = self._cw.vreg['etypes'].etype_class(add_related)(self._cw)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   245
            _new_entity.eid = self._cw.varmaker.next()
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   246
            related_entity = _new_entity
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   247
            # XXX see forms.py ~ 276 and entities.linked_to method
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   248
            #     is there another way ?
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   249
            self._cw.form['__linkto'] = '%s:%s:%s' % (rtype, entity.eid, neg_role(role))
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   250
        return display_label, related_entity
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   251
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   252
    def _build_renderer(self, related_entity, display_label):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   253
        return self._cw.vreg['formrenderers'].select(
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   254
            self._form_renderer_id, self._cw, entity=related_entity,
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   255
            display_label=display_label,
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   256
            table_class='attributeForm' if display_label else '',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   257
            display_help=False, button_bar_class='buttonbar',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   258
            display_progress_div=False)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   259
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   260
    def _build_form(self, entity, rtype, role, divid, formid, reload,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   261
                    display_label, related_entity, extradata=None, **formargs):
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   262
        event_args = self._build_args(entity, rtype, role, formid,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   263
                                      reload, extradata)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   264
        cancelclick = self._cancelclick % divid
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   265
        form = self._cw.vreg['forms'].select(
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   266
            formid, self._cw, rset=related_entity.as_rset(), entity=related_entity,
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   267
            domid='%s-form' % divid, formtype='inlined',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   268
            action=self._cw.build_url('validateform', __onsuccess='window.parent.cw.reledit.onSuccess'),
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   269
            cwtarget='eformframe', cssclass='releditForm',
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   270
            **formargs)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   271
        # pass reledit arguments
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   272
        for pname, pvalue in event_args.iteritems():
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   273
            form.add_hidden('__reledit|' + pname, pvalue)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   274
        # handle buttons
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   275
        if form.form_buttons: # edition, delete
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   276
            form_buttons = []
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   277
            for button in form.form_buttons:
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   278
                if not button.label.endswith('apply'):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   279
                    if button.label.endswith('cancel'):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   280
                        button = copy.deepcopy(button)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   281
                        button.cwaction = None
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   282
                        button.onclick = cancelclick
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   283
                    form_buttons.append(button)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   284
            form.form_buttons = form_buttons
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   285
        else: # base
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   286
            form.form_buttons = [SubmitButton(),
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   287
                                 Button(stdmsgs.BUTTON_CANCEL, onclick=cancelclick)]
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   288
        form.event_args = event_args
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   289
        if formid == 'base':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   290
            field = form.field_by_name(rtype, role, entity.e_schema)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   291
            form.append_field(field)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   292
        return form, self._build_renderer(related_entity, display_label)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   293
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   294
    def _should_edit_attribute(self, entity, rschema):
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   295
        rdef = entity.e_schema.rdef(rschema)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   296
        # check permissions
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   297
        if not entity.cw_has_perm('update'):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   298
            return False
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   299
        rdef = entity.e_schema.rdef(rschema)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   300
        return rdef.has_perm(self._cw, 'update', eid=entity.eid)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   301
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   302
    should_edit_attributes = deprecated('[3.9] should_edit_attributes is deprecated,'
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   303
                                        ' use _should_edit_attribute instead',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   304
                                        _should_edit_attribute)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   305
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   306
    def _should_edit_relation(self, entity, rschema, role):
6264
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   307
        eeid = entity.eid
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   308
        perm_args = {'fromeid': eeid} if role == 'subject' else {'toeid': eeid}
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   309
        return rschema.has_perm(self._cw, 'add', **perm_args)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   310
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   311
    should_edit_relations = deprecated('[3.9] should_edit_relations is deprecated,'
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   312
                                       ' use _should_edit_relation instead',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   313
                                       _should_edit_relation)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   314
6264
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   315
    def _open_form_wrapper(self, divid, value, form, renderer,
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   316
                           _edit_related, _add_related, _delete_related):
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   317
        w = self.w
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   318
        w(u'<div id="%(id)s-reledit" onmouseout="%(out)s" onmouseover="%(over)s" class="%(css)s">' %
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   319
          {'id': divid, 'css': 'releditField',
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   320
           'out': "jQuery('#%s').addClass('hidden')" % divid,
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   321
           'over': "jQuery('#%s').removeClass('hidden')" % divid})
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   322
        w(u'<div id="%s-value" class="editableFieldValue">' % divid)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   323
        w(value)
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   324
        w(u'</div>')
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   325
        w(form.render(renderer=renderer))
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   326
        w(u'<div id="%s" class="editableField hidden">' % divid)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   327
6264
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   328
    def _edit_action(self, divid, args, edit_related, add_related, _delete_related):
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   329
        if not add_related: # currently, excludes edition
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   330
            w = self.w
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   331
            args['formid'] = 'edition' if edit_related else 'base'
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   332
            w(u'<div id="%s-update" class="editableField" onclick="%s" title="%s">' %
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   333
              (divid, xml_escape(self._onclick % args), self._cw._(self._editzonemsg)))
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   334
            w(self._build_edit_zone())
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   335
            w(u'</div>')
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   336
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   337
    def _add_action(self, divid, args, _edit_related, add_related, _delete_related):
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   338
        if add_related:
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   339
            w = self.w
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   340
            args['formid'] = 'edition' if add_related else 'base'
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   341
            w(u'<div id="%s-add" class="editableField" onclick="%s" title="%s">' %
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   342
              (divid, xml_escape(self._onclick % args), self._cw._(self._addmsg)))
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   343
            w(self._build_add_zone())
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   344
            w(u'</div>')
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   345
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   346
    def _del_action(self, divid, args, _edit_related, _add_related, delete_related):
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   347
        if delete_related:
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   348
            w = self.w
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   349
            args['formid'] = 'deleteconf'
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   350
            w(u'<div id="%s-delete" class="editableField" onclick="%s" title="%s">' %
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   351
              (divid, xml_escape(self._onclick % args), self._cw._(self._deletemsg)))
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   352
            w(self._build_delete_zone())
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   353
            w(u'</div>')
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   354
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   355
    def _close_form_wrapper(self):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   356
        self.w(u'</div>')
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   357
        self.w(u'</div>')
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   358
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   359
    def view_form(self, divid, value, form=None, renderer=None,
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   360
                  edit_related=False, add_related=False, delete_related=False):
6264
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   361
        self._open_form_wrapper(divid, value, form, renderer,
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   362
                                edit_related, add_related, delete_related)
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   363
        args = form.event_args.copy()
6264
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   364
        self._edit_action(divid, args, edit_related, add_related, delete_related)
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   365
        self._add_action(divid, args, edit_related, add_related, delete_related)
0dcd19d89767 [reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6246
diff changeset
   366
        self._del_action(divid, args, edit_related, add_related, delete_related)
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   367
        self._close_form_wrapper()
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   368
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   369
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   370
class AutoClickAndEditFormView(ClickAndEditFormView):
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   371
    __regid__ = 'reledit'
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   372
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   373
    def _build_form(self, entity, rtype, role, divid, formid, reload,
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6111
diff changeset
   374
                    display_label, related_entity, extradata=None, **formargs):
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6282
diff changeset
   375
        event_args = self._build_args(entity, rtype, role, 'base',
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   376
                                      reload, extradata)
6111
06c96a79c3c0 [views/reledit] small refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6110
diff changeset
   377
        form = _DummyForm()
5869
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   378
        form.event_args = event_args
8a129b3a5aff reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   379
        return form, None