Exemplo n.º 1
0
def werk_matches_options(werk, werk_table_options):
    if not ((not werk_table_options["id"] or werk["id"] == int(werk_table_options["id"])) and \
           werk["level"] in werk_table_options["levels"] and \
           werk["class"] in werk_table_options["classes"] and \
           werk["compatible"] in werk_table_options["compatibility"] and \
           werk_table_options["component"] in ( None, werk["component" ]) and \
           werk["date"] >= werk_table_options["date_range"][0] and \
           werk["date"] <= werk_table_options["date_range"][1]):
        return False

    if werk_table_options[
            "edition"] and werk["edition"] != werk_table_options["edition"]:
        return False

    from_version, to_version = werk_table_options["version"]
    if from_version and utils.cmp_version(werk["version"], from_version) < 0:
        return False

    if to_version and utils.cmp_version(werk["version"], to_version) > 0:
        return False

    if werk_table_options["werk_content"]:
        have_match = False
        search_text = werk_table_options["werk_content"].lower()
        for line in [werk["title"]] + werk["body"]:
            if search_text in line.lower():
                have_match = True
                break
        if not have_match:
            return False

    return True
Exemplo n.º 2
0
    def filter_table(self, rows: Rows) -> Rows:
        from_version = html.request.var(self.htmlvars[0])
        to_version = html.request.var(self.htmlvars[1])
        if not from_version and not to_version:
            return rows  # Filter not used

        new_rows = []
        for row in rows:
            version = row.get(self.ident, "")
            if from_version and utils.cmp_version(version, from_version) == -1:
                continue
            if to_version and utils.cmp_version(version, to_version) == 1:
                continue
            new_rows.append(row)

        return new_rows
Exemplo n.º 3
0
def version_in_range(ident: str, request_vars: List[str],
                     context: VisualContext, rows: Rows) -> Rows:
    values = context.get(ident, {})
    assert not isinstance(values, str)
    from_version, to_version = (values.get(v) for v in request_vars)

    new_rows = []
    for row in rows:
        version = row.get(ident, "")
        if from_version and utils.cmp_version(version, from_version) == -1:
            continue
        if to_version and utils.cmp_version(version, to_version) == 1:
            continue
        new_rows.append(row)

    return new_rows
Exemplo n.º 4
0
    def filter_table(self, context: VisualContext, rows: Rows) -> Rows:
        values = context.get(self.ident, {})
        assert not isinstance(values, str)
        from_version, to_version = (values.get(v) for v in self.htmlvars)
        if not from_version and not to_version:
            return rows  # Filter not used

        new_rows = []
        for row in rows:
            version = row.get(self.ident, "")
            if from_version and utils.cmp_version(version, from_version) == -1:
                continue
            if to_version and utils.cmp_version(version, to_version) == 1:
                continue
            new_rows.append(row)

        return new_rows
Exemplo n.º 5
0
def werk_matches_options(werk, werk_table_options):
    # TODO: Fix this silly typing chaos below!
    # check if werk id is int because valuespec is TextInput
    # else, set empty id to return all results beside input warning
    try:
        werk_to_match: Union[int, str] = int(werk_table_options["id"])
    except ValueError:
        werk_to_match = ""

    if not (
        (not werk_to_match or werk["id"] == werk_to_match)
        and werk["level"] in werk_table_options["levels"]
        and werk["class"] in werk_table_options["classes"]
        and werk["compatible"] in werk_table_options["compatibility"]
        and werk_table_options["component"] in (None, werk["component"])
        and werk["date"] >= werk_table_options["date_range"][0]
        and werk["date"] <= werk_table_options["date_range"][1]
    ):
        return False

    if werk_table_options["edition"] and werk["edition"] != werk_table_options["edition"]:
        return False

    from_version, to_version = werk_table_options["version"]
    if from_version and utils.cmp_version(werk["version"], from_version) < 0:
        return False

    if to_version and utils.cmp_version(werk["version"], to_version) > 0:
        return False

    if werk_table_options["werk_content"]:
        have_match = False
        search_text = werk_table_options["werk_content"].lower()
        for line in [werk["title"]] + werk["body"]:
            if search_text in line.lower():
                have_match = True
                break
        if not have_match:
            return False

    return True
Exemplo n.º 6
0
 def version_is_higher(self, a: Optional[str], b: Optional[str]) -> bool:
     return utils.cmp_version(a, b) == 1
Exemplo n.º 7
0
 def version_is_higher(self, a, b):
     # type: (Optional[str], Optional[str]) -> bool
     return utils.cmp_version(a, b) == 1
Exemplo n.º 8
0
 def version_is_higher(self, a, b):
     return utils.cmp_version(a, b) == 1