Пример #1
0
    def _match_title(parent_model,
                     child_model,
                     term,
                     options,
                     capture=db.model_name(db.Title)):
        get_model = database_cmd.GetModelClass()
        parent_model = get_model.run(parent_model)
        child_model = get_model.run(child_model)

        match_string = PartialModelFilter._match_string_column
        term = ParseTerm().run(term)
        ids = set()

        if term.namespace.lower() == 'title' or not term.namespace:

            col_on_parent = db.relationship_column(parent_model, child_model)
            s = constants.db_session()
            ids.update(
                x[0]
                for x in s.query(parent_model.id).join(col_on_parent).filter(
                    match_string(child_model.name, term.tag, options)).all())
        return ids
Пример #2
0
    def _match_namemixin(parent_model,
                         child_model,
                         term,
                         options,
                         capture=[
                             db.model_name(x) for x in _models()
                             if issubclass(x, db.NameMixin)
                         ]):
        get_model = database_cmd.GetModelClass()
        parent_model = get_model.run(parent_model)
        child_model = get_model.run(child_model)
        match_string = PartialModelFilter._match_string_column
        term = ParseTerm().run(term)
        ids = set()

        s = constants.db_session()

        col = db.relationship_column(parent_model, child_model)

        ids.update(x[0] for x in s.query(parent_model.id).join(col).filter(
            match_string(child_model.name, term, options)).all())

        return ids
Пример #3
0
    def _match_title(parent_model,
                     child_model,
                     term,
                     options,
                     capture=db.model_name(db.Title)):
        get_model = database_cmd.GetModelClass()
        parent_model = get_model.run(parent_model)
        child_model = get_model.run(child_model)

        match_string = PartialModelFilter._match_string_column
        term = ParseTerm().run(term)
        ids = set()

        if issubclass(parent_model, db.Gallery):
            if term.namespace.lower() == 'title' or not term.namespace:
                s = constants.db_session()
                ids.update(x[0] for x in s.query(parent_model.id).join(
                    parent_model.titles).filter(
                        match_string(child_model.name, term, options)).all())
        else:
            raise NotImplementedError(
                "Title on {} has not been implemented".format(parent_model))

        return ids
Пример #4
0
 def _empty(model_name):
     model = database_cmd.GetModelClass().run(model_name)
     s = constants.db_session()
     return set(x[0] for x in s.query(model.id).all())