def form2obj(self, ar, instance, post_data, is_new):
        """
        Test cases:
        - setting a CharField to ''
        - sales.Invoice.number may be blank
        """
        v = self.extract_form_data(post_data)
        # logger.info("20130128 %s.form2obj() %s = %r",self.__class__.__name__,self.name,v)
        if v is None:
            # means that the field wasn't part of the submitted form. don't
            # touch it.
            return
        if v == '':
            # print 20130125, self.field.empty_strings_allowed, self.field.name, self.form2obj_default
            if self.field.empty_strings_allowed:
                v = self.parse_form_value(v, instance)

                # If a field has been posted with empty string, we
                # don't want it to get the field's default value!
                # Otherwise checkboxes with default value True can
                # never be unset!

                # Charfields have empty_strings_allowed (e.g. id field
                # may be empty) but don't do this for other cases.
            else:
                v = self.form2obj_default
        else:
            v = self.parse_form_value(v, instance)
        if not is_new and self.field.primary_key and instance.pk is not None:
            if instance.pk == v:
                return
            raise exceptions.ValidationError({
                self.field.name: _(
                    "Existing primary key value %r "
                    "may not be modified.") % instance.pk})

        return self.set_value_in_object(ar, instance, v)
dataset/ETHPy150Open lsaffre/lino/lino/core/store.py/StoreField.form2obj/original