cubicweb/web/views/editforms.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 05 Apr 2019 17:58:19 +0200
changeset 12567 26744ad37953
parent 12503 b01dd0ef43aa
permissions -rw-r--r--
Drop python2 support This mostly consists in removing the dependency on "six" and updating the code to use only Python3 idioms. Notice that we previously used TemporaryDirectory from cubicweb.devtools.testlib for compatibility with Python2. We now directly import it from tempfile.
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: 7149
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
"""Set of HTML automatic forms to create, delete, copy or edit a single entity
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
or a list of entities of the same type
5583
24125df012f3 [reledit] #894131: use "<`attribute` unset>" instead of generic "<not specified>" when an attribute or relation has no value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    20
"""
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11301
diff changeset
    22
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    24
from copy import copy
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    25
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7149
diff changeset
    26
from logilab.common.registry import yes
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    27
11295
00d42916f238 [web] Remove some unused imports in editforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11294
diff changeset
    28
from cubicweb import _
5583
24125df012f3 [reledit] #894131: use "<`attribute` unset>" instead of generic "<not specified>" when an attribute or relation has no value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    29
from cubicweb import tags
11295
00d42916f238 [web] Remove some unused imports in editforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11294
diff changeset
    30
from cubicweb.predicates import (one_line_rset, non_final_entity,
00d42916f238 [web] Remove some unused imports in editforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11294
diff changeset
    31
                                 specified_etype_implements, is_instance)
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    32
from cubicweb.view import EntityView
11295
00d42916f238 [web] Remove some unused imports in editforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11294
diff changeset
    33
from cubicweb.web import stdmsgs, eid_param, formwidgets as fw
00d42916f238 [web] Remove some unused imports in editforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11294
diff changeset
    34
from cubicweb.web.form import FormViewMixIn
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8190
diff changeset
    35
from cubicweb.web.views import uicfg, forms, reledit
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents: 1459
diff changeset
    36
3927
b2a6c25b8429 consider 'rvid' key in primaryview_display_control to determine sub-view to use in reledit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3880
diff changeset
    37
