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

Overriding workflows

By default, we use a workflow that makes sense for public videos – Anyone can edit, the only action is Publish, etc.

To override the workflow by Video (for example for videos in a certain type of team):

To override the workflow for by SubtitleLanguage (for example you can override the workflow for the SubtitleLanguage covered by professional service request):

Workflow Classes

class subtitles.workflows.VideoWorkflow(video)

VideoWorkflow subclasses work with LanguageWorkflow subclasses to control the overall workflow for editing and publishing subtitles. Workflows control the work modes, actions, permissions, etc. for subtitle sets.

user_can_view_video(user)

Check if a user can view the video

Returns:True/False
user_can_edit_video(user)

Check if a user can view the video

Returns:True/False
get_add_language_mode(user)

Control the add new language section of the video page

Parameters:user (User) – user viewing the page
Returns:Value that specifies how the section should appear
  • 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.
extra_tabs(user)

Get extra tabs for the videos page

Returns:list of (name, title) tuples. Name is used for the tab id, title is a human friendly title.

For each tab name you should create a video-<name>.html and video-<name>-tab.html templates. If you need to pass variables to those templates, create a setup_tab_<name> method that inputs the same args as the methods from VideoPageContext and returns a dict of variables for the template.

get_default_language_workflow(language_code)

Get the default LanguageWorkflow for this VideoWorkflow.

This will be used unless some other component overrides it with get_language_workflow()

class subtitles.workflows.LanguageWorkflow(video, language_code)
get_work_mode(user)

Get the work mode to use for an editing session

Parameters:user (User) – user who is editing
Returns:WorkMode object to use
Return type::class
get_actions(user)

Get available actions for a user

Parameters:user (User) – user who is editing
Returns:class:Action objects that are available to the user.
Return type:list of
action_for_add_subtitles(user, 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
  • complete (bool or None) – complete arg from add_subtitles()
Returns:

Action object or None.

get_editor_notes(user)

Get notes to display in the editor

Returns:EditorNotes object
Return type::class
user_can_view_private_subtitles(user)

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_delete_subtitles(user, language_code)

Check if a user can delete a language

Returns:True/False
user_can_edit_subtitles(user)

Check if a user can edit subtitles

Returns:True/False

Behavior Functions

subtitles.workflows.get_workflow(video)

Get the workflow to use for a video.

By default this method returns the workflow for public, non-team videos. Other apps can override it to customize the behavior.

subtitles.workflows.get_language_workflow(video, language_code)

Override the default LanguageWorkflow for a subtitle set

Normally this method returns None, which means use the default for the VideoWorkflow. Other apps can override this and control the workflow for specific video languages.

See also

behaviors module for how you can override these functions.

Editor Notes

class subtitles.workflows.EditorNotes(video, language_code)

Manage notes for the subtitle editor.

EditorNotes handles fetching notes for the editor and posting new ones.

heading

heading for the editor section

notes

list of SubtitleNotes for the editor (or any model that inherits from SubtitleNoteBase)

post(user, body)

Add a new note.

Parameters:
  • user (CustomUser) – user adding the note
  • body (unicode) – note text

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 ReviewWorkMode(heading, help_text=None)

    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, and optionally implementing perform().

name

Machine-friendly name

label

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

in_progress_text

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

visual_class

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

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

Visibility value for newly created

SubtitleVersions("public" or "private")
CLASS_ENDORSE

visual class constant for endorse/approve buttons

CLASS_SEND_BACK

visual class constant for reject/send-back buttons

require_synced_subtitles()

Should we require that all subtitles have timings?

The default implementation uses the complete attribute

validate(user, video, subtitle_language, saved_version)

Check if we can 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.
Raises:

ActionError – this action can’t be performed

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.
update_language(user, video, subtitle_language, saved_version)

Update the subtitle language after adding subtitles

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.
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