Subtitle Workflows

Subtitle workflows control how subtitle sets get edited and published. In particular they control:

  • Work Modes – Tweak the subtitle editor behavior (for example review mode)
  • Actions – User actions that can be done to subtitle sets (Publish, Approve, Send back, etc).
  • Permissions – Who can edit subtitles, who can view private subtitles
class subtitles.workflows.Workflow(video)

A workflow class controls the overall workflow for editing and publishing subtitles. Workflows control the work modes, actions, and permissions for a set of subtitles.

By default, we use a workflow that makes sense for public videos – Anyone can edit, the only action is Publish, etc. However, other components can create custom workflows for specific videos by:

  • Creating a Workflow subclass
  • Overriding get_workflow() and returning a custom workflow object
get_work_mode(user, language_code)

Get the work mode to use for an editing session

Parameters:
  • user (User) – user who is editing
  • language_code (str) – language being edited
Returns:

WorkMode object to use

get_actions(user, language_code)

Get available actions for a user

Parameters:
  • user (User) – user who is editing
  • language_code (str) – language being edited
Returns:

list of Action objects that are available to the user.

action_for_add_subtitles(user, language_code, complete)

Get an action to use for add_subtitles()

This is used when pipeline.add_subtitles() is called, but not passed an action. This happens for a couple reasons:

  • User saves a draft (in which case complete will be None)
  • User is adding subtitles via the API (complete can be True, False, or None)

Subclasses can override this method if they want to use different actions to handle this case.

Parameters:
  • user (User) – user adding subtitles
  • language_code (str) – language being edited
  • complete (bool or None) – complete arg from add_subtitles()
Returns:

Action object or None.

get_add_language_mode(user)

Control the add new language section of the video page

Parameters:user (User) – user viewing the page
Returns:
  • None/False: Don’t display anything
  • “<standard>”: Use the standard behavior – a link that opens the create subtitles dialog.
  • any other string: Render this in the section. You probably want to send the string through mark_safe() to avoid escaping HTML tags.
user_can_view_private_subtitles(user, language_code)

Check if a user can view private subtitles

Private subtitles are subtitles with visibility or visibility_override set to “private”. A typical use is to limit viewing of the subtitles to members of a team.

Returns:True/False
user_can_edit_subtitles(user, language_code)

Check if a user can edit subtitles

Returns:True/False
subtitles.workflows.get_workflow(video)

Get the workflow to use for a subtitle set

This method uses the behaviors module, to allow other apps to override this and control the workflow for specific subtitles sets. A typical example is the tasks system which creates a custom workflow for videos owned by tasks teams.

Work Modes

class subtitles.workflows.WorkMode

Work modes are used to change the workflow section of the editor and affect the overall feel of the editing session. Currently we only have 2 work modes:

  • class NormalWorkMode

    The usual work mode with typing/syncing/review steps.

  • class subtitles.workflows.ReviewWorkMode(heading)

    Review someone else’s work (for example a review/approve task)

    Parameters:heading (str) – heading to display in the workflow area

Actions

Actions are things things that users can do to a subtitle set other than changing the actual subtitles. They correspond to the buttons in the editor at the bottom of the workflow session (publish, endorse, send back, etc). Actions can occur alongside changes to the subtitle lines or independent of them.

class subtitles.workflows.Action

Base class for actions

Other components can define new actions by subclassing Action, setting the class attributes, then implementing do_perform().

name = NotImplemented

Machine-friendly name

label = NotImplemented

human-friendly label. Strings should be run through ugettext_lazy()

in_progress_text = NotImplemented

text to display in the editor while this action is being performed. Strings should be run through ugettext_lazy()

visual_class = None

visual class to render the action with. This controls things like the icon we use in our editor button. Must be one of the CLASS_ constants

complete = None

complete defines how to handle subtitles_complete. There are 3 options:

  • True – this action sets subtitles_complete
  • False – this action unsets subtitles_complete
  • None (default) - this action doesn’t change subtitles_complete
subtitle_visibility = 'public'

Visibility value for newly created SubtitleVerisons.

CLASS_ENDORSE = 'endorse'

endorse/approve buttons

CLASS_SEND_BACK = 'send-back'

reject/send-back buttons

perform(user, video, subtitle_language, saved_version)

Perform this action

Parameters:
  • user (User) – User performing the action
  • video (Video) – Video being changed
  • subtitle_language (SubtitleLanguage) – SubtitleLanguage being changed
  • saved_version (SubtitleVersion or None) – new version that was created for subtitle changes that happened alongside this action. Will be None if no changes were made.
do_perform(user, video, subtitle_language, saved_version)

Does the work to perform this action. Subclasses must implement this method.

Notes

  • If complete is set to True or False, we will already have updated subtitles_complete at this point.
  • We will save the SubtitleLanguage after do_perform runs, so don’t save it yourself.
send_signals(subtitle_language, version)

Send signals after an action

This is called at the end of perform() and pipeline.add_subtitles().

Parameters:
  • subtitle_language (SubtitleLanguage) – changed language
  • version (SubtitleVersion) – new subtitle version or None
editor_data()

Get a dict of data to pass to the editor for this action.

class subtitles.workflows.Publish

Publish action

Publish sets the subtitles_complete flag to True