Ejemplo n.º 1
0
def make_fieldspecs(searchtable):
    tablename = searchtable.find('tableName').text

    return [
        QueryFieldSpec.from_path((tablename, fieldname.text))
        for fieldname in searchtable.findall('.//displayfield/fieldName')
    ]
Ejemplo n.º 2
0
    def build_related_query(self, session, config, terms, collection, user):
        logger.info('%s: building related query using definition: %s',
                    self.__class__.__name__, self.definition)

        from .views import build_primary_query

        primary_fieldspec = QueryFieldSpec.from_path(
            self.definition.split('.'), add_id=True)

        pivot = primary_fieldspec.table

        logger.debug('pivoting on: %s', pivot)
        for searchtable in config.findall('tables/searchtable'):
            if searchtable.find('tableName').text == pivot.name:
                break
        else:
            return None

        logger.debug('using %s for primary search',
                     searchtable.find('tableName').text)
        primary_query = build_primary_query(session,
                                            searchtable,
                                            terms,
                                            collection,
                                            as_scalar=True)

        if primary_query is None:
            return None
        logger.debug('primary query: %s', primary_query)

        primary_field = QueryField(fieldspec=primary_fieldspec,
                                   op_num=QueryOps.OPERATIONS.index('op_in'),
                                   value=primary_query,
                                   negate=False,
                                   display=False,
                                   sort_type=0)

        logger.debug("primary queryfield: %s", primary_field)
        logger.debug("display queryfields: %s", self.display_fields)
        logger.debug("filter queryfields: %s", self.filter_fields)

        queryfields = self.display_fields + self.filter_fields + [
            primary_field
        ]

        related_query, _ = build_query(session, collection, user,
                                       self.root.tableId, queryfields)

        if self.distinct:
            related_query = related_query.distinct()

        logger.debug('related query: %s', related_query)
        return related_query
Ejemplo n.º 3
0
    def build_related_query(self, session, config, terms, collection, user):
        logger.info("%s: building related query using definition: %s", self.__class__.__name__, self.definition)

        from .views import build_primary_query

        primary_fieldspec = QueryFieldSpec.from_path(self.definition.split("."), add_id=True)

        pivot = primary_fieldspec.table

        logger.debug("pivoting on: %s", pivot)
        for searchtable in config.findall("tables/searchtable"):
            if searchtable.find("tableName").text == pivot.name:
                break
        else:
            return None

        logger.debug("using %s for primary search", searchtable.find("tableName").text)
        primary_query = build_primary_query(session, searchtable, terms, collection, as_scalar=True)

        if primary_query is None:
            return None
        logger.debug("primary query: %s", primary_query)

        primary_field = QueryField(
            fieldspec=primary_fieldspec,
            op_num=QueryOps.OPERATIONS.index("op_in"),
            value=primary_query,
            negate=False,
            display=False,
            sort_type=0,
        )

        logger.debug("primary queryfield: %s", primary_field)
        logger.debug("display queryfields: %s", self.display_fields)
        logger.debug("filter queryfields: %s", self.filter_fields)

        queryfields = self.display_fields + self.filter_fields + [primary_field]

        related_query, _ = build_query(session, collection, user, self.root.tableId, queryfields)

        if self.distinct:
            related_query = related_query.distinct()

        logger.debug("related query: %s", related_query)
        return related_query
Ejemplo n.º 4
0
 def col_to_fs(col, add_id=False):
     return QueryFieldSpec.from_path([root_table_name] + col.split('.'),
                                     add_id)
Ejemplo n.º 5
0
 def col_to_fs(col, add_id=False):
     return QueryFieldSpec.from_path([root_table_name] + col.split("."), add_id)