示例#1
0
    def _create_field(self, attr_type=None, kwargs=None):
        """create field for dynamic form
        """

        if attr_type is None:
            type = match_type(self.attr.type)
            sql_type = self.attr.sql_type
        else:
            sql_type = attr_type
            type = match_type(attr_type)

        if kwargs is None:
            kwargs = self.get_init_kwargs()

        if (
            self.is_foreign_key
            and not self.ignore_foreign_fields
            and self.foreign_is_manuallookup
        ):
            return self.create_manuallookup_field(kwargs)
        elif (
            self.is_foreign_key
            and len(self.foreign_data) <= config['fk_dropdown_limit']
        ):
            return self.create_dropdown_field(kwargs)

        if type == 'INTEGER':
            return self.integer_field(kwargs)
        elif type == 'DECIMAL':
            return self.decimal_field(kwargs)
        elif type == 'FLOAT':
            return self.float_field(kwargs)
        elif type == 'STRING':
            return self.string_field(kwargs, sql_type)
        elif type == 'ENUM':
            return self.enum_field(kwargs, sql_type)
        elif type == 'BOOL':
            return self.bool_field(kwargs)
        elif type == 'TEMPORAL':
            return self.temporal_field(kwargs, sql_type)
        elif type in ('INTERNAL_BLOB', 'EXTERNAL_BLOB'):
            return self.blob_field(kwargs)
        elif type in ('INTERNAL_ATTACH', 'EXTERNAL_ATTACH'):
            return self.attach_field(kwargs)
        elif type == 'FILEPATH':
            return self.filepath_field(kwargs)
        elif type == 'UUID':
            return self.uuid_field(kwargs)
        elif type == 'ADAPTED':
            return self.adapted_field(kwargs)
示例#2
0
 def foreign_data(self):
     if self.aliased is None:
         data = self.foreign_table.proj(self.name).fetch()[self.name]
     else:
         data = self.foreign_table.proj(**self.aliased).fetch()[self.name]
     # sort values if integer
     if match_type(self.attr.type) == "INTEGER":
         data = np.sort(data)
     return data
示例#3
0
 def is_uuid(self):
     return match_type(self.attr.type) == 'UUID'
示例#4
0
 def is_integer(self):
     # won't work with adapted types
     return match_type(self.attr.type) == 'INTEGER'
示例#5
0
 def is_datelike(self):
     return match_type(self.type) == 'TEMPORAL'
示例#6
0
 def is_prefixid(self):
     return (match_type(self.type) == 'ADAPTED') and isinstance(
         self.adapter, PrefixId)