• Home
  • API Documentation
  • wte.helpers.frontend – Helpers for the frontend display

wte.helpers.frontend – Helpers for the frontend display¶

The frontend module provides helper functionality used to render the frontend page displays.

wte.helpers.frontend.codemirror_options(request, mimetype, include_mode=False)[source]¶

Generates a JSON representation of CodeMirror options that are valid for the given mimetype.

Parameters:
  • request (Request) – The current request
  • mimetype (unicode) – The mimetype to generate CodeMirror options for
  • include_mode (bool) – Whether to include the mode setting in the options
Returns:

The JSON representation of options

wte.helpers.frontend.codemirror_scripts(request, mimetypes)[source]¶

Generates the <script> tags necessary to load the CodeMirror mode JS files for the given list of mimetypes.

Parameters:
  • request (~pyramid.request.Request) – The request to use for generating URLs
  • mimetypes (list of unicode) – The mimetypes to load the CodeMirror modes for
Returns:

The necessary <script> tags

wte.helpers.frontend.confirm_action(title, message, cancel, ok)[source]¶

Generates a confirmation JSON object for use with the jQuery.postLink() plugin.

Parameters:
  • title (unicode) – The title of the confirmation dialog box
  • message (unicode) – The main message to show
  • cancel (dict or unicode) – The cancel button’s settings
  • ok (dict or unicode) – The ok button’s settings
Returns:

JSON object

Return type:

unicode()

wte.helpers.frontend.confirm_delete(obj_type, title, has_parts=False)[source]¶

Generates the confirmation JSON object for use with the jQuery.postLink() plugin.

Parameters:
  • obj_type (unicode) – The type of object that is being deleted
  • title (unicode) – The title of the object that is being delete
  • has_parts (bool) – Whether to add the suffix ” and all its parts”
Returns:

JSON object

Return type:

unicode()

wte.helpers.frontend.html_id(text)[source]¶

Turns a given text into a valid HTML id attribute value. Removes spaces and full-stops.

Parameters:text (unicode) – The text to convert
Returns:The corresponding HTML id
Return type:unicode()
wte.helpers.frontend.lt(a, b)[source]¶

Helper function that checks if a is less than b.

wte.helpers.frontend.natural_list(items, separator=', ', final_separator=' & ')[source]¶

Returns a string representation of the items list. For an empty list or a single item the value is returned. For a list of two items, the items are joined together using the final_separator. For a list of more than two items, the all but the last item are joined using separator and the last item is joined using final_separator.

Parameters:
  • items (list()) – The list of items to join
  • separator (unicode()) – The separator to use when more than 2 items are joined. Defaults to ‘, ‘.
  • final_separator – The separator to use for the last two items in the list. Defaults to ‘ & ‘.
Returns:

A string representation of the list

Return_type:

unicode()

wte.helpers.frontend.part_change_notification_text(request, part)[source]¶

Generates a default notification text to be emailed when changes are made to a part.

Parameters:
  • request (Request) – The current request to get the current user from
  • part (Part) – The part that is being changed
Returns:

The default notification text

Return type:

str

wte.helpers.frontend.readable_timedelta(delta)[source]¶

Converts a datetime.timedelta into a human-readable string.

Parameters:delta (datetime.timedelta) – The time-delta to convert
Returns:The human-readable string representation of the delta
Return type:unicode()
wte.helpers.frontend.set_list(items)[source]¶

Returns a string representation of the unique items in the items. The items must be a list() of tuple() (item, count) as returned by ordered_counted_set().

Parameters:items – The list of items to transform into a string
Returns:A string containing all unique items
Return_type:unicode()
wte.helpers.frontend.split_seconds(seconds)[source]¶

Converts a time in seconds into a (days, hours, minutes, seconds) tuple for use in time_string().

Parameters:seconds (int) – The time in seconds to split
Returns:A tuple (days, hours, minutes, seconds)
Return type:tuple
wte.helpers.frontend.template_for_part(part)[source]¶

Returns the correct partial template path for a given Part. If there is no partial template for the given Part, then None is returned.

Parameters:part (Part) – The Part to generate the template path for
Returns:The partial template path or None
Return_type:string
wte.helpers.frontend.time_string(days, hours, minutes, seconds)[source]¶

Converts the days, hours, minutes, and seconds into a human-readable format.

Parameters:
  • days (int()) – The number of days to the timestamp
  • hours (int()) – The number of hours to the timestamp
  • minutes (int()) – The number of minutes to the timestamp
  • seconds (int()) – The number of seconds to the timestamp
Returns:

The human-readable representation

Return type:

unicode()

wte.helpers.frontend.user_admin_menubar(request, user)[source]¶

Generates the menu bar for the users administration list.

  • wte.helpers – Helper functionality for views
  • wte.models – Database Models