utils — Swingtime Utilities

Common features and functions for swingtime

Functions

html_mark_safe

utils.html_mark_safe(func)

Decorator for functions return strings that should be treated as template safe.

time_delta_total_seconds

utils.time_delta_total_seconds(time_delta)

Calculate the total number of seconds represented by a datetime.timedelta object

month_boundaries

utils.month_boundaries([dt=None])

Return a 2-tuple containing the datetime instances for the first and last dates of the current month or using dt as a reference.

css_class_cycler

utils.css_class_cycler()

Return a dictionary keyed by EventType abbreviations, whose values are an iterable or cycle of CSS class names.

create_timeslot_table

utils.create_timeslot_table([dt=None, items=None, start_time=swingtime_settings.TIMESLOT_START_TIME, end_time_delta=swingtime_settings.TIMESLOT_END_TIME_DURATION, time_delta=swingtime_settings.TIMESLOT_INTERVAL, min_columns=swingtime_settings.TIMESLOT_MIN_COLUMNS, css_class_cycles=css_class_cycler, proxy_class=DefaultOccurrenceProxy])

Create a grid-like object representing a sequence of times (rows) and columns where cells are either empty or reference a wrapper object for event occasions that overlap a specific time slot.

Currently, there is an assumption that if an occurrence has a start_time that falls with the temporal scope of the grid, then that start_time will also match an interval in the sequence of the computed row entries.

dt
a datetime.datetime instance or None to default to now
items
a queryset or sequence of Occurrence instances. If None, default to the daily occurrences for dt
start_time
a datetime.time instance, defaulting to swingtime_settings.TIMESLOT_START_TIME
end_time_delta
a datetime.timedelta instance, defaulting to swingtime_settings.TIMESLOT_END_TIME_DURATION
time_delta
a datetime.timedelta instance, defaulting to swingtime_settings.TIMESLOT_INTERVAL
min_column
the minimum number of columns to show in the table, defaulting to swingtime_settings.TIMESLOT_MIN_COLUMNS
css_class_cycles
if not None, a callable returning a dictionary keyed by desired EventType abbreviations with values that iterate over progressive CSS class names for the particular abbreviation; defaults to css_class_cycler()
proxy_class
a wrapper class for accessing an Occurrence object, which should also expose event_type and event_class attrs, and handle the custom output via its __unicode__ method; defaults to DefaultOccurrenceProxy

Classes

BaseOccurrenceProxy

class utils.BaseOccurrenceProxy(object)

A simple wrapper class for handling the representational aspects of an Occurrence instance.

DefaultOccurrenceProxy

class utils.DefaultOccurrenceProxy(BaseOccurrenceProxy)

Through the __unicode__ method, outputs a safe string anchor tag for the Occurrence instance, followed by simple token placeholders to represent additional slot fillings.