web/form.py
author sylvain.thenault@logilab.fr
Fri, 17 Apr 2009 11:14:19 +0200
branchtls-sprint
changeset 1392 d6279efff7b3
parent 1391 2a80b14fc548
child 1393 ff6758d7b96f
permissions -rw-r--r--
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""abstract form classes for CubicWeb web client
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
751
ec16f43107d3 update import
sylvain.thenault@logilab.fr
parents: 692
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
     9
from warnings import warn
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
    10
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
    11
from logilab.common.compat import any
1058
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
    12
from logilab.common.decorators import iclassmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    14
from cubicweb.appobject import AppRsetObject
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    15
from cubicweb.selectors import yes, non_final_entity, match_kwargs, one_line_rset
1133
8a409ea0c9ec more linting
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    16
from cubicweb.view import NOINDEX, NOFOLLOW
1097
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
    17
from cubicweb.common import tags
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
    18
from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
from cubicweb.web.httpcache import NoHTTPCacheManager
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    20
from cubicweb.web.controller import NAV_FORM_PARAMETERS
1097
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
    21
from cubicweb.web.formfields import (Field, StringField, RelationField,
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
    22
                                     HiddenInitialValueField)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    23
from cubicweb.web.formrenderers import FormRenderer
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    24
from cubicweb.web import formwidgets as fwdgs
1097
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
    25
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    26
class FormViewMixIn(object):
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    27
    """abstract form view mix-in"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    category = 'form'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
    controller = 'edit'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    http_cache_manager = NoHTTPCacheManager
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
    add_to_breadcrumbs = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
    33
    def __init__(self, req, rset, **kwargs):
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    34
        super(FormViewMixIn, self).__init__(req, rset, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        # get validation session data which may have been previously set.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        # deleting validation errors here breaks form reloading (errors are
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        # no more available), they have to be deleted by application's publish
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        # method on successful commit
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        formurl = req.url()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        forminfo = req.get_session_data(formurl)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        if forminfo:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
            req.data['formvalues'] = forminfo['values']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
            req.data['formerrors'] = errex = forminfo['errors']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
            req.data['displayederrors'] = set()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
            # if some validation error occured on entity creation, we have to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
            # get the original variable name from its attributed eid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
            foreid = errex.entity
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            for var, eid in forminfo['eidmap'].items():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
                if foreid == eid:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
                    errex.eid = var
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
                    break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
                errex.eid = foreid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    def html_headers(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        """return a list of html headers (eg something to be inserted between
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        <head> and </head> of the returned page
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
        by default forms are neither indexed nor followed
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        return [NOINDEX, NOFOLLOW]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    def linkable(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        """override since forms are usually linked by an action,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        so we don't want them to be listed by appli.possible_views
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        return False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    69
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    70
# XXX should disappear 
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    71
class FormMixIn(object):
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    72
    """abstract form mix-in
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    73
    XXX: you should inherit from this FIRST (obscure pb with super call)
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    74
    """
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    75
1289
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    76
    def initialize_varmaker(self):
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    77
        varmaker = self.req.get_page_data('rql_varmaker')
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    78
        if varmaker is None:
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    79
            varmaker = self.req.varmaker
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    80
            self.req.set_page_data('rql_varmaker', varmaker)
5eff2ef92977 move initialize_varmaker on the FormMixIn class
sylvain.thenault@logilab.fr
parents: 1272
diff changeset
    81
        self.varmaker = varmaker
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
1318
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    83
    # XXX deprecated with new form system. Should disappear
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    84
    
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    85
    domid = 'entityForm'
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    86
    category = 'form'
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    87
    controller = 'edit'
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    88
    http_cache_manager = NoHTTPCacheManager
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    89
    add_to_breadcrumbs = False
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    90
    
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    91
    def __init__(self, req, rset, **kwargs):
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    92
        super(FormMixIn, self).__init__(req, rset, **kwargs)
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    93
        # get validation session data which may have been previously set.
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    94
        # deleting validation errors here breaks form reloading (errors are
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    95
        # no more available), they have to be deleted by application's publish
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    96
        # method on successful commit
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    97
        formurl = req.url()
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    98
        forminfo = req.get_session_data(formurl)
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
    99
        if forminfo:
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   100
            req.data['formvalues'] = forminfo['values']
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   101
            req.data['formerrors'] = errex = forminfo['errors']
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   102
            req.data['displayederrors'] = set()
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   103
            # if some validation error occured on entity creation, we have to
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   104
            # get the original variable name from its attributed eid
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   105
            foreid = errex.entity
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   106
            for var, eid in forminfo['eidmap'].items():
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   107
                if foreid == eid:
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   108
                    errex.eid = var
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   109
                    break
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   110
            else:
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   111
                errex.eid = foreid    
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   112
        
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   113
    def html_headers(self):
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   114
        """return a list of html headers (eg something to be inserted between
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   115
        <head> and </head> of the returned page
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   116
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   117
        by default forms are neither indexed nor followed
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   118
        """
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   119
        return [NOINDEX, NOFOLLOW]
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   120
        
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   121
    def linkable(self):
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   122
        """override since forms are usually linked by an action,
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   123
        so we don't want them to be listed by appli.possible_views
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   124
        """
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   125
        return False
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   126
50e1a778c5ee new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents: 1315
diff changeset
   127
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   128
    def button(self, label, klass='validateButton', tabindex=None, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   129
        if tabindex is None:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   130
            tabindex = self.req.next_tabindex()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   131
        return tags.input(value=label, klass=klass, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   132
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   133
    def action_button(self, label, onclick=None, __action=None, **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   134
        if onclick is None:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   135
            onclick = "postForm('__action_%s', \'%s\', \'%s\')" % (
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   136
                __action, label, self.domid)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   137
        return self.button(label, onclick=onclick, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   138
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   139
    def button_ok(self, label=None, type='submit', name='defaultsubmit',
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   140
                  **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   141
        label = self.req._(label or stdmsgs.BUTTON_OK).capitalize()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   142
        return self.button(label, name=name, type=type, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   143
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   144
    def button_apply(self, label=None, type='button', **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   145
        label = self.req._(label or stdmsgs.BUTTON_APPLY).capitalize()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   146
        return self.action_button(label, __action='apply', type=type, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   148
    def button_delete(self, label=None, type='button', **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   149
        label = self.req._(label or stdmsgs.BUTTON_DELETE).capitalize()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   150
        return self.action_button(label, __action='delete', type=type, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   151
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   152
    def button_cancel(self, label=None, type='button', **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   153
        label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   154
        return self.action_button(label, __action='cancel', type=type, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   155
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   156
    def button_reset(self, label=None, type='reset', name='__action_cancel',
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   157
                     **kwargs):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   158
        label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize()
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   159
        return self.button(label, type=type, **kwargs)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   160
1305
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   161
    def need_multipart(self, entity, categories=('primary', 'secondary')):
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   162
        """return a boolean indicating if form's enctype should be multipart
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   163
        """
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   164
        for rschema, _, x in entity.relations_by_category(categories):
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   165
            if entity.get_widget(rschema, x).need_multipart:
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   166
                return True
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   167
        # let's find if any of our inlined entities needs multipart
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   168
        for rschema, targettypes, x in entity.relations_by_category('inlineview'):
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   169
            assert len(targettypes) == 1, \
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   170
                   "I'm not able to deal with several targets and inlineview"
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   171
            ttype = targettypes[0]
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   172
            inlined_entity = self.vreg.etype_class(ttype)(self.req, None, None)
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   173
            for irschema, _, x in inlined_entity.relations_by_category(categories):
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   174
                if inlined_entity.get_widget(irschema, x).need_multipart:
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   175
                    return True
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   176
        return False
395ef7f2b95b cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents: 1304
diff changeset
   177
    
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    def error_message(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
        """return formatted error message
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        This method should be called once inlined field errors has been consumed
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
        errex = self.req.data.get('formerrors')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
        # get extra errors
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        if errex is not None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
            errormsg = self.req._('please correct the following errors:')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
            displayed = self.req.data['displayederrors']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
            errors = sorted((field, err) for field, err in errex.errors.items()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
                            if not field in displayed)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
            if errors:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
                if len(errors) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
                    templstr = '<li>%s</li>\n' 
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
                else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
                    templstr = '&nbsp;%s\n'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
                for field, err in errors:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
                    if field is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
                        errormsg += templstr % err
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
                    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
                        errormsg += templstr % '%s: %s' % (self.req._(field), err)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
                if len(errors) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
                    errormsg = '<ul>%s</ul>' % errormsg
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
            return u'<div class="errorMessage">%s</div>' % errormsg
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
        return u''
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   204
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   205
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   206
###############################################################################
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   207
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   208
class metafieldsform(type):
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   209
    def __new__(mcs, name, bases, classdict):
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   210
        allfields = []
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   211
        for base in bases:
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   212
            if hasattr(base, '_fields_'):
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   213
                allfields += base._fields_
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   214
        clsfields = (item for item in classdict.items()
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   215
                     if isinstance(item[1], Field))
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   216
        for fieldname, field in sorted(clsfields, key=lambda x: x[1].creation_rank):
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   217
            if not field.name:
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   218
                field.set_name(fieldname)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   219
            allfields.append(field)
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   220
        classdict['_fields_'] = allfields
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   221
        return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict)
1270
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   222
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   223
    
1270
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   224
class FieldNotFound(Exception):
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   225
    """raised by field_by_name when a field with the given name has not been
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   226
    found
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   227
    """
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   228
    
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   229
class FieldsForm(FormMixIn, AppRsetObject):
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   230
    __metaclass__ = metafieldsform
1047
21d4d5e6aa45 make forms selectable (appobject)
sylvain.thenault@logilab.fr
parents: 1032
diff changeset
   231
    __registry__ = 'forms'
21d4d5e6aa45 make forms selectable (appobject)
sylvain.thenault@logilab.fr
parents: 1032
diff changeset
   232
    __select__ = yes()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   233
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   234
    is_subform = False
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   235
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   236
    # attributes overrideable through __init__
1082
07c21784787b more rendering control
sylvain.thenault@logilab.fr
parents: 1081
diff changeset
   237
    internal_fields = ('__errorurl',) + NAV_FORM_PARAMETERS
1311
4cc6e2723dc7 move ajax.js to base form class
sylvain.thenault@logilab.fr
parents: 1308
diff changeset
   238
    needs_js = ('cubicweb.ajax.js', 'cubicweb.edition.js',)
1097
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   239
    needs_css = ('cubicweb.form.css',)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   240
    domid = 'form'
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   241
    title = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   242
    action = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   243
    onsubmit = "return freezeFormButtons('%(domid)s');"
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   244
    cssclass = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   245
    cssstyle = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   246
    cwtarget = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   247
    redirect_path = None
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   248
    set_error_url = True
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   249
    copy_nav_params = False
1304
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1289
diff changeset
   250
    form_buttons = None # form buttons (button widgets instances)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   251
                 
1271
0a5257f5d723 handle __message in FieldsForm, not only in EntityFieldsForm
sylvain.thenault@logilab.fr
parents: 1270
diff changeset
   252
    def __init__(self, req, rset=None, row=None, col=None, submitmsg=None,
0a5257f5d723 handle __message in FieldsForm, not only in EntityFieldsForm
sylvain.thenault@logilab.fr
parents: 1270
diff changeset
   253
                 **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   254
        super(FieldsForm, self).__init__(req, rset, row=row, col=col)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   255
        for key, val in kwargs.items():
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   256
            assert hasattr(self.__class__, key) and not key[0] == '_', key
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   257
            setattr(self, key, val)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   258
        self.fields = list(self.__class__._fields_)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   259
        if self.set_error_url:
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   260
            self.form_add_hidden('__errorurl', req.url())
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   261
        if self.copy_nav_params:
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   262
            for param in NAV_FORM_PARAMETERS:
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   263
                value = kwargs.get(param, req.form.get(param))
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   264
                if value:
1326
1d389a6b99b1 should not name that parameter
sylvain.thenault@logilab.fr
parents: 1318
diff changeset
   265
                    self.form_add_hidden(param, value)
1271
0a5257f5d723 handle __message in FieldsForm, not only in EntityFieldsForm
sylvain.thenault@logilab.fr
parents: 1270
diff changeset
   266
        if submitmsg is not None:
0a5257f5d723 handle __message in FieldsForm, not only in EntityFieldsForm
sylvain.thenault@logilab.fr
parents: 1270
diff changeset
   267
            self.form_add_hidden('__message', submitmsg)
1053
e4d965b5ca37 cleanup
sylvain.thenault@logilab.fr
parents: 1050
diff changeset
   268
        self.context = None
1058
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   269
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   270
    @iclassmethod
1183
62afd820d3ae field_by_name now takes a "role" argument, override it in AutomaticForm to call guess field if necessary
sylvain.thenault@logilab.fr
parents: 1175
diff changeset
   271
    def field_by_name(cls_or_self, name, role='subject'):
1270
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   272
        """return field with the given name and role"""
1058
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   273
        if isinstance(cls_or_self, type):
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   274
            fields = cls_or_self._fields_
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   275
        else:
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   276
            fields = cls_or_self.fields
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   277
        for field in fields:
1183
62afd820d3ae field_by_name now takes a "role" argument, override it in AutomaticForm to call guess field if necessary
sylvain.thenault@logilab.fr
parents: 1175
diff changeset
   278
            if field.name == name and field.role == role:
1058
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   279
                return field
1270
53f35db66f88 raise specific exception
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
   280
        raise FieldNotFound(name)
1058
c27be37daef8 field_by_name method (on class or instance)
sylvain.thenault@logilab.fr
parents: 1056
diff changeset
   281
    
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   282
    @iclassmethod
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   283
    def remove_field(cls_or_self, field):
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   284
        """remove a field from form class or instance"""
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   285
        if isinstance(cls_or_self, type):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   286
            fields = cls_or_self._fields_
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   287
        else:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   288
            fields = cls_or_self.fields
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   289
        fields.remove(field)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   290
    
1272
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   291
    @iclassmethod
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   292
    def append_field(cls_or_self, field):
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   293
        """append a field to form class or instance"""
1272
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   294
        if isinstance(cls_or_self, type):
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   295
            fields = cls_or_self._fields_
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   296
        else:
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   297
            fields = cls_or_self.fields
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   298
        fields.append(field)
e710fc46c6a0 new append_field method
sylvain.thenault@logilab.fr
parents: 1271
diff changeset
   299
    
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   300
    @property
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   301
    def form_needs_multipart(self):
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   302
        """true if the form needs enctype=multipart/form-data"""
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   303
        return any(field.needs_multipart for field in self.fields) 
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   305
    def form_add_hidden(self, name, value=None, **kwargs):
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   306
        """add an hidden field to the form"""
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   307
        field = StringField(name=name, widget=fwdgs.HiddenInput, initial=value,
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   308
                            **kwargs)
1338
9e038f84dbb3 setdomid should be true when id specified in kwargs
sylvain.thenault@logilab.fr
parents: 1326
diff changeset
   309
        if 'id' in kwargs:
9e038f84dbb3 setdomid should be true when id specified in kwargs
sylvain.thenault@logilab.fr
parents: 1326
diff changeset
   310
            # by default, hidden input don't set id attribute. If one is
9e038f84dbb3 setdomid should be true when id specified in kwargs
sylvain.thenault@logilab.fr
parents: 1326
diff changeset
   311
            # explicitly specified, ensure it will be set
9e038f84dbb3 setdomid should be true when id specified in kwargs
sylvain.thenault@logilab.fr
parents: 1326
diff changeset
   312
            field.widget.setdomid = True
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   313
        self.fields.append(field)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   314
        return field
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   315
    
1097
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   316
    def add_media(self):
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   317
        """adds media (CSS & JS) required by this widget"""
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   318
        if self.needs_js:
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   319
            self.req.add_js(self.needs_js)
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   320
        if self.needs_css:
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   321
            self.req.add_css(self.needs_css)
611bacbbe001 pylint fixes, media definitions on form as well
sylvain.thenault@logilab.fr
parents: 1082
diff changeset
   322
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   323
    def form_render(self, **values):
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   324
        """render this form, using the renderer given in args or the default
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   325
        FormRenderer()
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   326
        """
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   327
        renderer = values.pop('renderer', FormRenderer())
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   328
        return renderer.render(self, values)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   329
1391
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   330
    def form_build_context(self, rendervalues=None):
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   331
        """build form context values (the .context attribute which is a
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   332
        dictionary with field instance as key associated to a dictionary
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   333
        containing field 'name' (qualified), 'id', 'value' (for display, always
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   334
        a string).
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   335
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   336
        rendervalues is an optional dictionary containing extra kwargs given to
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   337
        form_render()
2a80b14fc548 more docstring
sylvain.thenault@logilab.fr
parents: 1386
diff changeset
   338
        """
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   339
        self.context = context = {}
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   340
        # on validation error, we get a dictionary of previously submitted
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   341
        # values
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   342
        self._previous_values = self.req.data.get('formvalues', {})
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   343
        # ensure rendervalues is a dict
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   344
        if rendervalues is None:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   345
            rendervalues = {}
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   346
        for field in self.fields:
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 892
diff changeset
   347
            for field in field.actual_fields(self):
1304
8975c8e520a9 refactor button handling
sylvain.thenault@logilab.fr
parents: 1289
diff changeset
   348
                field.form_init(self)
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   349
                value = self.form_field_display_value(field, rendervalues)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   350
                context[field] = {'value': value,
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   351
                                  'name': self.form_field_name(field),
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   352
                                  'id': self.form_field_id(field),
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   353
                                  }
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   354
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   355
    def form_field_display_value(self, field, rendervalues, load_bytes=False):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   356
        """return field's *string* value to use for display
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   357
        
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   358
        looks in
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   359
        1. previously submitted form values if any (eg on validation error)
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   360
        2. req.form
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   361
        3. extra kw args given to render_form
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   362
        4. field's typed value
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   363
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   364
        values found in 1. and 2. are expected te be already some 'display'
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   365
        value while those found in 3. and 4. are expected to be correctly typed.
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   366
        """
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   367
        if field.name in self._previous_values:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   368
            value = self._previous_values[field.name]
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   369
        elif field.name in self.req.form:
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   370
            value = self.req.form[field.name]
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   371
        else:
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   372
            if field.name in rendervalues:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   373
                value = rendervalues[field.name]
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   374
            else:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   375
                value = self.form_field_value(field, load_bytes)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   376
                if callable(value):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   377
                    value = value(self)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   378
            if value != INTERNAL_FIELD_VALUE: 
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   379
                value = field.format_value(self.req, value)
897
f5b91f11d8b6 provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 896
diff changeset
   380
        return value
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   381
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   382
    def form_field_value(self, field, load_bytes=False):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   383
        """return field's *typed* value"""
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   384
        value = field.initial
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   385
        if callable(value):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   386
            value = value(self)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   387
        return value
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   388
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   389
    def _errex_match_field(self, errex, field):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   390
        """return true if the field has some error in given validation exception
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   391
        """
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   392
        return field.name in errex.errors
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   393
    
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   394
    def form_field_error(self, field):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   395
        """return validation error for widget's field, if any"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   396
        errex = self.req.data.get('formerrors')
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   397
        if errex and self._errex_match_field(errex, field):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   398
            self.req.data['displayederrors'].add(field.name)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   399
            return u'<span class="error">%s</span>' % errex.errors[field.name]
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   400
        return u''
897
f5b91f11d8b6 provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 896
diff changeset
   401
1060
d795477ad16b rename method to form_field_format
sylvain.thenault@logilab.fr
parents: 1059
diff changeset
   402
    def form_field_format(self, field):
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   403
        return self.req.property_value('ui.default-text-format')
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   404
    
1061
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   405
    def form_field_encoding(self, field):
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   406
        return self.req.encoding
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   407
    
849
8591d896db7e update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents: 848
diff changeset
   408
    def form_field_name(self, field):
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   409
        return field.name
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   410
849
8591d896db7e update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents: 848
diff changeset
   411
    def form_field_id(self, field):
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   412
        return field.id
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   413
   
1183
62afd820d3ae field_by_name now takes a "role" argument, override it in AutomaticForm to call guess field if necessary
sylvain.thenault@logilab.fr
parents: 1175
diff changeset
   414
    def form_field_vocabulary(self, field, limit=None):
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   415
        raise NotImplementedError
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   416
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   417
   
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   418
class EntityFieldsForm(FieldsForm):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   419
    __select__ = (match_kwargs('entity') | (one_line_rset & non_final_entity()))
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   420
    
1082
07c21784787b more rendering control
sylvain.thenault@logilab.fr
parents: 1081
diff changeset
   421
    internal_fields = FieldsForm.internal_fields + ('__type', 'eid')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   422
    domid = 'entityForm'
1082
07c21784787b more rendering control
sylvain.thenault@logilab.fr
parents: 1081
diff changeset
   423
    
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   424
    def __init__(self, *args, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   425
        self.edited_entity = kwargs.pop('entity', None)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   426
        msg = kwargs.pop('submitmsg', None)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   427
        super(EntityFieldsForm, self).__init__(*args, **kwargs)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   428
        if self.edited_entity is None:
1369
49497136e977 must specify col where entity's eid is
sylvain.thenault@logilab.fr
parents: 1360
diff changeset
   429
            self.edited_entity = self.complete_entity(self.row, self.col)
887
51e371245bc5 various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents: 874
diff changeset
   430
        self.form_add_hidden('__type', eidparam=True)
51e371245bc5 various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents: 874
diff changeset
   431
        self.form_add_hidden('eid')
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   432
        if msg is not None:
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   433
            # If we need to directly attach the new object to another one
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   434
            for linkto in self.req.list_form_param('__linkto'):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   435
                self.form_add_hidden('__linkto', linkto)
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   436
                msg = '%s %s' % (msg, self.req._('and linked'))
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   437
            self.form_add_hidden('__message', msg)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   438
        
1315
86bddd181e03 should set None as default here as well
sylvain.thenault@logilab.fr
parents: 1312
diff changeset
   439
    def form_build_context(self, values=None):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   440
        self.form_add_entity_hiddens(self.edited_entity.e_schema)
1308
3d01229d9f6a override form_build_context instead of form_render so we get sure to call form_add_entity_hiddens even on subforms
sylvain.thenault@logilab.fr
parents: 1305
diff changeset
   441
        return super(EntityFieldsForm, self).form_build_context(values)
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   442
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   443
    def form_add_entity_hiddens(self, eschema):
863
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   444
        for field in self.fields[:]:
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 892
diff changeset
   445
            for field in field.actual_fields(self):
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   446
                fieldname = field.name
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   447
                if fieldname != 'eid' and (
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   448
                    (eschema.has_subject_relation(fieldname) or
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   449
                     eschema.has_object_relation(fieldname))):
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   450
                    field.eidparam = True
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   451
                    self.fields.append(self.form_entity_hidden_field(field))
863
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   452
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   453
    def form_entity_hidden_field(self, field):
863
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   454
        """returns the hidden field which will indicate the value
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   455
        before the modification
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   456
        """
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   457
        # Only RelationField has a `role` attribute, others are used
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   458
        # to describe attribute fields => role is 'subject'
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   459
        if getattr(field, 'role', 'subject') == 'subject':
863
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   460
            name = 'edits-%s' % field.name
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   461
        else:
4fde01fc39ca restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 849
diff changeset
   462
            name = 'edito-%s' % field.name
898
583f64567256 fix HiddenRelationField bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 897
diff changeset
   463
        return HiddenInitialValueField(field, name=name)
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   464
        
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   465
    def form_field_value(self, field, load_bytes=False):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   466
        """return field's *typed* value
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   467
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   468
        overriden to deal with
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   469
        * special eid / __type / edits- / edito- fields
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   470
        * lookup for values on edited entities
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   471
        """
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   472
        attr = field.name
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   473
        entity = self.edited_entity
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   474
        if attr == 'eid':
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   475
            return entity.eid
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   476
        if not field.eidparam:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   477
            return super(EntityFieldsForm, self).form_field_value(field, load_bytes)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   478
        if attr.startswith('edits-') or attr.startswith('edito-'):
888
603327e9aef4 fix field value for hidden edit[s|à] fields
sylvain.thenault@logilab.fr
parents: 887
diff changeset
   479
            # edit[s|o]- fieds must have the actual value stored on the entity
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   480
            assert hasattr(field, 'visible_field')
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   481
            vfield = field.visible_field
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   482
            assert vfield.eidparam
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   483
            if entity.has_eid():
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   484
                return self.form_field_value(vfield)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   485
            return INTERNAL_FIELD_VALUE
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   486
        if attr == '__type':
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   487
            return entity.id
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   488
        if field.role == 'object':
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   489
            attr = 'reverse_' + attr
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   490
        elif entity.e_schema.subject_relation(attr).is_final():
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   491
            attrtype = entity.e_schema.destination(attr)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   492
            if attrtype == 'Password':
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   493
                return entity.has_eid() and INTERNAL_FIELD_VALUE or ''
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   494
            if attrtype == 'Bytes':
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   495
                if entity.has_eid():
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   496
                    if load_bytes:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   497
                        return getattr(entity, attr)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   498
                    # XXX value should reflect if some file is already attached
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   499
                    return True
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   500
                return False
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   501
            if entity.has_eid():
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   502
                value = getattr(entity, attr)
888
603327e9aef4 fix field value for hidden edit[s|à] fields
sylvain.thenault@logilab.fr
parents: 887
diff changeset
   503
            else:
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   504
                value = self._form_field_default_value(field, load_bytes)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   505
            return value
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   506
        # non final relation field
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   507
        if entity.has_eid():
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   508
            value = [ent.eid for ent in getattr(entity, attr)]
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   509
        else:
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   510
            value = self._form_field_default_value(field, load_bytes)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   511
        return value
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   512
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   513
    def _form_field_default_value(self, field, load_bytes):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   514
        defaultattr = 'default_%s' % field.name
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   515
        if hasattr(self.edited_entity, defaultattr):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   516
            # XXX bw compat, default_<field name> on the entity
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   517
            warn('found %s on %s, should be set on a specific form'
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   518
                 % (defaultattr, self.edited_entity.id), DeprecationWarning)
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   519
            value = getattr(self.edited_entity, defaultattr)
848
f5aca5c5f6ca set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents: 847
diff changeset
   520
            if callable(value):
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   521
                value = value()
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   522
        else:
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   523
            value = super(EntityFieldsForm, self).form_field_value(field,
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   524
                                                                   load_bytes)
897
f5b91f11d8b6 provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 896
diff changeset
   525
        return value
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   526
        
1060
d795477ad16b rename method to form_field_format
sylvain.thenault@logilab.fr
parents: 1059
diff changeset
   527
    def form_field_format(self, field):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   528
        entity = self.edited_entity
1107
961a478593a5 has_metadata is a schema method
sylvain.thenault@logilab.fr
parents: 1101
diff changeset
   529
        if field.eidparam and entity.e_schema.has_metadata(field.name, 'format') and (
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   530
            entity.has_eid() or '%s_format' % field.name in entity):
1360
13ae1121835e rename attribute_metadata method to attr_metadata to save a few chars
sylvain.thenault@logilab.fr
parents: 1338
diff changeset
   531
            return self.edited_entity.attr_metadata(field.name, 'format')
892
1558772340a7 rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents: 888
diff changeset
   532
        return self.req.property_value('ui.default-text-format')
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   533
1061
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   534
    def form_field_encoding(self, field):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   535
        entity = self.edited_entity
1107
961a478593a5 has_metadata is a schema method
sylvain.thenault@logilab.fr
parents: 1101
diff changeset
   536
        if field.eidparam and entity.e_schema.has_metadata(field.name, 'encoding') and (
1061
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   537
            entity.has_eid() or '%s_encoding' % field.name in entity):
1360
13ae1121835e rename attribute_metadata method to attr_metadata to save a few chars
sylvain.thenault@logilab.fr
parents: 1338
diff changeset
   538
            return self.edited_entity.attr_metadata(field.name, 'encoding')
1061
7d2e6b5fae3c * new load_bytes argument to form_field_value
sylvain.thenault@logilab.fr
parents: 1060
diff changeset
   539
        return super(EntityFieldsForm, self).form_field_encoding(field)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   540
    
1392
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   541
    
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   542
    def _errex_match_field(self, errex, field):
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   543
        """return true if the field has some error in given validation exception
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   544
        """
d6279efff7b3 refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents: 1391
diff changeset
   545
        return errex.eid == self.edited_entity.eid and field.name in errex.errors
903
63a8ab7eeb9c The value as returned by FieldWidget._render_attrs() is now always a list
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 902
diff changeset
   546
    
849
8591d896db7e update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents: 848
diff changeset
   547
    def form_field_name(self, field):
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   548
        if field.eidparam:
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   549
            return eid_param(field.name, self.edited_entity.eid)
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   550
        return field.name
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   551
849
8591d896db7e update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents: 848
diff changeset
   552
    def form_field_id(self, field):
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   553
        if field.eidparam:
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   554
            return eid_param(field.id, self.edited_entity.eid)
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 844
diff changeset
   555
        return field.id
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   556
        
1031
1a89683cb687 restore limit on form_field_vocabulary, actually used
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
   557
    def form_field_vocabulary(self, field, limit=None):
903
63a8ab7eeb9c The value as returned by FieldWidget._render_attrs() is now always a list
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 902
diff changeset
   558
        role, rtype = field.role, field.name
1265
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   559
        method = '%s_%s_vocabulary' % (role, rtype)
903
63a8ab7eeb9c The value as returned by FieldWidget._render_attrs() is now always a list
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 902
diff changeset
   560
        try:
1265
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   561
            vocabfunc = getattr(self, method)
903
63a8ab7eeb9c The value as returned by FieldWidget._render_attrs() is now always a list
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 902
diff changeset
   562
        except AttributeError:
1265
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   563
            try:
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   564
                # XXX bw compat, <role>_<rtype>_vocabulary on the entity
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   565
                vocabfunc = getattr(self.edited_entity, method)
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   566
            except AttributeError:
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   567
                vocabfunc = getattr(self, '%s_relation_vocabulary' % role)
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   568
            else:
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   569
                warn('found %s on %s, should be set on a specific form'
e5cdd5c0dce3 handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents: 1184
diff changeset
   570
                     % (method, self.edited_entity.id), DeprecationWarning)
1009
bcd0c3ae1935 typos, backport comment
sylvain.thenault@logilab.fr
parents: 944
diff changeset
   571
        # NOTE: it is the responsibility of `vocabfunc` to sort the result
bcd0c3ae1935 typos, backport comment
sylvain.thenault@logilab.fr
parents: 944
diff changeset
   572
        #       (direclty through RQL or via a python sort). This is also
bcd0c3ae1935 typos, backport comment
sylvain.thenault@logilab.fr
parents: 944
diff changeset
   573
        #       important because `vocabfunc` might return a list with
bcd0c3ae1935 typos, backport comment
sylvain.thenault@logilab.fr
parents: 944
diff changeset
   574
        #       couples (label, None) which act as separators. In these
bcd0c3ae1935 typos, backport comment
sylvain.thenault@logilab.fr
parents: 944
diff changeset
   575
        #       cases, it doesn't make sense to sort results afterwards.
1031
1a89683cb687 restore limit on form_field_vocabulary, actually used
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
   576
        return vocabfunc(rtype, limit)
844
8ab6f64c3750 start django like forms
sylvain.thenault@logilab.fr
parents: 765
diff changeset
   577
902
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   578
    def subject_relation_vocabulary(self, rtype, limit=None):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   579
        """defaut vocabulary method for the given relation, looking for
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   580
        relation's object entities (i.e. self is the subject)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   581
        """
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   582
        entity = self.edited_entity
902
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   583
        if isinstance(rtype, basestring):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   584
            rtype = entity.schema.rschema(rtype)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   585
        done = None
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   586
        assert not rtype.is_final(), rtype
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   587
        if entity.has_eid():
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   588
            done = set(e.eid for e in getattr(entity, str(rtype)))
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   589
        result = []
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   590
        rsetsize = None
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   591
        for objtype in rtype.objects(entity.e_schema):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   592
            if limit is not None:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   593
                rsetsize = limit - len(result)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   594
            result += self.relation_vocabulary(rtype, objtype, 'subject',
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   595
                                               rsetsize, done)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   596
            if limit is not None and len(result) >= limit:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   597
                break
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   598
        return result
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   599
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   600
    def object_relation_vocabulary(self, rtype, limit=None):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   601
        """defaut vocabulary method for the given relation, looking for
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   602
        relation's subject entities (i.e. self is the object)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   603
        """
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   604
        entity = self.edited_entity
902
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   605
        if isinstance(rtype, basestring):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   606
            rtype = entity.schema.rschema(rtype)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   607
        done = None
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   608
        if entity.has_eid():
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   609
            done = set(e.eid for e in getattr(entity, 'reverse_%s' % rtype))
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   610
        result = []
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   611
        rsetsize = None
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   612
        for subjtype in rtype.subjects(entity.e_schema):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   613
            if limit is not None:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   614
                rsetsize = limit - len(result)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   615
            result += self.relation_vocabulary(rtype, subjtype, 'object',
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   616
                                               rsetsize, done)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   617
            if limit is not None and len(result) >= limit:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   618
                break
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   619
        return result
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   620
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   621
    def relation_vocabulary(self, rtype, targettype, role,
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   622
                            limit=None, done=None):
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   623
        if done is None:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   624
            done = set()
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   625
        rset = self.edited_entity.unrelated(rtype, targettype, role, limit)
902
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   626
        res = []
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   627
        for entity in rset.entities():
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   628
            if entity.eid in done:
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   629
                continue
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   630
            done.add(entity.eid)
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   631
            res.append((entity.view('combobox'), entity.eid))
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   632
        return res
e4de959c76af vocabulary methods are now defined on forms, not on entities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 901
diff changeset
   633
1175
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   634
    def subject_in_state_vocabulary(self, rschema, limit=None):
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   635
        """vocabulary method for the in_state relation, looking for
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   636
        relation's object entities (i.e. self is the subject) according
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   637
        to initial_state, state_of and next_state relation
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   638
        """
1184
a33deae7c6a2 oops, this method doesn't belong anymore to entity class
sylvain.thenault@logilab.fr
parents: 1183
diff changeset
   639
        entity = self.edited_entity
a33deae7c6a2 oops, this method doesn't belong anymore to entity class
sylvain.thenault@logilab.fr
parents: 1183
diff changeset
   640
        if not entity.has_eid() or not entity.in_state:
1175
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   641
            # get the initial state
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   642
            rql = 'Any S where S state_of ET, ET name %(etype)s, ET initial_state S'
1184
a33deae7c6a2 oops, this method doesn't belong anymore to entity class
sylvain.thenault@logilab.fr
parents: 1183
diff changeset
   643
            rset = self.req.execute(rql, {'etype': str(entity.e_schema)})
1175
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   644
            if rset:
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   645
                return [(rset.get_entity(0, 0).view('combobox'), rset[0][0])]
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   646
            return []
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   647
        results = []
1184
a33deae7c6a2 oops, this method doesn't belong anymore to entity class
sylvain.thenault@logilab.fr
parents: 1183
diff changeset
   648
        for tr in entity.in_state[0].transitions(entity):
1175
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   649
            state = tr.destination_state[0]
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   650
            results.append((state.view('combobox'), state.eid))
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   651
        return sorted(results)
96747df28a1f backport subject_in_state_vocabulary to EntityFieldsForm, deprecate the old one
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
   652
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   653
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   654
class CompositeForm(FieldsForm):
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   655
    """form composed for sub-forms"""
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   656
    
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   657
    def __init__(self, *args, **kwargs):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   658
        super(CompositeForm, self).__init__(*args, **kwargs)
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   659
        self.forms = []
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   660
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   661
    def form_add_subform(self, subform):
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1133
diff changeset
   662
        subform.is_subform = True
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 867
diff changeset
   663
        self.forms.append(subform)