示例#1
0
 def validate(self, record, softvalidation=False, pre_validate=None):
     if self.attrs.get('readonly'):
         return True
     invalid = False
     self.get_state_attrs(record)['domain_readonly'] = False
     domain = simplify(self.validation_domains(record, pre_validate))
     if not softvalidation:
         if not self.check_required(record):
             invalid = 'required'
             logging.getLogger('root').debug('Field %s of %s is required' %
                                             (self.name, record.model_name))
     if isinstance(domain, bool):
         if not domain:
             invalid = 'domain'
             logging.getLogger('root').debug(
                 'Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     elif domain == [('id', '=', None)]:
         invalid = 'domain'
         logging.getLogger('root').debug(
             'Invalid domain on Field %s of'
             ' %s : %s' % (self.name, record.model_name, str(domain)))
     else:
         unique, leftpart, value = unique_value(domain)
         if unique:
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             group_domain = record.group.get_domain()
             if group_domain:
                 original_domain = merge(group_domain)
             else:
                 original_domain = merge(domain)
             domain_readonly = original_domain[0] == 'AND'
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 constraintfields = set()
                 if domain_readonly:
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault and not pre_validate:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         if not eval_domain(domain, EvalEnvironment(record)):
             invalid = domain
             logging.getLogger('root').debug(
                 'Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     self.get_state_attrs(record)['invalid'] = invalid
     return not invalid
示例#2
0
文件: field.py 项目: coopengo/tryton
 def validate(self, record, softvalidation=False, pre_validate=None):
     if self.attrs.get('readonly'):
         return True
     invalid = False
     self.get_state_attrs(record)['domain_readonly'] = False
     domain = simplify(self.validation_domains(record, pre_validate))
     if not softvalidation:
         if not self.check_required(record):
             invalid = 'required'
             logging.getLogger('root').debug('Field %s of %s is required' %
                 (self.name, record.model_name))
     if isinstance(domain, bool):
         if not domain:
             invalid = 'domain'
             logging.getLogger('root').debug('Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     elif domain == [('id', '=', None)]:
         invalid = 'domain'
         logging.getLogger('root').debug('Invalid domain on Field %s of'
             ' %s : %s' % (self.name, record.model_name, str(domain)))
     else:
         unique, leftpart, value = unique_value(domain)
         if unique:
             # If the inverted domain is so constraint that only one value
             # is possible we should use it. But we must also pay attention
             # to the fact that the original domain might be a 'OR' domain
             # and thus not preventing the modification of fields.
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             group_domain = record.group.get_domain()
             if group_domain:
                 original_domain = merge(group_domain)
             else:
                 original_domain = merge(domain)
             domain_readonly = original_domain[0] == 'AND'
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 constraintfields = set()
                 if domain_readonly:
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault and not pre_validate:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         if not eval_domain(domain, EvalEnvironment(record)):
             invalid = domain
             logging.getLogger('root').debug('Invalid domain on Field %s of'
                 ' %s : %s' % (self.name, record.model_name, str(domain)))
     self.get_state_attrs(record)['invalid'] = invalid
     return not invalid
示例#3
0
文件: list.py 项目: masking/tryton
    def display(self, force=False):
        self.treeview.display_counter += 1
        current_record = self.record
        if (force or not self.treeview.get_model()
                or self.group != self.treeview.get_model().group):
            model = AdaptModelGroup(self.group, self.children_field,
                                    self.children_definitions)
            self.treeview.set_model(model)
            # __select_changed resets current_record to None
            self.record = current_record
            if current_record:
                selection = self.treeview.get_selection()
                path = current_record.get_index_path(model.group)
                # JCA : Check selection is not empty before updateing path
                if selection:
                    selection.select_path(path)
        if not current_record:
            selection = self.treeview.get_selection()
            selection.unselect_all()
        self.treeview.queue_draw()
        if self.editable:
            self.set_state()
        self.update_arrow()
        self.update_sum()

        # Set column visibility depending on attributes and domain
        domain = []
        if self.screen.domain:
            domain.append(self.screen.get_domain())
        tab_domain = self.screen.screen_container.get_tab_domain()
        if tab_domain:
            domain.append(tab_domain)
        domain = simplify(domain)
        decoder = PYSONDecoder(self.screen.context)
        for column in self.treeview.get_columns():
            name = column.name
            if not name:
                continue
            widget = self.get_column_widget(column)
            if current_record and widget.editable:
                widget.set_editable(current_record)
            if decoder.decode(widget.attrs.get('tree_invisible', '0')):
                column.set_visible(False)
            elif name == self.screen.exclude_field:
                column.set_visible(False)
            else:
                inv_domain = domain_inversion(domain, name)
                if not isinstance(inv_domain, bool):
                    inv_domain = simplify(inv_domain)
                unique, _, _ = unique_value(inv_domain)
                column.set_visible(not unique or bool(self.children_field))
示例#4
0
    def display(self):
        self.treeview.display_counter += 1
        current_record = self.screen.current_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)
            self.treeview.set_model(model)
            # __select_changed resets current_record to None
            self.screen.current_record = current_record
            if current_record:
                selection = self.treeview.get_selection()
                path = model.on_get_path(current_record)
                selection.select_path(path)
        self.reload = False
        if not current_record:
            selection = self.treeview.get_selection()
            selection.unselect_all()
        self.treeview.queue_draw()
        if self.editable:
            self.set_state()
        self.update_sum()

        # Set column visibility depending on attributes and domain
        domain = []
        if self.screen.domain:
            domain.append(self.screen.domain)
        tab_domain = self.screen.screen_container.get_tab_domain()
        if tab_domain:
            domain.append(tab_domain)
        domain = simplify(domain)
        for column in self.treeview.get_columns():
            name = column.name
            if not name:
                continue
            widget = self.get_column_widget(column)
            if widget.attrs.get('tree_invisible', False):
                column.set_visible(False)
            elif name == self.screen.exclude_field:
                column.set_visible(False)
            else:
                inv_domain = domain_inversion(domain, name)
                if not isinstance(inv_domain, bool):
                    inv_domain = simplify(inv_domain)
                unique, _, _ = unique_value(inv_domain)
                column.set_visible(not unique or bool(self.children_field))
示例#5
0
文件: list.py 项目: tryton/tryton
    def display(self, force=False):
        self.treeview.display_counter += 1
        current_record = self.record
        if (force or not self.treeview.get_model()
                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.record = current_record
            if current_record:
                selection = self.treeview.get_selection()
                path = current_record.get_index_path(model.group)
                selection.select_path(path)
            # The search column must be set each time the model is changed
            self.treeview.set_search_column(0)
        if not current_record:
            selection = self.treeview.get_selection()
            selection.unselect_all()
        self.treeview.queue_draw()
        if self.editable:
            self.set_state()
        self.update_arrow()
        self.update_sum()

        # Set column visibility depending on attributes and domain
        domain = []
        if self.screen.domain:
            domain.append(self.screen.domain)
        tab_domain = self.screen.screen_container.get_tab_domain()
        if tab_domain:
            domain.append(tab_domain)
        domain = simplify(domain)
        decoder = PYSONDecoder(self.screen.context)
        tree_column_optional = self.screen.tree_column_optional.get(
            self.view_id, {})
        for column in self.treeview.get_columns():
            name = column.name
            if not name:
                continue
            widget = self.get_column_widget(column)
            widget.set_editable()
            if column.name in tree_column_optional:
                optional = tree_column_optional[column.name]
            else:
                optional = bool(int(widget.attrs.get('optional', '0')))
            invisible = decoder.decode(widget.attrs.get('tree_invisible', '0'))
            if invisible or optional:
                column.set_visible(False)
            elif name == self.screen.exclude_field:
                column.set_visible(False)
            else:
                inv_domain = domain_inversion(domain, name)
                if not isinstance(inv_domain, bool):
                    inv_domain = simplify(inv_domain)
                unique, _, _ = unique_value(inv_domain)
                column.set_visible(not unique or bool(self.children_field))
        if self.children_field:
            for i, column in enumerate(self.treeview.get_columns()):
                if self.draggable and not i:
                    continue
                if column.get_visible():
                    self.treeview.set_expander_column(column)
                    break