Utility
mark_safe_lazy = lazy(mark_safe, str)
module-attribute
Deprecated: A lazy wrapper for mark_safe function.
This function is deprecated and obsolete as of Django 4.1. It was previously used to create lazy versions of marked-safe strings, typically for form help text with HTML.
See
https://docs.djangoproject.com/en/4.1/releases/4.1/#utilities
get_django_countries_dict()
Retrieves dictionaries mapping country codes to names and vice versa.
Returns:
| Type | Description |
|---|---|
tuple[dict[str, str], dict[str, str]]
|
Tuple[Dict[str, str], Dict[str, str]]: A tuple containing: - code_name: Dict mapping country codes to uppercase country names - name_code: Dict mapping uppercase country names to codes |
Raises:
| Type | Description |
|---|---|
ImportError
|
If django-countries package is not installed. |
Source code in django_util/utility.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
init_django(django_dir, project_name=None)
Initializes Django environment for external Python scripts or notebooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
django_dir
|
str
|
Path to Django project directory. |
required |
project_name
|
Optional[str]
|
Name of the Django project. If None, will check DJANGO_PROJECT env var. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If project_name is not provided and DJANGO_PROJECT environment variable is not set. |
ImportError
|
If Django cannot be imported or setup fails. |
Source code in django_util/utility.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
is_object_creator(object, profile)
Check if the given profile is the creator of the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object
|
The object to check ownership of. |
required | |
profile
|
The profile to verify as the creator. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the profile is the creator of the object, False otherwise. |
Source code in django_util/utility.py
70 71 72 73 74 75 76 77 78 79 80 | |