web

web

This package contains the web interface based on flask

copyright
  1. 2012 by AG DSN.

Subpackages

Submodules

class PycroftFlask(*a: Any, **kw: Any)[source]

Extend the Flask class to set Jinja options.

jinja_options: dict[str, t.Any] = {'autoescape': <function select_autoescape.<locals>.autoescape>, 'extensions': [<class 'jinja2.ext.ExprStmtExtension'>, <class 'jinja2.ext.LoopControlExtension'>], 'undefined': <class 'jinja2.runtime.StrictUndefined'>}

Options that are passed to the Jinja environment in create_jinja_environment(). Changing these options after the environment is created (accessing jinja_env) will have no effect.

Changed in version 1.1.0: This is a dict instead of an ImmutableDict to allow easier configuration.

login_manager: LoginManager
maybe_add_config_from_env(keys: Iterable[str]) None[source]

Write keys from the environment to the app’s config

If a key does not exist in the environment, it will just be skipped.

make_app(hades_logs: bool = True) PycroftFlask[source]

Create and configure the main? Flask app object

register_pyinstrument(app: Flask) None[source]
register_commands(app: Flask) None[source]

Register custom commands executable via flask $command_name.

web

This package contains the web interface based on flask

copyright
  1. 2012 by AG DSN.

template_filter(name: str) Callable[[_TF], _TF][source]
exception AssetNotFound[source]
require(ctx: Context, asset: str, **kwargs: Any) str[source]

Build an URL for an asset generated by esbuild.

To prevent Jinja2 from inlining the calls of this filter with constant parameters, this filter needs to be declared as a context filter. The context is not actually used.

Parameters
  • ctx – Template context

  • asset – Name of the

  • kwargs – Kwargs for url_for()

Returns

URL

pretty_category_filter(category: str) str[source]

Make pretty category names for flash messages, etc

date_filter(dt: datetime | date | None, format: str | None = None) str[source]

Format date or datetime objects using Flask-Babel

Parameters
  • dt – a datetime object or None

  • format – format as understood by Flask-Babel’s format_datetime

datetime_filter(dt: datetime | None, format: str | None = None) str[source]

Format datetime objects using Flask-Babel

Parameters
  • dt – a datetime object or None

  • format – format as understood by Flask-Babel’s format_datetime

timesince_filter(dt: datetime | None, default: str = 'just now') str[source]

Returns string representing “time since” e.g. 3 days ago, 5 hours ago etc.

adopted from http://flask.pocoo.org/snippets/33/

prefix_unit_filter(value: float | Decimal, unit: str, factor: int, prefixes: Iterable[str]) str[source]
byte_size_filter(value: float | Decimal) str[source]
money_filter(amount: float | Decimal) str[source]
icon_filter(icon_class: str) str[source]
account_type_filter(account_type: str) str[source]
transaction_type_filter(credit_debit_type: tuple[str, str]) str[source]
register_filters(app: Flask) None[source]
template_check(name: str) Callable[[_T], _T][source]
no_network_access_check(user: User) bool[source]

Tests if user has network access

privilege_check(user: User, *required_privileges: str) bool[source]

Tests if the user has one of the required_privileges to view the requested component.

greater(value: Any, other: Any) bool[source]

Tests if another value is greater than a given value.

less(value: Any, other: Any) bool[source]

Tests if another value is less than a given value.

greater_equal(value: Any, other: Any) bool[source]

Tests if another value is greater than or equal a given value.

less_equal(value: Any, other: Any) bool[source]

Tests if another value is less than or equal a given value.

is_dict(value: Any) bool[source]
register_checks(app: Flask) None[source]