Better exclude fields for One2Many

- exclude fields on the screen level
- form parser don't put empty widget in table, it just skip it
This commit is contained in:
Cédric Krier committed 2008-03-07 11:56:13 +01:00
1 parent 09a638f257
commit 670d4ecfe7
3 files changed
+24 -9

No files matched your search

+6 -6
View File
@@ -16,7 +16,7 @@ class Screen(SignalEvent):
parent=None, context=None, views_preload=None, tree_saves=True,
domain=None, create_new=False, row_activate=None, hastoolbar=False,
default_get=None, show_search=False, window=None, limit=80,
readonly=False, form=None):
readonly=False, form=None, exclude_field=None):
if view_ids is None:
view_ids = []
if view_type is None:
@@ -69,6 +69,7 @@ class Screen(SignalEvent):
self.readonly = readonly
self.form = form
self.fields_view_tree = None
self.exclude_field = exclude_field
if view_type:
self.view_to_load = view_type[1:]
@@ -219,8 +220,7 @@ class Screen(SignalEvent):
def add_view_custom(self, arch, fields, display=False, toolbar=None):
return self.add_view(arch, fields, display, True, toolbar=toolbar)
def add_view_id(self, view_id, view_type, display=False,
exclude_field=None, context=None):
def add_view_id(self, view_id, view_type, display=False, context=None):
if view_type in self.views_preload:
return self.add_view(self.views_preload[view_type]['arch'],
self.views_preload[view_type]['fields'], display,
@@ -233,9 +233,9 @@ class Screen(SignalEvent):
except Exception, exception:
rpc.process_exception(exception, self.window)
raise
if exclude_field:
if exclude_field in view['fields']:
del view['fields'][exclude_field]
if self.exclude_field:
if self.exclude_field in view['fields']:
del view['fields'][self.exclude_field]
return self.add_view(view['arch'], view['fields'], display,
toolbar=view.get('toolbar', False), context=context)
@@ -58,7 +58,8 @@ class Dialog(object):
self.dia.show_all()
self.screen = Screen(model_name, view_type=[], parent=parent,
window=self.dia)
window=self.dia,
exclude_field=attrs.get('relation_field', None))
self.screen.models._context.update(model_ctx)
if not model:
model = self.screen.new(context=default_get_ctx)
@@ -74,7 +75,6 @@ class Dialog(object):
context=default_get_ctx)
else:
self.screen.add_view_id(False, 'form', display=True,
exclude_field=attrs.get('relation_field', None),
context=default_get_ctx)
viewport.add(self.screen.widget)
width, height = self.screen.screen_container.size_get()
@@ -218,7 +218,8 @@ class One2Many(WidgetInterface):
parent=self.parent, views_preload=attrs.get('views', {}),
tree_saves=attrs.get('saves', False), create_new=True,
row_activate=self._on_activate,
default_get=attrs.get('default_get', {}), window=self._window)
default_get=attrs.get('default_get', {}), window=self._window,
exclude_field=attrs.get('relation_field', None))
self.screen.signal_connect(self, 'record-message', self._sig_label)
menuitem_title.get_child().set_text(self.screen.current_view.title)
@@ -200,6 +200,15 @@ class _container(object):
wid_list.reverse()
table.set_focus_chain(wid_list)
def empty_add(self, colspan=1):
(table, width, height) = self.cont[-1]
if colspan > self.col[-1]:
colspan = self.col[-1]
if colspan + width > self.col[-1]:
self.newline()
(table, width, height) = self.cont[-1]
self.cont[-1] = (table, width + colspan, height)
class ParserForm(ParserInterface):
@@ -267,6 +276,9 @@ class ParserForm(ParserInterface):
text += node.data
else:
text += node.toxml()
if not text:
container.empty_add(int(attrs.get('colspan', 1)))
continue
label = Label(text, attrs)
button_list.append(label)
label.set_use_markup(True)
@@ -343,11 +355,13 @@ class ParserForm(ParserInterface):
name = str(attrs['name'])
del attrs['name']
if name not in fields:
container.empty_add(int(attrs.get('colspan', 1)))
continue
ftype = attrs.get('widget', fields[name]['type'])
fields[name].update(attrs)
fields[name]['model'] = model
if not ftype in WIDGETS_TYPE:
container.empty_add(int(attrs.get('colspan', 1)))
continue
fields[name]['name'] = name