ae.django_utils

helpers for django projects

this module is providing helper functions for your django projects.

Functions

generic_language(lang_code)

remove the country specific part - if exists - from the passed language code.

requested_language()

determine the currently requested short translation language code, fallback to english/'en' if unset.

set_url_part(url[, fragment, query])

add or replace fragment and/or query string of url.

generic_language(lang_code)[source]

remove the country specific part - if exists - from the passed language code.

Parameters:

lang_code (str) – lower-case language code with optional hyphen and country specific part.

Return type:

str

Returns:

stripped/short language code (e.g. return “en” if lang_code == “en-gb”)

requested_language()[source]

determine the currently requested short translation language code, fallback to english/’en’ if unset.

Return type:

str

Returns:

short (without country specific part) and lower-case language code

set_url_part(url, fragment='', query='', **set_part_values)[source]

add or replace fragment and/or query string of url.

Parameters:
  • url (str) – url to complete by adding and/or updating parts of it.

  • fragment (str) – id of the fragment to add/replace.

  • query (str) – query string to add/replace.

  • set_part_values – other parts like ‘scheme’, ‘netloc’, ‘path’, ‘params’ (see :func:urllib.parse.urlparse).

Return type:

str

Returns:

url with added/replaced parts.