def display(self): super(DictWidget, self).display() if not self.field: return record_id = self.record.id if self.record else None if record_id != self._record_id: for key in list(self.fields.keys()): self._sig_remove(None, key, modified=False) self._record_id = record_id value = self.field.get_client(self.record) if self.field else {} new_key_names = set(value.keys()) - set(self.field.keys) if new_key_names: self.field.add_keys(list(new_key_names), self.record) decoder = PYSONDecoder() for key, val in sorted(value.items()): if key not in self.field.keys: continue if key not in self.fields: self.add_line(key) widget = self.fields[key] widget.set_value(val) widget.set_readonly(self._readonly) key_domain = decoder.decode(self.field.keys[key].get('domain') or '[]') widget_class(widget.widget, 'invalid', not eval_domain(key_domain, value)) for key in set(self.fields.keys()) - set(value.keys()): self._sig_remove(None, key, modified=False) self._set_button_sensitive()
def display(self): super(DictWidget, self).display() if not self.field: return record_id = self.record.id if self.record else None if record_id != self._record_id: for key in list(self.fields.keys()): self._sig_remove(None, key, modified=False) self._record_id = record_id value = self.field.get_client(self.record) if self.field else {} new_key_names = set(value.keys()) - set(self.field.keys) if new_key_names: self.field.add_keys(list(new_key_names), self.record) decoder = PYSONDecoder() # ABDC: Allow dictschema to be ordered by a sequence value_ordered = OrderedDict() use_sequence = any( x[1].get('sequence_order', None) for x in self.field.keys.items()) if use_sequence: for skey, svalues in sorted(self.field.keys.items(), key=lambda x: x[1]['sequence_order']): if skey not in value: continue value_ordered[skey] = value[skey] def _loop_order_hook(): if use_sequence: return value_ordered.items() else: return ((key, val) for key, val in sorted(value.items())) for key, val in _loop_order_hook(): if key not in self.field.keys: continue if key not in self.fields: self.add_line(key) widget = self.fields[key] widget.set_value(val) widget.set_readonly(self._readonly) key_domain = decoder.decode( self.field.keys[key].get('domain') or '[]') widget_class( widget.widget, 'invalid', not eval_domain(key_domain, value)) for key in set(self.fields.keys()) - set(value.keys()): self._sig_remove(None, key, modified=False) self._set_button_sensitive()