コード例 #1
0
def fetchall_table(sql):
    sql = utils.convert_boolean(sql)
    cursor = connection.cursor()
    cursor.execute(sql)
    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()
    ]
コード例 #2
0
ファイル: models.py プロジェクト: mdrouhard/textvisdrg
def fetchall_table(sql):
    sql = utils.convert_boolean(sql)
    cursor = connection.cursor()
    cursor.execute(sql)
    desc = cursor.description
    return [
        dict(zip([col[0] for col in desc], row))
        for row in cursor.fetchall()
    ]
コード例 #3
0
ファイル: models.py プロジェクト: mdrouhard/textvisdrg
def fetchall(sql):
    sql = utils.convert_boolean(sql)
    cursor = connection.cursor()
    cursor.execute(sql)
    desc = cursor.description
    return [
        row[0]
        for row in cursor.fetchall()
    ]
コード例 #4
0
ファイル: models.py プロジェクト: mhwangbo11/textvisdrg
    def get_example_messages_by_groups(self, groups, filters=[], excludes=[]):
        include_groups = map(
            lambda x: int(x['value']),
            filter(lambda x: x['dimension'].key == 'groups', filters))
        if len(include_groups) > 0:
            groups = include_groups
        exclude_groups = map(
            lambda x: int(x['value']),
            filter(lambda x: x['dimension'].key == 'groups', excludes))
        groups = filter(lambda x: x not in exclude_groups, groups)

        per_group = int(10 / len(groups))
        combined_messages = []
        group_querysets = []
        for group in groups:
            group_obj = self.groups.get(id=group)
            messages = group_obj.messages
            for filterA in filters:
                dimension = filterA["dimension"]

                # Remove the dimension key
                params = {
                    key: value
                    for key, value in filterA.iteritems() if key != "dimension"
                }
                messages = dimension.filter(messages, **params)

            for exclude in excludes:
                dimension = exclude["dimension"]

                # Remove the dimension key
                params = {
                    key: value
                    for key, value in excludes.iteritems()
                    if key != "dimension"
                }

                messages = dimension.exclude(messages, **params)

            group_querysets.append(messages)
            #combined_messages.extend(messages[:per_group])
        query = ""
        for idx, queryset in enumerate(group_querysets):
            if idx > 0:
                query += " UNION "
            query += "(%s)" % (utils.quote(str(queryset.query)))
        query = utils.convert_boolean(query)
        queryset = Message.objects.raw(query)
        return queryset
コード例 #5
0
ファイル: models.py プロジェクト: mdrouhard/textvisdrg
    def get_example_messages_by_groups(self, groups, filters=[], excludes=[]):
        include_groups = map(lambda x: int(x['value']), filter(lambda x: x['dimension'].key=='groups', filters))
        if len(include_groups)> 0:
            groups = include_groups
        exclude_groups = map(lambda x: int(x['value']), filter(lambda x: x['dimension'].key=='groups', excludes))
        groups = filter(lambda x: x not in exclude_groups, groups)

        per_group = int(10 / len(groups))
        combined_messages = []
        group_querysets = []
        for group in groups:
            group_obj = self.groups.get(id=group)
            messages = group_obj.messages
            for filterA in filters:
                dimension = filterA["dimension"]

                # Remove the dimension key
                params = {key: value for key, value in filterA.iteritems() if key != "dimension"}
                messages = dimension.filter(messages, **params)

            for exclude in excludes:
                dimension = exclude["dimension"]

                # Remove the dimension key
                params = {key: value for key, value in excludes.iteritems() if key != "dimension"}

                messages = dimension.exclude(messages, **params)

            group_querysets.append(messages)
            #combined_messages.extend(messages[:per_group])
        query = ""
        for idx, queryset in enumerate(group_querysets):
            if idx > 0:
                query += " UNION "
            query += "(%s)" %(utils.quote(str(queryset.query)))
        query = utils.convert_boolean(query)
        queryset = Message.objects.raw(query)
        return queryset
コード例 #6
0
def fetchall(sql):
    sql = utils.convert_boolean(sql)
    cursor = connection.cursor()
    cursor.execute(sql)
    desc = cursor.description
    return [row[0] for row in cursor.fetchall()]