Exemple #1
0
 def filter_selection(self, domain, record, field):
     if not domain:
         return
     test = lambda value: eval_domain(domain, {
         self.field_name: value[0],
     })
     self.selection = filter(test, self.selection)
Exemple #2
0
 def filter_selection(self, domain, record, field):
     if not domain:
         return
     test = lambda value: eval_domain(domain, {
             self.field_name: value[0],
             })
     self.selection = filter(test, self.selection)
Exemple #3
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
Exemple #4
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
Exemple #5
0
 def validate(self, record, softvalidation=False):
     if self.attrs.get('readonly'):
         return True
     res = True
     self.get_state_attrs(record)['domain_readonly'] = False
     inverted_domain, domain = self.validation_domains(record)
     if not softvalidation:
         res = res and self.check_required(record)
     if isinstance(domain, bool):
         res = res and domain
     elif domain == [('id', '=', False)]:
         res = False
     else:
         if (isinstance(inverted_domain, list) and len(inverted_domain) == 1
                 and inverted_domain[0][1] == '='):
             # 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.
             leftpart, _, value = inverted_domain[0][:3]
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             original_domain = merge(record.group.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:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = (
                     domain_readonly)
         res = res and eval_domain(domain, EvalEnvironment(record))
     self.get_state_attrs(record)['valid'] = res
     return res
Exemple #6
0
 def validate(self, record, softvalidation=False):
     if self.attrs.get('readonly'):
         return True
     res = True
     self.get_state_attrs(record)['domain_readonly'] = False
     inverted_domain, domain = self.validation_domains(record)
     if not softvalidation:
         res = res and self.check_required(record)
     if isinstance(domain, bool):
         res = res and domain
     elif domain == [('id', '=', False)]:
         res = False
     else:
         if (isinstance(inverted_domain, list)
                 and len(inverted_domain) == 1
                 and inverted_domain[0][1] == '='):
             # 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.
             leftpart, _, value = inverted_domain[0][:3]
             if value is False:
                 # XXX to remove once server domains are fixed
                 value = None
             setdefault = True
             if '.' in leftpart:
                 recordpart, localpart = leftpart.split('.', 1)
                 original_domain = merge(record.group.domain)
                 constraintfields = set()
                 if original_domain[0] == 'AND':
                     for leaf in localize_domain(original_domain[1:]):
                         constraintfields.add(leaf[0])
                 if localpart != 'id' or recordpart not in constraintfields:
                     setdefault = False
             if setdefault:
                 self.set_client(record, value)
                 self.get_state_attrs(record)['domain_readonly'] = True
         res = res and eval_domain(domain, EvalEnvironment(record))
     self.get_state_attrs(record)['valid'] = res
     return res
Exemple #7
0
    def validate(self, record, softvalidation=False, pre_validate=None):
        valid = super(DictField, self).validate(record, softvalidation,
                                                pre_validate)

        if self.attrs.get('readonly'):
            return valid

        decoder = PYSONDecoder()
        field_value = self.get_eval(record)
        domain = []
        for key in field_value:
            if key not in self.keys:
                continue
            key_domain = self.keys[key].get('domain')
            if key_domain:
                domain.append(decoder.decode(key_domain))

        valid_value = eval_domain(domain, field_value)
        if not valid_value:
            self.get_state_attrs(record)['invalid'] = 'domain'

        return valid and valid_value
Exemple #8
0
 def _value_evaluator(value):
     return eval_domain(domain, {
         self.field_name: value[0],
     })
Exemple #9
0
 def test(value):
     return eval_domain(domain, {
         self.field_name: value[0],
     })