Exemple #1
0
def filtering_form_generator():
    for table, properties in filtering_properties.items():
        relations = {}
        for model, relation in relationships[table].items():
            if model in ("edges", "results"):
                continue
            relations[model] = MultipleInstanceField(model)
            relationships[f"{table}_filtering"][model] = relation
        type(
            f"{table.capitalize()}FilteringForm",
            (BaseForm, ),
            {
                "template":
                "filtering",
                "properties":
                list(relations) + properties,
                "form_type":
                HiddenField(default=f"{table}_filtering"),
                "operator":
                SelectField(
                    "Type of match",
                    choices=(
                        ("all", "Match if all properties match"),
                        ("any", "Match if any property matches"),
                    ),
                ),
                **{
                    **{property: StringField()
                       for property in properties},
                    **{
                        f"{property}_filter": SelectField(choices=(
                            ("inclusion", "Inclusion"),
                            ("equality", "Equality"),
                            ("regex", "Regular Expression"),
                        ))
                        for property in properties
                    },
                    **relations,
                    **{
                        f"{relation}_filter": SelectField(choices=(
                            ("any", "Any"),
                            ("not_any", "Not related to Any"),
                            ("none", "None"),
                        ))
                        for relation in relations
                    },
                },
            },
        )
Exemple #2
0
def filtering_form_generator() -> None:
    for table, properties in filtering_properties.items():
        table_model = table.capitalize(
        ) if table != "configuration" else "Device"
        relations = {
            model: MultipleInstanceField(model.capitalize(),
                                         instance_type=relation["model"])
            for model, relation in relationships[table_model].items()
            if model not in ("edges", "results")
        }
        type(
            f"{table.capitalize()}FilteringForm",
            (BaseForm, ),
            {
                "template":
                "filtering",
                "properties":
                list(relations) + properties,
                "form_type":
                HiddenField(default=f"{table}_filtering"),
                "operator":
                SelectField(
                    "Match Condition",
                    choices=(
                        ("all", "Match if all properties match"),
                        ("any", "Match if any property matches"),
                    ),
                ),
                **{
                    **{property: StringField()
                       for property in properties},
                    **{
                        f"{property}_filter": SelectField(choices=(
                            ("inclusion", "Inclusion"),
                            ("equality", "Equality"),
                            ("regex", "Regular Expression"),
                        ))
                        for property in properties
                    },
                    **relations,
                    **{
                        f"{relation}_filter": SelectField(choices=(("any", "Any"), ("not_any", "Not related to Any")))
                        for relation in relations
                    },
                },
            },
        )
Exemple #3
0
def filtering_form_generator() -> None:
    for table, properties in filtering_properties.items():
        kwargs = {}
        if table in ("device", "link", "configuration"):
            kwargs["pools"] = MultipleInstanceField("Pools",
                                                    instance_type="Pool")
        if table == "service":
            kwargs["workflows"] = MultipleInstanceField(
                "Workflows", instance_type="Workflow")
        if table == "workflow":
            kwargs["services"] = MultipleInstanceField("Services",
                                                       instance_type="Service")
        type(
            f"{table.capitalize()}FilteringForm",
            (BaseForm, ),
            {
                "template":
                "filtering",
                "properties":
                list(kwargs) + properties,
                "form_type":
                HiddenField(default=f"{table}_filtering"),
                "operator":
                SelectField(
                    "Match Condition",
                    choices=(
                        ("all", "Match if all properties match"),
                        ("any", "Match if any property matches"),
                    ),
                ),
                **{
                    **{property: StringField()
                       for property in properties},
                    **{
                        f"{property}_filter": SelectField(choices=(
                            ("inclusion", "Inclusion"),
                            ("equality", "Equality"),
                            ("regex", "Regular Expression"),
                        ))
                        for property in properties
                    },
                    **kwargs,
                },
            },
        )