swh.web.utils.swh_templatetags module#

swh.web.utils.swh_templatetags.docstring_display(docstring)[source]#

Utility function to htmlize reST-formatted documentation in browsable api.

Utility function for decorating api links in browsable api.

Parameters:
  • text – whose content matching links should be transformed into

  • links. (contextual API or Browse html)

Returns

The text transformed if any link is found. The text as is otherwise.

Utility function for decorating headers links in browsable api.

Args

text: Text whose content contains Link header value

Returns:

The text transformed with html link if any link is found. The text as is otherwise.

swh.web.utils.swh_templatetags.jsonify(obj)[source]#

Utility function for converting a django template variable to JSON in order to use it in script tags.

Args

obj: Any django template context variable

Returns:

JSON representation of the variable.

swh.web.utils.swh_templatetags.sub(value, arg)[source]#

Django template filter for subtracting two numbers

Parameters:
  • value (int/float) – the value to subtract from

  • arg (int/float) – the value to subtract to

Returns:

The subtraction result

Return type:

int/float

swh.web.utils.swh_templatetags.mul(value, arg)[source]#

Django template filter for multiplying two numbers

Parameters:
  • value (int/float) – the value to multiply from

  • arg (int/float) – the value to multiply with

Returns:

The multiplication result

Return type:

int/float

swh.web.utils.swh_templatetags.key_value(dict, key)[source]#

Django template filter to get a value in a dictionary.

Parameters:
  • dict (dict) – a dictionary

  • key (str) – the key to lookup value

Returns:

The requested value in the dictionary

swh.web.utils.swh_templatetags.visit_type_savable(visit_type: str) bool[source]#

Django template filter to check if a save request can be created for a given visit type.

Args:

visit_type: the type of visit

Returns:

If the visit type is saveable or not

swh.web.utils.swh_templatetags.split(value, arg)[source]#

Django template filter to split a string.

Parameters:
  • value (str) – the string to split

  • arg (str) – the split separator

Returns:

the split string parts

Return type:

list

swh.web.utils.swh_templatetags.static_path_exists(path: str) bool[source]#

Django template filter to check a static path exists.

Parameters:

path – static path to check existence.

Returns:

Whether the path exists.