Beispiel #1
0
    def fm_validate_insert(self, value):
        """
            This validator checks the field using the Fileman logic.
            Since it expects value to be in Fileman External format
            and we are using Internal Format, it is of limited use.

            Also, I don't know how it will work on a sub-file.
        """
        M.Globals["ERR"].kill()

        # Validates single field against the data dictionary
        s0, = M.proc("CHK^DIE", self.fileid, self.fieldid, "H", value,
                     M.INOUT(""), "ERR")

        err = M.Globals["ERR"]

        # s0 should contain ^ for error, internal value for valid data
        if s0 == "^":
            error_code = err['DIERR'][1].value
            error_msg = '\n'.join(
                [v for k, v in err['DIERR'][1]['TEXT'].items()])
            help_msg = [v for k, v in err['DIHELP'].items()]

            raise FilemanError(
                """DBSDD.fm_validate_insert(): fileid = [%s], fieldid = [%s], value = [%s], error_code = [%s], error_msg = [%s], help = [%s]"""
                % (self.fileid, self.fieldid, value, error_code, error_msg,
                   help_msg))

        # If err exists, then some form of programming error
        if err.exists():
            raise FilemanError(
                """DBSDD.fm_validate_insert(): fileid = [%s], fieldid = [%s], value = [%s], err = [%s]"""
                % (self.fileid, self.fieldid, value, '\n'.join(err)))
Beispiel #2
0
 def validate_insert(self, s, internal=True):
     """
         Verify that the code is a valid code.
     """
     super(FieldSet, self).validate_insert(s, internal)  # mandatory check
     if s and s not in [d[0] for d in self.details]:
         valid = []
         for k, v in self.details:
             valid.append("%s=%s" % (k, v))
         raise FilemanError(
             """Value [%s] is not valid. must be one of: %s""" %
             (s, ", ".join(valid)))
Beispiel #3
0
 def pyto_external(self, s):
     """
         I need to retrieve the remote record, so that fileman can un-retrieve it !!!
     """
     if s:
         remote_gl = self.dd.m_open_form()
         cf = remote_gl + str(s) + ")"
         g = M.Globals.from_closed_form(cf)
         if not g.exists():
             raise FilemanError(
                 """Remote record [%s] does not exist. Missing global=[%s]"""
                 % (s, cf))
         value = g[0].value
         s = value.split("^", 1)[0]
     return s
Beispiel #4
0
    def validate_insert(self, s, internal=True):
        """
            Prevent insert if remote record does not exist.

            This is important since we are using internal format
        """
        super(FieldPointer, self).validate_insert(s,
                                                  internal)  # mandatory check
        if s and internal:  # external validated via pyto_exernal()
            remote_gl = self.dd.m_open_form()
            cf = remote_gl + str(s) + ")"
            if not M.Globals.from_closed_form(cf).exists():
                raise FilemanError(
                    """Remote record [%s] does not exist. Missing global=[%s]"""
                    % (s, cf))
Beispiel #5
0
 def pyto_internal(self, s):
     if type(s) == float:
         f = s
         if self.format_info[1]:
             return "%.*f" % (self.format_info[1], f)
         return "%d" % f
     else:
         # Verify that this is a valid number
         try:
             f = float(s)
         except:
             raise FilemanError("""[%s] is not a valid number""" % s)
         if self.format_info[1]:
             return "%.*f" % (self.format_info[1], f)
         return "%d" % f
Beispiel #6
0
    def get_file(self, name, internal=True, fieldids=None, fieldnames=None):
        """
            Look up the ^DIC array and find the file number for the specified file, 
            e.g. FILE = 1 - result is a string.
        """
        if self.remote:
            return DBSFileRemote(self.remote, name, internal=internal, fieldnames=fieldnames, fieldids=fieldids)

        if name.find('::') >= 0:
            # This is a full path name to a subfile. 
            dd = DD(subfile_path=name)
        else:
            # top-level file - dd entry defines the storage.
            dd = DD(name)

        if dd.fileid is None:
            raise FilemanError("""DBS.get_file() : File not found [%s]""" % name)
        return DBSFile(dd, internal=internal, fieldids=fieldids, fieldnames=fieldnames, ext_filename=name)
Beispiel #7
0
    def validate_insert(self, s, internal=True):
        """
            Verify that the code is a valid code.

            I limit the validation to whether the input value is a numeric.
            I silently ignore rounding problems. The reason for this is that
            floating point numbers often don't round well,

            >>> 1.1 % 1 == .1
            False

        """
        super(FieldNumeric, self).validate_insert(s,
                                                  internal)  # mandatory check
        if s:
            try:
                float(s)
            except:
                raise FilemanError("""[%s] is not a valid number""" % s)
Beispiel #8
0
    def validate_insert(self, s, internal=True):
        """
            Verify that an insert / modify attempt is valid. 

            Ensure that the foreign key exists.
            
            This works on the Mumps Internal format.

            For efficiency, generate the closed form of the target, and look-up
            based on that, rather than navigating via a file.
        """
        super(FieldVPointer, self).validate_insert(s,
                                                   internal)  # mandatory check
        if s:
            key, remote_gl = s.split(";", 1)

            cf = "^" + remote_gl + str(key) + ")"
            if not M.Globals.from_closed_form(cf).exists():
                raise FilemanError(
                    """Remote record [%s] does not exist. Missing global=[%s]"""
                    % (s, cf))
Beispiel #9
0
 def validate_insert(self, s, internal=True):
     """
         Mandatory field checking.
     """
     if self.mandatory and (s is None or s == ""):
         raise FilemanError("""Field is mandatory""")
Beispiel #10
0
 def foreign_get(self, s, internal=True):
     """
         Return the foreign record for this field.
     """
     raise FilemanError("""No Foreign File for this class""",
                        self.__class__)