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: 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.get_senior_graduation_date()[source]
intranet.utils.date.get_senior_graduation_year(*, now=None)[source]
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(iterable=(), /)[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: Set[str] = {}
intranet.utils.helpers.awaredate()[source]
intranet.utils.helpers.dark_mode_enabled(request)[source]
intranet.utils.helpers.debug_toolbar_callback(request)[source]
In development:

Show the debug toolbar to all users.

In production:

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]

ap_day = timezone.localtime() if ap_day.hour > 16:

ap_day += datetime.timedelta(days=1)

while ap_day.weekday() >= 5: # Saturday or Sunday

ap_day += datetime.timedelta(days=1)

data = {“day”: ap_day.day, “date”: request.GET.get(“date”, None)} if ap_day.month == 5 and 4 <= ap_day.day <= 17:

return get_template(“auth/ap_week_schedule.html”).render(data)

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.get_theme() Dict[str, Dict[str, str]][source]

Return JS and CSS for the currently active special event theme.

intranet.utils.helpers.get_theme_name() str[source]

Get the name of the currently active special event theme.

intranet.utils.helpers.get_warning_html(warnings, dashboard=False, login=False)[source]

Returns HTML for announcements.models.WarningAnnouncement objects. Dashboard and login logic is processed here because they cannot be filtered using .filter(). Global warnings are pre-filtered and passed directly to this function from the context processor.

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

intranet.utils.html.get_domain_name(url)[source]

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[Model, Manager, 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: SessionStore

load()[source]

Module contents