_pvdc = uicfg.primaryview_display_ctrl
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    40
class DeleteConfForm(forms.CompositeForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    41
    __regid__ = 'deleteconf'
4649
9a6db1eb12ff [views/deleteconf] remove action ppty (useless & clashes with form attr, replace buggy non_final_entity selector with implements workaround
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4641
diff changeset
    42
    # XXX non_final_entity does not implement eclass_selector
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5869
diff changeset
    43
    __select__ = is_instance('Any')
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    44
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    45
    domid = 'deleteconf'
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    46
    copy_nav_params = True
4378
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4366
diff changeset
    47
    form_buttons = [fw.Button(stdmsgs.BUTTON_DELETE, cwaction='delete'),
11197
9f1c89e7426d [web/views] stop using cwaction='cancel'
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    48
                    fw.Button(stdmsgs.BUTTON_CANCEL,
9f1c89e7426d [web/views] stop using cwaction='cancel'
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    49
                              {'class': fw.Button.css_class + ' cwjs-edition-cancel'})]
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    50
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    51
    def __init__(self, *args, **kwargs):
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    52
        super(DeleteConfForm, self).__init__(*args, **kwargs)
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    53
        done = set()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    54
        for entity in self.cw_rset.entities():
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    55
            if entity.eid in done:
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    56
                continue
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    57
            done.add(entity.eid)
3485
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
    58
            subform = self._cw.vreg['forms'].select('base', self._cw,
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
    59
                                                    entity=entity,
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
    60
                                                    mainform=False)
3513
c002f6488631 [form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3355
diff changeset
    61
            self.add_subform(subform)
2572
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    62
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    63
58556f9317c9 [notification view] consider row/col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2538
diff changeset
    64
class DeleteConfFormView(FormViewMixIn, EntityView):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
    65
    """form used to confirm deletion of some entities"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
    66
    __regid__ = 'deleteconf'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
    title = _('delete')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
    # don't use navigation, all entities asked to be deleted should be displayed
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
    # else we will only delete the displayed page
4244
2c3de1953d00 rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4242
diff changeset
    70
    paginable = False
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    71
    # show first level of composite relations in a treeview
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    72
    show_composite = False
12064
0c06abcf4f82 [web/views] deleteconf: ignore workflow when displaying composite entities
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
    73
    show_composite_skip_rtypes = set('wf_info_for',)
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    74
12064
0c06abcf4f82 [web/views] deleteconf: ignore workflow when displaying composite entities
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
    75
    def _iter_composite_entities(self, entity, limit=None):
12090
245a4f81053b [web/views] display unique composite entities in deleteconf
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12064
diff changeset
    76
        eids = set()
12184
cd940ebefc4e [web/views] delete: show composite entities in predictible order
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12091
diff changeset
    77
        for rdef, role in sorted(entity.e_schema.composite_rdef_roles,
cd940ebefc4e [web/views] delete: show composite entities in predictible order
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12091
diff changeset
    78
                                 key=lambda x: x[0].rtype):
12064
0c06abcf4f82 [web/views] deleteconf: ignore workflow when displaying composite entities
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
    79
            if rdef.rtype in self.show_composite_skip_rtypes:
0c06abcf4f82 [web/views] deleteconf: ignore workflow when displaying composite entities
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
    80
                continue
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    81
            for centity in entity.related(
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    82
                rdef.rtype, role, limit=limit
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    83
            ).entities():
12090
245a4f81053b [web/views] display unique composite entities in deleteconf
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12064
diff changeset
    84
                if centity.eid not in eids:
245a4f81053b [web/views] display unique composite entities in deleteconf
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12064
diff changeset
    85
                    eids.add(centity.eid)
245a4f81053b [web/views] display unique composite entities in deleteconf
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12064
diff changeset
    86
                    yield centity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
    87
1852
f04da596da6c give back onsubmit customizability (oops)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1847
diff changeset
    88
    def call(self, onsubmit=None):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
        """ask for confirmation before real deletion"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
    90
        req, w = self._cw, self.w
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
        _ = req._
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    92
        if self.show_composite:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    93
            req.add_css(('jquery-treeview/jquery.treeview.css', 'cubicweb.treeview.css'))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
        w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
          % _('this action is not reversible!'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
        # XXX above message should have style of a warning
9492
c7fc56eecd1a English typography
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents: 8665
diff changeset
    97
        w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s)?'))
3485
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
    98
        form = self._cw.vreg['forms'].select(self.__regid__, req,
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
    99
                                             rset=self.cw_rset,
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
   100
                                             onsubmit=onsubmit)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   101
        w(u'<ul>\n')
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   102
        page_size = req.property_value('navigation.page-size')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   103
        for entity in self.cw_rset.entities():
3485
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
   104
            # don't use outofcontext view or any other that may contain inline
e867ae952fc0 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3479
diff changeset
   105
            # edition form
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   106
            w(u'<li>%s' % tags.a(entity.view('textoutofcontext'),
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   107
                                 href=entity.absolute_url()))
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   108
            if self.show_composite:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   109
                content = None
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   110
                for count, centity in enumerate(self._iter_composite_entities(
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   111
                    entity, limit=page_size,
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   112
                )):
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   113
                    if count == 0:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   114
                        w(u'<ul class="treeview">')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   115
                    if content is not None:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   116
                        w(u'<li>%s</li>' % content)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   117
                    if count == page_size - 1:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   118
                        w(u'<li class="last">%s</li></ul>' % _(
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   119
                            'And more composite entities'))
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   120
                        break
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   121
                    content = tags.a(centity.view('textoutofcontext'),
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   122
                                     href=centity.absolute_url())
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   123
                else:
12091
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12090
diff changeset
   124
                    if content is not None:
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12090
diff changeset
   125
                        w(u'<li class="last">%s</li></ul>' % content)
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   126
            w(u'</li>\n')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
        w(u'</ul>\n')
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6225
diff changeset
   128
        form.render(w=self.w)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   131
class EditionFormView(FormViewMixIn, EntityView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   132
    """display primary entity edition form"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   133
    __regid__ = 'edition'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   134
    # add yes() so it takes precedence over deprecated views in baseforms,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   135
    # though not baseforms based customized view
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   136
    __select__ = one_line_rset() & non_final_entity() & yes()
7149
9dfd0dea692b make it easier to inherit from EditionFormView
Florent Cayré <florent.cayre@gmail.com>
parents: 6453
diff changeset
   137
    form_id = 'edition'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
6177
76aaca285e07 [views] rename Edition to Modification and personal information to profile
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5940
diff changeset
   139
    title = _('modification')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   140
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   141
    def cell_call(self, row, col, **kwargs):
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   142
        entity = self.cw_rset.complete_entity(row, col)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   143
        self.render_form(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   144
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   145
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   146
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   147
        self.form_title(entity)
7149
9dfd0dea692b make it easier to inherit from EditionFormView
Florent Cayré <florent.cayre@gmail.com>
parents: 6453
diff changeset
   148
        form = self._cw.vreg['forms'].select(self.form_id, self._cw,
9dfd0dea692b make it easier to inherit from EditionFormView
Florent Cayré <florent.cayre@gmail.com>
parents: 6453
diff changeset
   149
                                             entity=entity,
3457
0924d0d08d60 [api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   150
                                             submitmsg=self.submited_message())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   151
        self.init_form(form, entity)
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6225
diff changeset
   152
        form.render(w=self.w)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   154
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   155
        """customize your form before rendering here"""
2049
b9baedffeb8b set __maineid in EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2048
diff changeset
   156
        pass
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   157
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   158
    def form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   159
        """the form view title"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   160
        ptitle = self._cw._(self.title)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   161
        self.w(u'<div class="formTitle"><span>%s %s</span></div>' % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   162
            entity.dc_type(), ptitle and '(%s)' % ptitle))
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   163
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   164
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   165
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   166
        return self._cw._('entity edited')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   167
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   168
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   169
class CreationFormView(EditionFormView):
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   170
    """display primary entity creation form"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   171
    __regid__ = 'creation'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   172
    __select__ = specified_etype_implements('Any') & yes()
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   173
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   174
    title = _('creation')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   175
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   176
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   177
        """creation view for an entity"""
3346
b1fd9d4ef579 fix case insensitive selector for entity creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3331
diff changeset
   178
        # at this point we know etype is a valid entity type, thanks to our
b1fd9d4ef579 fix case insensitive selector for entity creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3331
diff changeset
   179
        # selector
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   180
        etype = kwargs.pop('etype', self._cw.form.get('etype'))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   181
        entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw)
10669
155c29e0ed1c [py3k] use next builtin instead of next method
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   182
        entity.eid = next(self._cw.varmaker)
3077
6c92323667a6 case insensitive add/XXX url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3062
diff changeset
   183
        self.render_form(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   184
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   185
    def form_title(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   186
        """the form view title"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   187
        if '__linkto' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   188
            if isinstance(self._cw.form['__linkto'], list):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   189
                # XXX which one should be considered (case: add a ticket to a
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   190
                # version in jpl)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   191
                rtype, linkto_eid, role = self._cw.form['__linkto'][0].split(':')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   192
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   193
                rtype, linkto_eid, role = self._cw.form['__linkto'].split(':')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   194
            linkto_rset = self._cw.eid_rset(linkto_eid)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   195
            linkto_type = linkto_rset.description[0][0]
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   196
            if role == 'subject':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   197
                title = self._cw.__('creating %s (%s %s %s %%(linkto)s)' % (
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   198
                    entity.e_schema, entity.e_schema, rtype, linkto_type))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   199
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   200
                title = self._cw.__('creating %s (%s %%(linkto)s %s %s)' % (
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   201
                    entity.e_schema, linkto_type, rtype, entity.e_schema))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   202
            msg = title % {'linkto' : self._cw.view('incontext', linkto_rset)}
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   203
            self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   204
        else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   205
            super(CreationFormView, self).form_title(entity)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   206
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   207
    def url(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   208
        """return the url associated with this view"""
6039
6e84db1b3e44 [view] deprecate create_url in favor of a cw_create_url class method on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   209
        req = self._cw
6e84db1b3e44 [view] deprecate create_url in favor of a cw_create_url class method on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   210
        return req.vreg["etypes"].etype_class(req.form['etype']).cw_create_url(
6e84db1b3e44 [view] deprecate create_url in favor of a cw_create_url class method on entity classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   211
            req)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   212
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   213
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   214
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   215
        return self._cw._('entity created')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   216
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   217
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   218
class CopyFormView(EditionFormView):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   219
    """display primary entity creation form initialized with values from another
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   220
    entity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   221
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   222
    __regid__ = 'copy'
3629
559cad62c786 backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3627
diff changeset
   223
3627
70dbba754c11 fix title of CopyFormView
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 3586
diff changeset
   224
    title = _('copy')
3062
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   225
    warning_message = _('Please note that this is only a shallow copy')
a8e901fc4457 ease overriding of copy warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2686
diff changeset
   226
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   227
    def render_form(self, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   228
        """fetch and render the form"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   229
        # make a copy of entity to avoid altering the entity in the
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   230
        # request's cache.
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   231
        entity.complete()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   232
        self.newentity = copy(entity)
1703
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   233
        self.copying = entity
10669
155c29e0ed1c [py3k] use next builtin instead of next method
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   234
        self.newentity.eid = next(self._cw.varmaker)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   235
        self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   236
               % self._cw._(self.warning_message))
1685
3c59ae0e6548 fix copy edition view
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1629
diff changeset
   237
        super(CopyFormView, self).render_form(self.newentity)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   238
        del self.newentity
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   239
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   240
    def init_form(self, form, entity):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   241
        """customize your form before rendering here"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   242
        super(CopyFormView, self).init_form(form, entity)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   243
        if entity.eid == self.newentity.eid:
4164
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4160
diff changeset
   244
            form.add_hidden(eid_param('__cloned_eid', entity.eid),
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4160
diff changeset
   245
                            self.copying.eid)
3476
6e927b729ae1 [uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
   246
        for rschema, role in form.editable_attributes():
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3643
diff changeset
   247
            if not rschema.final:
1703
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   248
                # ensure relation cache is filed
a2b5dfdb4b62 should prefill cached values for relation in the primary or secondary category
sylvain.thenault@logilab.fr
parents: 1692
diff changeset
   249
                rset = self.copying.related(rschema, role)
5557
1a534c596bff [entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   250
                self.newentity.cw_set_relation_cache(rschema, role, rset)
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   251
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   252
    def submited_message(self):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   253
        """return the message that will be displayed on successful edition"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   254
        return self._cw._('entity copied')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   255
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   256
2005
e8032965f37a turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1995
diff changeset
   257
class TableEditForm(forms.CompositeForm):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   258
    __regid__ = 'muledit'
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   259
    domid = 'entityForm'
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   260
    onsubmit = "return validateForm('%s', null);" % domid
4378
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4366
diff changeset
   261
    form_buttons = [fw.SubmitButton(_('validate modifications on selected items')),
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4366
diff changeset
   262
                    fw.ResetButton(_('revert changes'))]
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   263
1692
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   264
    def __init__(self, req, rset, **kwargs):
56009f2101fe fix multiple edit
sylvain.thenault@logilab.fr
parents: 1685
diff changeset
   265
        kwargs.setdefault('__redirectrql', rset.printable_rql())
2890
fdcb8a2bb6eb fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   266
        super(TableEditForm, self).__init__(req, rset=rset, **kwargs)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9492
diff changeset
   267
        for row in range(len(self.cw_rset)):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3396
diff changeset
   268
            form = self._cw.vreg['forms'].select('edition', self._cw,
3476
6e927b729ae1 [uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
   269
                                                 rset=self.cw_rset, row=row,
6e927b729ae1 [uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
   270
                                                 formtype='muledit',
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777 3880
diff changeset
   271
                                                 copy_nav_params=False,
3476
6e927b729ae1 [uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
   272
                                                 mainform=False)
1324
a82f83188695 ease renderer overriding
sylvain.thenault@logilab.fr
parents: 1322
diff changeset
   273
            # XXX rely on the EntityCompositeFormRenderer to put the eid input
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   274
            form.remove_field(form.field_by_name('eid'))
3513
c002f6488631 [form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3355
diff changeset
   275
            self.add_subform(form)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   276
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   277
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1313
diff changeset
   278
class TableEditFormView(FormViewMixIn, EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   279
    __regid__ = 'muledit'
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   280
    __select__ = EntityView.__select__ & yes()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   281
    title = _('multiple edit')
1423
39320a58faac missing overriding of removejs in inline-creation form view
sylvain.thenault@logilab.fr
parents: 1396
diff changeset
   282
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   283
    def call(self, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   284
        """a view to edit multiple entities of the same type the first column
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   285
        should be the eid
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1138
diff changeset
   286
        """
4310
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   287
        # XXX overriding formvid (eg __form_id) necessary to make work edition:
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   288
        # the edit controller try to select the form with no rset but
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   289
        # entity=entity, and use this form to edit the entity. So we want
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   290
        # edition form there but specifying formvid may have other undesired
4669
2a77a0d9075f cleanup, typos
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4668
diff changeset
   291
        # side effect. Maybe we should provide another variable optionally
4310
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   292
        # telling which form the edit controller should select (eg difffers
a139b98b6af5 specify formvid=edition to get multiple edition working w/ 3.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4278
diff changeset
   293
        # between html generation / post handling form)
4668
9f82f81bf13d [form] fix #719285, due to multiple calls to restore_previous_post, by proper refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4649
diff changeset
   294
        form = self._cw.vreg['forms'].select(self.__regid__, self._cw,
9f82f81bf13d [form] fix #719285, due to multiple calls to restore_previous_post, by proper refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4649
diff changeset
   295
                                             rset=self.cw_rset,
9f82f81bf13d [form] fix #719285, due to multiple calls to restore_previous_post, by proper refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4649
diff changeset
   296
                                             copy_nav_params=True,
9f82f81bf13d [form] fix #719285, due to multiple calls to restore_previous_post, by proper refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4649
diff changeset
   297
                                             formvid='edition')
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6225
diff changeset
   298
        form.render(w=self.w)