Esempio n. 1
0
    def __init__(self, configuration_name, texts):
        """
        The dictionary texts goes { "<weight>": "<Text>", ... },
        <weight> being one of 'A', 'B', 'C', 'D' and <Text> the text
        to be indexed with that weight.
        """
        sql.expression.__init__(self)
        self._name = "ts_vector"

        for key in texts.keys():
            if strip(texts[key]) == "":
                del texts[key]

        if len(texts) == 0:
            self._parts = ["NULL",]
        else:
            for weight, text in texts.items():
                if type(text) != types.UnicodeType: text = unicode(text)
                self._append( ("setweight(",
                               "  to_tsvector(",
                               sql.string_literal(configuration_name), ", ",
                               sql.unicode_literal(text),
                               "), ", sql.string_literal(upper(weight)), ")",
                               "||",) )
            if len(self._parts) > 0:
                self._parts.pop() # Remove last ||
Esempio n. 2
0
    def sql_literal(self, dbobj):
        if not self.isset(dbobj):
            msg = "This attribute has not been retrieved from the database."
            raise AttributeError(msg)
        else:        
            value = getattr(dbobj, self.data_attribute_name())

            if value is None:
                return sql.NULL
            else:
                return sql.string_literal(self.datetime_as_string(value))
Esempio n. 3
0
    def sql_literal(self, dbobj):
        """
        This function takes care of converting the Python object into a
        serialized string representation.
        """
        if not self.isset(dbobj):
            msg = "This attribute has not been retrieved from the database."
            raise AttributeError(msg)
        else:        
            value = getattr(dbobj, self.data_attribute_name())

            if value is None:
                return sql.NULL
            else:                
                return sql.string_literal(join(value, "/"))