Template Tags
django_spire.core.templatetags.spire_core_tags
register = template.Library()
module-attribute
T = TypeVar('T', bound=Model)
module-attribute
U = TypeVar('U')
module-attribute
add_str
Concatenates two strings.
Parameters:
Returns:
-
str
–The concatenated string.
Source code in django_spire/core/templatetags/spire_core_tags.py
content_type_url
Constructs a URL for a given content type using the object's metadata.
Parameters:
-
url_name
(str
) –The name of the URL pattern.
-
obj
(T
) –A Django model instance whose metadata is used to construct the URL.
-
kwargs
–Additional keyword arguments for URL reversal.
Returns:
-
str
–The reversed URL as a string.
Source code in django_spire/core/templatetags/spire_core_tags.py
in_list
Checks if a string is present in a comma-separated list.
Parameters:
Returns:
-
bool
–True if the value is present, False otherwise.
Source code in django_spire/core/templatetags/spire_core_tags.py
index
Returns the element at the given index from an indexable or the entire indexable if the index is out-of-bounds.
Parameters:
-
indexable
(Sequence[U]
) –A sequence from which to retrieve an element.
-
index_value
(int
) –The index of the element to retrieve.
Returns:
-
U | Sequence[U]
–The element at the specified index, or the original sequence if the index is out-of-bounds.
Source code in django_spire/core/templatetags/spire_core_tags.py
generate_id
Generates an 8-character random string using ASCII letters.
Returns:
-
str
–An 8-character random string.
Source code in django_spire/core/templatetags/spire_core_tags.py
not_in_list
Checks if a string is not present in a comma-separated list.
Parameters:
Returns:
-
bool
–True if the value is not present, False otherwise.
Source code in django_spire/core/templatetags/spire_core_tags.py
query_param_url
Generates a URL by appending the query parameters from the request context to a reversed URL.
Parameters:
-
context
(RequestContext
) –A RequestContext containing the current request.
-
url_name
(str
) –The name of the URL pattern.
-
kwargs
–Additional keyword arguments for URL reversal.
Returns:
-
str
–The generated URL with query parameters appended as a string.
Source code in django_spire/core/templatetags/spire_core_tags.py
to_snake_case
Converts a label to snake_case by replacing spaces with underscores and then converting it to lowercase.
Parameters:
-
label
(str
) –The label string to convert.
Returns:
-
str
–The snake_case version of the label.