Exemplo n.º 1
0
 def val_txt2py(self, txtval):
     """
     Convert text to a python variable.
     
     @type txtval: str
     @param txtval: text representation of column value
     
     @rtype: object
     """
     if self.isarray:
         return text_to_array ( txtval[6:], self.arraysize-1 )
     return txtval
Exemplo n.º 2
0
 def val_txt2py(self, txtval):
     """
     Convert text to a python variable.
     
     @type txtval: str
     @param txtval: text representation of column value
     
     @rtype: object
     """
     if self.isarray:
         return text_to_array(txtval[6:], self.arraysize - 1)
     return txtval
Exemplo n.º 3
0
    def __init__(self, name=None, type='text', size=-1, ndims=0, **kkw):
        try:
            ndims = ndims or kkw.get('ndims', 0)
            self.name = name or kkw['name']
            self.type = type or kkw['type']
            self.size = size or kkw['size']
            self.lp = kkw.get("lp", -1)
            self.isarray = kkw.get("isarray", ndims > 0)
            self.arraysize = kkw.get("arraysize", ndims)
            self.label = kkw.get("label", self.name)
            self.auto = kkw.get("auto", False)
            self.id = kkw.get("objectid", None)

            for k in kkw:
                if k not in self.__dict__: self.__dict__[k] = kkw[k]

            choices = text_to_array(self.choices, 0)
            self.choices = []
            self.choices_value_hash = {}
            self.choices_label_hash = {}
            for c in choices:
                if c.startswith("<["):
                    cv, cd = c[2:-2].split("::=")[:2]
                else:
                    cv, cd = c, c
                self.choices.append((cv, cd))
                self.choices_label_hash[cd] = cv
                self.choices_value_hash[cv] = cd

            params = text_to_array(self.editor_class_params, 0) or []
            params = map(lambda x: tuple(x.split("::=")), params)
            self.editor_class_params = {}
            for (pname, pvalue) in params:
                self.editor_class_params[pname] = pvalue
        except KeyError, e:
            kwname, = e.args
            raise Field.IncompleteDefinition(
                "missing: '%s' in field definition." % kwname)
Exemplo n.º 4
0
 def __init__(self, name=None, type='text', size=-1, ndims=0, **kkw):
     try:            
         ndims = ndims or kkw.get('ndims', 0)
         self.name = name or kkw['name']
         self.type = type or kkw['type']
         self.size = size or kkw['size']
         self.lp = kkw.get ( "lp", -1 )
         self.isarray = kkw.get("isarray", ndims > 0)
         self.arraysize = kkw.get("arraysize", ndims )
         self.label = kkw.get("label", self.name)
         self.auto = kkw.get("auto", False)
         self.id = kkw.get("objectid", None)
         
         for k in kkw:
             if k not in self.__dict__: self.__dict__[k] = kkw[k]                        
         
         choices = text_to_array ( self.choices, 0 )
         self.choices = []
         self.choices_value_hash = {}
         self.choices_label_hash = {}
         for c in choices:
             if c.startswith("<["):
                 cv,cd = c[2:-2].split("::=")[:2]
             else:
                 cv,cd = c, c                    
             self.choices.append ( (cv, cd) )
             self.choices_label_hash[cd] = cv
             self.choices_value_hash[cv] = cd
             
         params = text_to_array ( self.editor_class_params, 0 ) or []            
         params = map ( lambda x: tuple(x.split("::=")), params )
         self.editor_class_params = {}
         for (pname, pvalue) in params:
             self.editor_class_params[pname] = pvalue
     except KeyError, e:
         kwname, = e.args
         raise Field.IncompleteDefinition ( "missing: '%s' in field definition." % kwname )
Exemplo n.º 5
0
 def val_sql2py(self, sqlval):
     """
     Convert the value returned by postgres into a python variable.
     
     @type sqlval: str
     @param sqlval: value returned from a SELECT 
     
     @rtype: object
     """
     if self.isarray:
         return text_to_array (sqlval, self.arraysize-1)
     if self.type == 'bit': 
         if sqlval == '1': return True
         elif sqlval == '0': return False
         else: return None
     return sqlval
Exemplo n.º 6
0
 def val_sql2py(self, sqlval):
     """
     Convert the value returned by postgres into a python variable.
     
     @type sqlval: str
     @param sqlval: value returned from a SELECT 
     
     @rtype: object
     """
     if self.isarray:
         return text_to_array(sqlval, self.arraysize - 1)
     if self.type == 'bit':
         if sqlval == '1': return True
         elif sqlval == '0': return False
         else: return None
     return sqlval