intranet.utils package¶
Submodules¶
intranet.utils.admin_helpers module¶
-
intranet.utils.admin_helpers.
export_csv_action
(description='Export selected objects as CSV file', fields=None, exclude=None, header=True)[source]¶ This function returns an export csv action.
‘fields’ and ‘exclude’ work like in django
ModelForm ‘header’ is whether or not to output the column names as the first row.
intranet.utils.cache module¶
intranet.utils.date module¶
intranet.utils.deletion module¶
intranet.utils.helpers module¶
-
class
intranet.utils.helpers.
InvalidString
[source]¶ Bases:
str
An error for undefined context variables in templates.
-
intranet.utils.helpers.
debug_toolbar_callback
(request)[source]¶ Show the debug toolbar to those with the Django staff permission, excluding the Eighth Period office.
-
intranet.utils.helpers.
join_nicely
(items: Collection) → str[source]¶ Joins together a list of items in a human-readable format. Examples: >>> join_nicely([]) ‘’ >>> join_nicely([‘a’]) ‘a’ >>> join_nicely([‘a’, ‘b’]) ‘a and b’ >>> join_nicely([‘a’, ‘b’, ‘c’]) ‘a, b, and c’
- Parameters
items – The items to join together.
- Returns
The resulting joined-together string.
intranet.utils.html module¶
-
intranet.utils.html.
link_removal_callback
(attrs: Mapping[Union[str, Tuple[Optional[str]]], str], new: bool = False) → Optional[Mapping[Union[str, Tuple[Optional[str]]], str]][source]¶ Internal callback for
nullify_links()
.
-
intranet.utils.html.
nullify_links
(text: str) → str[source]¶ Given a string containing HTML, changes the
href
attribute of any links to “javascript:void(0)” to render the link useless.- Parameters
text – The HTML string in which links should be nullified.
- Returns
The HTML string with all links nullified.
intranet.utils.locking module¶
-
intranet.utils.locking.
lock_on
(items: Iterable[Union[django.db.models.base.Model, django.db.models.manager.Manager, django.db.models.query.QuerySet]]) → None[source]¶ Given an iterable of
Model
instances, ``Manager``s, and/or ``QuerySet``s, locks the corresponding database rows.More specifically, this uses the Django ORM’s
select_for_update()
method, which translates to aSELECT FOR UPDATE
SQL query. For more information on what this actually does in PostgreSQL (used as the database backend in all environments) see PostgreSQL’s documentation on locking at https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-ROWS.As described in Django’s documentation at https://docs.djangoproject.com/en/stable/ref/models/queryset/#django.db.models.query.QuerySet.select_for_update, the
select_for_update
locks prevent other transactions from acquiring locks until this transaction is complete.This MUST by run in a transaction. A straightforward way to do this is to use the
django.db.transaction.atomic
wrapper.