Skip to content

template

Generate CQL2 filter expressions via Jinja2 templating.

Template dataclass

Generate CQL2 filter expressions via Jinja2 templating.

Parameters:

Name Type Description Default
template_str str
required

Attributes:

Name Type Description
env Environment
Source code in src/stac_auth_proxy/filters/template.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
@dataclass
class Template:
    """Generate CQL2 filter expressions via Jinja2 templating."""

    template_str: str
    env: Environment = field(init=False)

    def __post_init__(self):
        """Initialize the Jinja2 environment."""
        self.env = Environment(loader=BaseLoader).from_string(self.template_str)

    async def __call__(self, context: dict[str, Any]) -> str:
        """Render a CQL2 filter expression with the request and auth token."""
        return self.env.render(**context).strip()

__call__(context: dict[str, Any]) -> str async

Render a CQL2 filter expression with the request and auth token.

Source code in src/stac_auth_proxy/filters/template.py
20
21
22
async def __call__(self, context: dict[str, Any]) -> str:
    """Render a CQL2 filter expression with the request and auth token."""
    return self.env.render(**context).strip()

__post_init__()

Initialize the Jinja2 environment.

Source code in src/stac_auth_proxy/filters/template.py
16
17
18
def __post_init__(self):
    """Initialize the Jinja2 environment."""
    self.env = Environment(loader=BaseLoader).from_string(self.template_str)