Remove use of screen.current_record and screen.group from views
issue8067 review62411002
This commit is contained in:
1 parent
a5d0aec172
commit
4d0a2f13ca
5 files changed
+56
-48
No files matched your search
@@ -25,6 +25,18 @@ class View(object):
|
||||
def get_fields(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def record(self):
|
||||
return self.screen.current_record
|
||||
|
||||
@record.setter
|
||||
def record(self, value):
|
||||
self.screen.current_record = value
|
||||
|
||||
@property
|
||||
def group(self):
|
||||
return self.screen.group
|
||||
|
||||
@property
|
||||
def selected_records(self):
|
||||
return []
|
||||
|
||||
@@ -76,7 +76,7 @@ class ViewCalendar(View):
|
||||
self.screen.search_filter()
|
||||
|
||||
def on_event_pressed(self, goocalendar, event):
|
||||
self.screen.current_record = event.record
|
||||
self.record = event.record
|
||||
|
||||
def on_event_activated(self, goocalendar, event):
|
||||
self.screen.switch_view('form')
|
||||
@@ -104,7 +104,7 @@ class ViewCalendar(View):
|
||||
record.save()
|
||||
|
||||
def on_day_pressed(self, goocalendar, day):
|
||||
self.screen.current_record = None
|
||||
self.record = None
|
||||
|
||||
def on_day_activated(self, goocalendar, day):
|
||||
self.screen.new()
|
||||
@@ -140,7 +140,7 @@ class ViewCalendar(View):
|
||||
|
||||
@goocalendar_required
|
||||
def display(self):
|
||||
self.widgets['goocalendar'].display(self.screen.group)
|
||||
self.widgets['goocalendar'].display(self.group)
|
||||
|
||||
def set_cursor(self, new=False, reset_view=True):
|
||||
pass
|
||||
|
||||
@@ -232,7 +232,7 @@ class ViewForm(View):
|
||||
|
||||
def _parse_separator(self, node, container, attributes):
|
||||
if 'name' in attributes:
|
||||
field = self.screen.group.fields[attributes['name']]
|
||||
field = self.group.fields[attributes['name']]
|
||||
for attr in ('states', 'string'):
|
||||
if attr not in attributes and attr in field.attrs:
|
||||
attributes[attr] = field.attrs[attr]
|
||||
@@ -249,7 +249,7 @@ class ViewForm(View):
|
||||
|
||||
def _parse_label(self, node, container, attributes):
|
||||
if 'name' in attributes:
|
||||
field = self.screen.group.fields[attributes['name']]
|
||||
field = self.group.fields[attributes['name']]
|
||||
if attributes['name'] == self.screen.exclude_field:
|
||||
container.add(None, attributes)
|
||||
return
|
||||
@@ -309,7 +309,7 @@ class ViewForm(View):
|
||||
def _parse_page(self, node, notebook, attributes):
|
||||
tab_box = gtk.HBox(spacing=3)
|
||||
if 'name' in attributes:
|
||||
field = self.screen.group.fields[attributes['name']]
|
||||
field = self.group.fields[attributes['name']]
|
||||
if attributes['name'] == self.screen.exclude_field:
|
||||
return
|
||||
for attr in ('states', 'string'):
|
||||
@@ -338,9 +338,9 @@ class ViewForm(View):
|
||||
|
||||
def _parse_field(self, node, container, attributes):
|
||||
name = attributes['name']
|
||||
field = self.screen.group.fields[name]
|
||||
field = self.group.fields[name]
|
||||
|
||||
if (name not in self.screen.group.fields
|
||||
if (name not in self.group.fields
|
||||
or name == self.screen.exclude_field):
|
||||
container.add(None, attributes)
|
||||
return
|
||||
@@ -378,7 +378,7 @@ class ViewForm(View):
|
||||
def _parse_group(self, node, container, attributes):
|
||||
group = self.parse(node)
|
||||
if 'name' in attributes:
|
||||
field = self.screen.group.fields[attributes['name']]
|
||||
field = self.group.fields[attributes['name']]
|
||||
if attributes['name'] == self.screen.exclude_field:
|
||||
container.add(None, attributes)
|
||||
return
|
||||
@@ -472,7 +472,7 @@ class ViewForm(View):
|
||||
self.widget.destroy()
|
||||
|
||||
def set_value(self, focused_widget=False):
|
||||
record = self.screen.current_record
|
||||
record = self.record
|
||||
if record:
|
||||
for name, widgets in self.widgets.items():
|
||||
if name in record.group.fields:
|
||||
@@ -485,8 +485,8 @@ class ViewForm(View):
|
||||
|
||||
@property
|
||||
def selected_records(self):
|
||||
if self.screen.current_record:
|
||||
return [self.screen.current_record]
|
||||
if self.record:
|
||||
return [self.record]
|
||||
return []
|
||||
|
||||
@property
|
||||
@@ -498,7 +498,7 @@ class ViewForm(View):
|
||||
return [b for b in self.state_widgets if isinstance(b, gtk.Button)]
|
||||
|
||||
def reset(self):
|
||||
record = self.screen.current_record
|
||||
record = self.record
|
||||
if record:
|
||||
for name, widgets in self.widgets.items():
|
||||
field = record.group.fields.get(name)
|
||||
@@ -508,7 +508,7 @@ class ViewForm(View):
|
||||
widget.display()
|
||||
|
||||
def display(self):
|
||||
record = self.screen.current_record
|
||||
record = self.record
|
||||
if record:
|
||||
# Force to set fields in record
|
||||
# Get first the lazy one from the view to reduce number of requests
|
||||
@@ -553,7 +553,7 @@ class ViewForm(View):
|
||||
child = find_focusable_child(self._viewport)
|
||||
if child:
|
||||
child.grab_focus()
|
||||
record = self.screen.current_record
|
||||
record = self.record
|
||||
if record:
|
||||
invalid_widgets = []
|
||||
for name in record.invalid_fields:
|
||||
|
||||
@@ -38,7 +38,7 @@ class Widget(object):
|
||||
|
||||
@property
|
||||
def record(self):
|
||||
return self.view.screen.current_record
|
||||
return self.view.record
|
||||
|
||||
@property
|
||||
def field(self):
|
||||
|
||||
@@ -316,7 +316,7 @@ class ViewTree(View):
|
||||
self.add_last_column()
|
||||
|
||||
def _parse_field(self, node):
|
||||
group = self.screen.group
|
||||
group = self.group
|
||||
node_attrs = node_attributes(node)
|
||||
name = node_attrs['name']
|
||||
field = group.fields[name]
|
||||
@@ -585,7 +585,7 @@ class ViewTree(View):
|
||||
def set_drag_and_drop(self):
|
||||
dnd = False
|
||||
if self.children_field:
|
||||
children = self.screen.group.fields.get(self.children_field)
|
||||
children = self.group.fields.get(self.children_field)
|
||||
if children:
|
||||
parent_name = children.attrs.get('relation_field')
|
||||
dnd = parent_name in self.widgets
|
||||
@@ -654,7 +654,7 @@ class ViewTree(View):
|
||||
def test_expand_row(self, widget, iter_, path):
|
||||
model = widget.get_model()
|
||||
if model.iter_n_children(iter_) > CONFIG['client.limit']:
|
||||
self.screen.current_record = model.get_value(iter_, 0)
|
||||
self.record = model.get_value(iter_, 0)
|
||||
self.screen.switch_view('form')
|
||||
return True
|
||||
iter_ = model.iter_children(iter_)
|
||||
@@ -718,12 +718,12 @@ class ViewTree(View):
|
||||
if col in columns:
|
||||
idx = columns.index(col)
|
||||
columns = columns[idx:]
|
||||
if self.screen.current_record:
|
||||
record = self.screen.current_record
|
||||
if self.record:
|
||||
record = self.record
|
||||
group = record.group
|
||||
idx = group.index(record)
|
||||
else:
|
||||
group = self.screen.group
|
||||
group = self.group
|
||||
idx = len(group)
|
||||
default = None
|
||||
for line in data:
|
||||
@@ -745,7 +745,7 @@ class ViewTree(View):
|
||||
if not record.validate():
|
||||
break
|
||||
idx += 1
|
||||
self.screen.current_record = record
|
||||
self.record = record
|
||||
self.screen.display(set_cursor=True)
|
||||
|
||||
def drag_data_get(self, treeview, context, selection, target_id,
|
||||
@@ -768,8 +768,8 @@ class ViewTree(View):
|
||||
info, etime):
|
||||
treeview.emit_stop_by_name('drag-data-received')
|
||||
if self.attributes.get('sequence'):
|
||||
field = self.screen.group.fields[self.attributes['sequence']]
|
||||
for record in self.screen.group:
|
||||
field = self.group.fields[self.attributes['sequence']]
|
||||
for record in self.group:
|
||||
if field.get_state_attrs(
|
||||
record).get('readonly', False):
|
||||
return
|
||||
@@ -895,7 +895,7 @@ class ViewTree(View):
|
||||
|
||||
selection = treeview.get_selection()
|
||||
if selection.count_selected_rows() == 1:
|
||||
group = self.screen.group
|
||||
group = self.group
|
||||
if selection.get_mode() == gtk.SELECTION_SINGLE:
|
||||
model = selection.get_selected()[0]
|
||||
elif selection.get_mode() == gtk.SELECTION_MULTIPLE:
|
||||
@@ -972,7 +972,7 @@ class ViewTree(View):
|
||||
treeview.expand_row(path, False)
|
||||
|
||||
def __select_changed(self, tree_sel):
|
||||
previous_record = self.screen.current_record
|
||||
previous_record = self.record
|
||||
if previous_record and previous_record not in previous_record.group:
|
||||
previous_record = None
|
||||
|
||||
@@ -980,25 +980,24 @@ class ViewTree(View):
|
||||
model, iter_ = tree_sel.get_selected()
|
||||
if model and iter_:
|
||||
record = model.get_value(iter_, 0)
|
||||
self.screen.current_record = record
|
||||
self.record = record
|
||||
else:
|
||||
self.screen.current_record = None
|
||||
self.record = None
|
||||
|
||||
elif tree_sel.get_mode() == gtk.SELECTION_MULTIPLE:
|
||||
model, paths = tree_sel.get_selected_rows()
|
||||
if model and paths:
|
||||
iter_ = model.get_iter(paths[0])
|
||||
record = model.get_value(iter_, 0)
|
||||
self.screen.current_record = record
|
||||
self.record = record
|
||||
else:
|
||||
self.screen.current_record = None
|
||||
self.record = None
|
||||
|
||||
if self.editable and previous_record:
|
||||
def go_previous():
|
||||
self.screen.current_record = previous_record
|
||||
self.record = previous_record
|
||||
self.set_cursor()
|
||||
if (not self.screen.parent
|
||||
and previous_record != self.screen.current_record):
|
||||
if not self.screen.parent and previous_record != self.record:
|
||||
|
||||
def save():
|
||||
if not previous_record.destroyed:
|
||||
@@ -1010,8 +1009,7 @@ class ViewTree(View):
|
||||
return True
|
||||
# Delay the save to let GTK process the current event
|
||||
gobject.idle_add(save)
|
||||
elif (previous_record != self.screen.current_record
|
||||
and self.screen.pre_validate):
|
||||
elif previous_record != self.record and self.screen.pre_validate:
|
||||
|
||||
def pre_validate():
|
||||
if not previous_record.destroyed:
|
||||
@@ -1030,16 +1028,14 @@ class ViewTree(View):
|
||||
|
||||
def display(self):
|
||||
self.treeview.display_counter += 1
|
||||
current_record = self.screen.current_record
|
||||
current_record = self.record
|
||||
if (self.reload
|
||||
or not self.treeview.get_model()
|
||||
or (self.screen.group !=
|
||||
self.treeview.get_model().group)):
|
||||
model = AdaptModelGroup(self.screen.group,
|
||||
self.children_field)
|
||||
or self.group != self.treeview.get_model().group):
|
||||
model = AdaptModelGroup(self.group, self.children_field)
|
||||
self.treeview.set_model(model)
|
||||
# __select_changed resets current_record to None
|
||||
self.screen.current_record = current_record
|
||||
self.record = current_record
|
||||
if current_record:
|
||||
selection = self.treeview.get_selection()
|
||||
path = current_record.get_index_path(model.group)
|
||||
@@ -1080,7 +1076,7 @@ class ViewTree(View):
|
||||
column.set_visible(not unique or bool(self.children_field))
|
||||
|
||||
def set_state(self):
|
||||
record = self.screen.current_record
|
||||
record = self.record
|
||||
if record:
|
||||
for field in record.group.fields:
|
||||
field = record.group.fields.get(field, None)
|
||||
@@ -1095,8 +1091,8 @@ class ViewTree(View):
|
||||
selected_sum = None
|
||||
loaded = True
|
||||
digit = 0
|
||||
field = self.screen.group.fields[name]
|
||||
for record in self.screen.group:
|
||||
field = self.group.fields[name]
|
||||
for record in self.group:
|
||||
if not record.get_loaded([name]) and record.id >= 0:
|
||||
loaded = False
|
||||
break
|
||||
@@ -1120,7 +1116,7 @@ class ViewTree(View):
|
||||
|
||||
if loaded:
|
||||
if field.attrs['type'] == 'timedelta':
|
||||
converter = field.converter(self.screen.group)
|
||||
converter = field.converter(self.group)
|
||||
selected_sum = common.timedelta.format(
|
||||
selected_sum, converter)
|
||||
sum_ = common.timedelta.format(sum_, converter)
|
||||
@@ -1141,8 +1137,8 @@ class ViewTree(View):
|
||||
def set_cursor(self, new=False, reset_view=True):
|
||||
self.treeview.grab_focus()
|
||||
model = self.treeview.get_model()
|
||||
if self.screen.current_record and model:
|
||||
path = self.screen.current_record.get_index_path(model.group)
|
||||
if self.record and model:
|
||||
path = self.record.get_index_path(model.group)
|
||||
if model.get_flags() & gtk.TREE_MODEL_LIST_ONLY:
|
||||
path = (path[0],)
|
||||
focus_column = self.treeview.next_column(path, editable=new)
|
||||
|
||||
Reference in new issue
Block a user