author | sylvain.thenault@logilab.fr |
Thu, 12 Mar 2009 16:33:47 +0100 | |
branch | tls-sprint |
changeset 1096 | e1fe98850bf7 |
parent 1091 | b5e253c0dd13 |
child 1132 | 96752791c2b6 |
permissions | -rw-r--r-- |
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 copy import copy |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
from simplejson import dumps |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
from logilab.mtconverter import html_escape |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
from logilab.common.decorators import cached |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
16 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
from cubicweb.selectors import (specified_etype_implements, implements, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
18 |
match_kwargs, match_form_params, one_line_rset, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
non_final_entity, accepts_etype_compat) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
from cubicweb.utils import make_uid |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
from cubicweb.view import View, EntityView |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
from cubicweb.common import tags |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
from cubicweb.common.uilib import cut |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, eid_param |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
from cubicweb.web.controller import NAV_FORM_PARAMETERS |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
from cubicweb.web.form import MultipleFieldsForm, EntityFieldsForm, FormMixIn, FormRenderer |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
from cubicweb.web.formfields import StringField, RichTextField, guess_field |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
from cubicweb.web.formwidgets import HiddenInput |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
_ = unicode |
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 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
class DeleteConfForm(EntityView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
id = 'deleteconf' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
title = _('delete') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
domid = 'deleteconf' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
onsubmit = None |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
# 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
|
39 |
# else we will only delete the displayed page |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
need_navigation = False |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
def call(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
"""ask for confirmation before real deletion""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
req, w = self.req, self.w |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
_ = req._ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
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
|
47 |
% _('this action is not reversible!')) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
# XXX above message should have style of a warning |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
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
|
50 |
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
|
51 |
onsubmit=self.onsubmit, copy_nav_params=True) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
form.buttons.append(form.button_delete(label=stdmsgs.YES)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
form.buttons.append(form.button_cancel(label=stdmsgs.NO)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
done = set() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
w(u'<ul>\n') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
for i in xrange(self.rset.rowcount): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
if self.rset[i][0] in done: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
continue |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
done.add(self.rset[i][0]) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
entity = self.rset.get_entity(i, 0) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
subform = EntityFieldsForm(req, set_error_url=False, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
entity=entity) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
form.form_add_subform(subform) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
# 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
|
65 |
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
|
66 |
href=entity.absolute_url())) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
w(u'</ul>\n') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
w(form.form_render()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
class ClickAndEditForm(FormMixIn, EntityView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
id = 'reledit' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
__select__ = non_final_entity() & match_kwargs('rtype') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
# FIXME editableField class could be toggleable from userprefs |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
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
|
78 |
entity = self.entity(row, col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
if getattr(entity, rtype) is None: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
value = self.req._('not specified') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
else: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
value = entity.printable_value(rtype) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
if not entity.has_perm('update'): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
self.w(value) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
return |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
self.req.add_js( ('cubicweb.ajax.js',) ) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
87 |
eid = entity.eid |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
edit_key = make_uid('%s-%s' % (rtype, eid)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
divid = 'd%s' % edit_key |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
reload = dumps(reload) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
tags.input(klass="validateButton", type="button", |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
value=self.req._(stdmsgs.BUTTON_CANCEL), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" % (eid, rtype, divid), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
tabindex=self.req.next_tabindex())] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
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
|
98 |
entity=entity, domid='%s-form' % divid, action='#', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
cssstyle='display: none', buttons=buttons, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
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
|
101 |
renderer = FormRenderer(display_label=False, display_help=False, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
display_fields=(rtype,), button_bar_class='buttonbar') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
self.w(tags.div(value, klass='editableField', id=divid, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
ondblclick="showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')" % locals())) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
self.w(form.render(renderer=renderer)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
106 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
108 |
class AutomaticEntityForm(EntityFieldsForm): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
109 |
id = 'edition' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
110 |
needs_js = EntityFieldsForm.needs_js + ('cubicweb.ajax.js',) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
111 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
112 |
def __init__(self, *args, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
super(AutomaticEntityForm, self).__init__(*args, **kwargs) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
self.entity.complete() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
for rschema, target in self.editable_attributes(entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
116 |
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
|
117 |
self.fields.append(field) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
118 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
def form_buttons(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
120 |
return [self.button_ok(tabindex=self.req.next_tabindex()), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
121 |
self.button_apply(tabindex=self.req.next_tabindex()), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
self.button_cancel(tabindex=self.req.next_tabindex())] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
123 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
124 |
def editable_attributes(self, entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
# XXX both (add, delete) required for non final relations |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
126 |
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
|
127 |
if rschema != 'eid'] |
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 |
class _EditionForm(EntityView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
130 |
"""primary entity edition form |
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 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
being connected |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
137 |
""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
id = 'edition' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
139 |
__select__ = one_line_rset() & non_final_entity() |
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 |
title = _('edition') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
142 |
controller = 'edit' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
143 |
skip_relations = FormMixIn.skip_relations.copy() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
145 |
def cell_call(self, row, col, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
self.req.add_js( ('cubicweb.ajax.js',) ) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
self.initialize_varmaker() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
148 |
entity = self.complete_entity(row, col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
149 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
def initialize_varmaker(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
151 |
varmaker = self.req.get_page_data('rql_varmaker') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
152 |
if varmaker is None: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
153 |
varmaker = self.req.varmaker |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
self.req.set_page_data('rql_varmaker', varmaker) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
self.varmaker = varmaker |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
157 |
def edit_form(self, entity, kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
158 |
form = EntityFieldsForm(self.req, entity=entity) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
159 |
for rschema, target in self.editable_attributes(entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
160 |
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
|
161 |
form.fields.append(field) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
162 |
form.buttons.append(form.button_ok()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
163 |
form.buttons.append(form.button_apply()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
164 |
form.buttons.append(form.button_cancel()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
self.w(form.form_render()) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
167 |
def editable_attributes(self, entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
168 |
# XXX both (add, delete) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
169 |
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
|
170 |
if rschema != 'eid'] |