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.

https://djangosnippets.org/snippets/2369/

intranet.utils.cache module

class intranet.utils.cache.DummyCache(host, *args, **kwargs)[source]

Bases: django.core.cache.backends.dummy.DummyCache

delete_pattern(key, version=None)[source]

intranet.utils.date module

intranet.utils.date.get_date_range_this_year(now=None)[source]

Return the starting and ending date of the current school year.

intranet.utils.date.is_current_year(date)[source]

intranet.utils.deletion module

intranet.utils.deletion.handle_eighth_sponsor_deletion(in_obj, eighth_sponsor)[source]
intranet.utils.deletion.set_historical_user(collector, field, sub_objs, using)[source]

intranet.utils.helpers module

class intranet.utils.helpers.GlobList[source]

Bases: list

A list of glob-style strings.

__contains__(key)[source]

Check if a string matches a glob in the list.

class intranet.utils.helpers.InvalidString[source]

Bases: str

An error for undefined context variables in templates.

class intranet.utils.helpers.MigrationMock[source]

Bases: object

seen = {}
intranet.utils.helpers.dark_mode_enabled(request)[source]
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.get_ap_week_warning(request)[source]
intranet.utils.helpers.get_current_commit_date()[source]
intranet.utils.helpers.get_current_commit_github_url(workdir)[source]
intranet.utils.helpers.get_current_commit_info()[source]
intranet.utils.helpers.get_current_commit_long_hash(workdir)[source]
intranet.utils.helpers.get_current_commit_short_hash(workdir)[source]
intranet.utils.helpers.get_fcps_emerg(request)[source]

Return FCPS emergency information.

intranet.utils.helpers.get_id(obj)[source]
intranet.utils.helpers.is_entirely_digit(digit_str)[source]
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.helpers.parse_db_url(db_url)[source]
intranet.utils.helpers.single_css_map(name)[source]

intranet.utils.html module

Internal callback for nullify_links().

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.html.safe_fcps_emerg_html(text: str, base_url: str) → str[source]
intranet.utils.html.safe_html(txt)[source]

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 a SELECT 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.

Parameters

items – An iterable of Model instances, ``Manager``s, and/or ``QuerySet``s representing the database rows to lock.

intranet.utils.serialization module

intranet.utils.serialization.safe_json(obj)[source]

intranet.utils.session module

class intranet.utils.session.SessionStore(session_key=None)[source]

Bases: redis_sessions.session.SessionStore

load()[source]

Module contents