web/views/editforms.py
author sylvain.thenault@logilab.fr
Wed, 25 Mar 2009 10:40:22 +0100
branchtls-sprint
changeset 1138 22f634977c95
parent 1135 00eb43688a57
child 1147 402e8a8b1d6a
permissions -rw-r--r--
make pylint happy, fix some bugs on the way
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
"""Set of HTML automatic forms to create, delete, copy or edit a single entity
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
or a list of entities of the same type
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
:organization: Logilab
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
__docformat__ = "restructuredtext en"
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
from simplejson import dumps
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    12
from cubicweb.selectors import match_kwargs, one_line_rset, non_final_entity
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
from cubicweb.utils import make_uid
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    14
from cubicweb.view import EntityView
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
from cubicweb.common import tags
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    16
from cubicweb.web import stdmsgs
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
from cubicweb.web.form import MultipleFieldsForm, EntityFieldsForm, FormMixIn, FormRenderer
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    18
from cubicweb.web.formfields import guess_field
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
_ = unicode
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
class DeleteConfForm(EntityView):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
    id = 'deleteconf'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
    title = _('delete')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
    domid = 'deleteconf'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
    onsubmit = None
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
    # don't use navigation, all entities asked to be deleted should be displayed
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
    # else we will only delete the displayed page
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
    need_navigation = False
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
    
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
    def call(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
        """ask for confirmation before real deletion"""
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
        req, w = self.req, self.w
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
        _ = req._
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
        w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
          % _('this action is not reversible!'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
        # XXX above message should have style of a warning
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
        w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
        form = MultipleFieldsForm(req, domid='deleteconf', action=self.build_url('edit'),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
                                  onsubmit=self.onsubmit, copy_nav_params=True)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
        form.buttons.append(form.button_delete(label=stdmsgs.YES))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
        form.buttons.append(form.button_cancel(label=stdmsgs.NO))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
        done = set()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
        w(u'<ul>\n')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
        for i in xrange(self.rset.rowcount):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
            if self.rset[i][0] in done:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
                continue
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
            done.add(self.rset[i][0])
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
            entity = self.rset.get_entity(i, 0)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
            subform = EntityFieldsForm(req, set_error_url=False,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
                                       entity=entity)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
            form.form_add_subform(subform)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    54
            # don't use outofcontext view or any other that may contain inline edition form
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    55
            w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
                                      href=entity.absolute_url()))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
        w(u'</ul>\n')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
        w(form.form_render())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
class ClickAndEditForm(FormMixIn, EntityView):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
    id = 'reledit'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
    __select__ = non_final_entity() & match_kwargs('rtype')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
    # FIXME editableField class could be toggleable from userprefs
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
      
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
    def cell_call(self, row, col, rtype=None, role='subject', reload=False):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
        entity = self.entity(row, col)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        if getattr(entity, rtype) is None:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
            value = self.req._('not specified')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
        else:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
            value = entity.printable_value(rtype)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
        if not entity.has_perm('update'):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
            self.w(value)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
            return
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
        self.req.add_js( ('cubicweb.ajax.js',) )
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
        eid = entity.eid
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
        edit_key = make_uid('%s-%s' % (rtype, eid))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
        divid = 'd%s' % edit_key
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
        reload = dumps(reload)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
        buttons = [tags.input(klass="validateButton", type="submit", name="__action_apply",
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
                              value=self.req._(stdmsgs.BUTTON_OK), tabindex=self.req.next_tabindex()),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
                   tags.input(klass="validateButton", type="button",
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
                              value=self.req._(stdmsgs.BUTTON_CANCEL),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
                              onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" % (eid, rtype, divid),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
                              tabindex=self.req.next_tabindex())]
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
        form = self.vreg.select_object('forms', 'edition', self.req, self.rset, row=row, col=col,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
                                       entity=entity, domid='%s-form' % divid, action='#',
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
                                       cssstyle='display: none', buttons=buttons,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
                                       onsubmit="return inlineValidateForm('%(divid)s-form', '%(rtype)s', '%(eid)s', '%(divid)s', %(reload)s);" % locals())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
        renderer = FormRenderer(display_label=False, display_help=False,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
                                display_fields=(rtype,), button_bar_class='buttonbar')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
        self.w(tags.div(value, klass='editableField', id=divid,
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
                        ondblclick="showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')" % locals()))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
        self.w(form.render(renderer=renderer))
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
class AutomaticEntityForm(EntityFieldsForm):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
    id = 'edition'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
    needs_js = EntityFieldsForm.needs_js + ('cubicweb.ajax.js',)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   101
    
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   102
    def __init__(self, *args, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   103
        super(AutomaticEntityForm, self).__init__(*args, **kwargs)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   104
        self.entity.complete()
1135
00eb43688a57 pylint detected errors
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   105
        for rschema, target in self.editable_attributes(self.entity):
1138
22f634977c95 make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   106
            field = guess_field(self.entity.__class__, self.entity.e_schema,
22f634977c95 make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   107
                                rschema, target)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   108
            self.fields.append(field)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
            
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   110
    def form_buttons(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   111
        return [self.button_ok(tabindex=self.req.next_tabindex()),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
                self.button_apply(tabindex=self.req.next_tabindex()),
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   113
                self.button_cancel(tabindex=self.req.next_tabindex())]
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   115
    def editable_attributes(self, entity):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   116
        # XXX both (add, delete) required for non final relations
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
        return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary', 'secondary'), 'add')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   118
                if rschema != 'eid']
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   119
    
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
class _EditionForm(EntityView):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
    """primary entity edition form
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
    When generating a new attribute_input, the editor will look for a method
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   124
    named 'default_ATTRNAME' on the entity instance, where ATTRNAME is the
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
    name of the attribute being edited. You may use this feature to compute
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   126
    dynamic default values such as the 'tomorrow' date or the user's login
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
    being connected
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
    """    
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
    id = 'edition'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
    __select__ = one_line_rset() & non_final_entity()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   132
    title = _('edition')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   133
    controller = 'edit'
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   134
    skip_relations = FormMixIn.skip_relations.copy()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   135
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   136
    def cell_call(self, row, col, **kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   137
        self.req.add_js( ('cubicweb.ajax.js',) )
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
        self.initialize_varmaker()
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   139
        entity = self.complete_entity(row, col)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   140
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   141
    def initialize_varmaker(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
        varmaker = self.req.get_page_data('rql_varmaker')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
        if varmaker is None:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   144
            varmaker = self.req.varmaker
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   145
            self.req.set_page_data('rql_varmaker', varmaker)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   146
        self.varmaker = varmaker
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   147
        
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   148
    def edit_form(self, entity, kwargs):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   149
        form = EntityFieldsForm(self.req, entity=entity)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
        for rschema, target in self.editable_attributes(entity):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   151
            field = guess_field(entity.__class__, entity.e_schema, rschema, target)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
            form.fields.append(field)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
        form.buttons.append(form.button_ok())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   154
        form.buttons.append(form.button_apply())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   155
        form.buttons.append(form.button_cancel())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   156
        self.w(form.form_render())
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   157
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   158
    def editable_attributes(self, entity):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   159
        # XXX both (add, delete)
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   160
        return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary', 'secondary'), 'add')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff changeset
   161
                if rschema != 'eid']