granicus_archiver.web.filters

class granicus_archiver.web.filters.Context[source]

Bases: TypedDict

Filter context

app: Application

The current application

request: Request

The current request

granicus_archiver.web.filters.local_tz(ctx: Context, dt: datetime) datetime[source]

Convert a datetime to the app’s local timezone (stored in types.TimezoneKey)

Parameters:
Return type:

datetime

granicus_archiver.web.filters.datetime_format(ctx: Context, dt: datetime, fmt: str = '%m/%d/%Y %H:%M') str[source]

Format a datetime object using datetime.datetime.strftime()

The timezone of the datetime object will first be converted using local_tz().

Parameters:
  • dt (datetime) – The datetime object to format

  • fmt (str) – The format string to use

  • ctx (Context)

Return type:

str

granicus_archiver.web.filters.date_format(ctx: Context, dt: datetime | date, fmt: str = '%x') str[source]

Format a date or datetime object as a date using datetime.datetime.strftime()

The timezone of the datetime object will first be converted using local_tz().

Parameters:
  • dt (datetime | date) – The date or datetime object to format

  • fmt (str) – The format string to use

  • ctx (Context)

Return type:

str

granicus_archiver.web.filters.time_format(ctx: Context, dt: datetime, fmt: str = '%X') str[source]

Format a datetime object as a time using datetime.datetime.strftime()

The timezone of the datetime object will first be converted using local_tz().

Parameters:
  • dt (datetime) – The datetime object to format

  • fmt (str) – The format string to use

  • ctx (Context)

Return type:

str

granicus_archiver.web.filters.duration_format(td: timedelta | float) str[source]

Format a timedelta or number of seconds as HH:MM:SS

Parameters:

td (timedelta | float)

Return type:

str

granicus_archiver.web.filters.snake_case_to_title(s: str) str[source]

Convert a snake_case string to title case

Parameters:

s (str)

Return type:

str

granicus_archiver.web.filters.url_query(ctx: Context, query_: dict[str, str] | None = None, merge: bool = True) URL[source]

Add query parameters to the current request URL

Parameters:
  • query – The query parameters to add

  • merge (bool) – If True, merge the new query parameters with any ewxisting query parameters. Otherwise, replace the existing query parameters.

  • ctx (Context)

  • query_ (dict[str, str] | None)

Return type:

URL

granicus_archiver.web.filters.static_path(ctx: Context, static_name: Literal['assets', 'granicus', 'legistar', 'legistar_rguid'], filename: Path | str) URL[source]

Get a URL for a static file

Parameters:
  • static_name (Literal['assets', 'granicus', 'legistar', 'legistar_rguid']) – The name of the static root to use (a member of types.StaticUrlRoots).

  • filename (Path | str) – The path to the file, relative to the static root

  • ctx (Context)

Return type:

URL

granicus_archiver.web.filters.clip_url(ctx: Context, clip_id: CLIP_ID, file_type: Literal['video', 'audio', 'chapters']) URL[source]

Get the s3 URL for a clip file

Note

For the chapters file type, the URL will be for a local view of the chapters file (views.clip_webvtt()). This is to prevent issues with CORS.

Parameters:
Return type:

URL

granicus_archiver.web.filters.legistar_url(ctx: Context, key: tuple[Literal['legistar'], GUID, LegistarFileUID] | tuple[Literal['legistar_rguid'], REAL_GUID, LegistarFileUID]) URL[source]

Get the s3 URL for a legistar file

Parameters:
  • ctx (Context)

  • key (tuple[Literal['legistar'], ~granicus_archiver.legistar.types.GUID, ~granicus_archiver.legistar.types.LegistarFileUID] | tuple[~typing.Literal['legistar_rguid'], ~granicus_archiver.legistar.types.REAL_GUID, ~granicus_archiver.legistar.types.LegistarFileUID])

Return type:

URL