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.timedeltaobject
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
dtas a reference.
css_class_cycler¶
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_timethat falls with the temporal scope of the grid, then thatstart_timewill also match an interval in the sequence of the computed row entries.dt- a
datetime.datetimeinstance orNoneto default to now items- a queryset or sequence of
Occurrenceinstances. IfNone, default to the daily occurrences fordt start_time- a
datetime.timeinstance, defaulting toswingtime_settings.TIMESLOT_START_TIME end_time_delta- a
datetime.timedeltainstance, defaulting toswingtime_settings.TIMESLOT_END_TIME_DURATION time_delta- a
datetime.timedeltainstance, defaulting toswingtime_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 desiredEventTypeabbreviations with values that iterate over progressive CSS class names for the particular abbreviation; defaults tocss_class_cycler() proxy_class- a wrapper class for accessing an
Occurrenceobject, which should also exposeevent_typeandevent_classattrs, and handle the custom output via its __unicode__ method; defaults toDefaultOccurrenceProxy
Classes¶
BaseOccurrenceProxy¶
-
class
utils.BaseOccurrenceProxy(object)¶ A simple wrapper class for handling the representational aspects of an
Occurrenceinstance.
DefaultOccurrenceProxy¶
-
class
utils.DefaultOccurrenceProxy(BaseOccurrenceProxy)¶ Through the
__unicode__method, outputs a safe string anchor tag for theOccurrenceinstance, followed by simple token placeholders to represent additional slot fillings.