def _create_necessary_tasks(version, team_video, workflow, committer, complete): """Create any necessary tasks for the newly added version. By the time we call this function we know that: * There are no existing open tasks for this version/language. * The committer cannot bypass moderation. So we may (or may not) need to create a task for this version/language. """ from teams.models import Task if complete: # If the subtitles are complete, then the new task will be either # a review or approve, depending on the team. if workflow.review_allowed: task_type = Task.TYPE_IDS['Review'] elif workflow.approve_allowed: task_type = Task.TYPE_IDS['Approve'] else: # Note that we may not have selected either of these, if the team # does not require review or approval. That's okay, we're done in # that case. return else: # Otherwise the new task will be a subtitle or translate, depending # on the type of subs. # TODO: More advanced logic here? if version.subtitle_language.is_primary_audio_language(): task_type = Task.TYPE_IDS['Subtitle'] else: task_type = Task.TYPE_IDS['Translate'] # We now know the type of task we need to create, so go ahead and make it. task = Task(team=team_video.team, team_video=team_video, language=version.language_code, type=task_type, new_subtitle_version=version) # Assign it to the correct user. if task.get_type_display() in ('Subtitle', 'Translate'): # If it's a subtitle/translate task, then someone just added # some incomplete subtitles. We'll assign it to them by # default. task.assignee = committer else: # Otherwise it's a review/approve task, so we'll see if anyone # has reviewed or approved this before. If so, assign it back # to them. Otherwise just leave it unassigned. task.assignee = task._find_previous_assignee(task.get_type_display()) task.save()
def _moderate_incomplete_version(self, subtitle_version, user): """ Verifies if it's possible to create a transcribe/translate task (if there's no other transcribe/translate task) and tries to assign to user. Also, if the video belongs to a team, change its status. """ team_video = subtitle_version.video.get_team_video() if not team_video: return language = subtitle_version.language.language # if there's any incomplete task, we can't create yet another. transcribe_task = team_video.task_set.incomplete().filter( language=language) if transcribe_task.exists(): return subtitle_version.moderation_status = WAITING_MODERATION subtitle_version.save() if subtitle_version.is_dependent(): task_type = Task.TYPE_IDS['Translate'] can_do = can_create_and_edit_translations else: task_type = Task.TYPE_IDS['Subtitle'] can_do = can_create_and_edit_subtitles task = Task(team=team_video.team, team_video=team_video, language=language, type=task_type) if can_do(user, team_video): task.assignee = user task.save()
def save_subtitles(self, parser, video=None, language=None, update_video=True, is_complete=True): video = video or self.cleaned_data['video'] if not video.has_original_language(): self._save_original_language(video, self.cleaned_data['video_language']) if language: self._sl_created = False language = language else: language, self._sl_created = self._find_appropriate_language( video, self.cleaned_data['language']) language = save_subtitle(video, language, parser, self.user, update_video) # If there are any outstanding tasks for this language, associate the # new version with them. team_video = video.get_team_video() if team_video: new_version = language.latest_version(public_only=False) # TODO: Refactor all of this out into some kind of generic "add subtitles" pipeline. # Determine if we need to moderate these subtitles and create a # review/approve task for them. workflow = team_video.get_workflow() # user can bypass moderation if: # 1) he is a moderator and # 2) it's a post-publish edit # 3) subtitle is complete can_bypass_moderation = (is_complete and not self._sl_created and can_publish_edits_immediately( team_video, self.user, language.language)) if can_bypass_moderation: new_version.moderate = APPROVED elif workflow.review_allowed or workflow.approve_allowed: new_version.moderation_status = WAITING_MODERATION else: new_version.moderation_status = UNMODERATED new_version.save() outstanding_tasks = team_video.task_set.incomplete().filter( language__in=[language.language, '']) if outstanding_tasks.exists(): if new_version.moderation_status != WAITING_MODERATION: outstanding_tasks.update(subtitle_version=new_version, language=language.language) elif not can_bypass_moderation: # we just need to create review/approve/subtitle if the language # is a new one or, if it's a post-publish edit, if the user can't # approve subtitles by himself. task_type = None if new_version.is_synced() and is_complete: if workflow.review_allowed: task_type = Task.TYPE_IDS['Review'] elif workflow.approve_allowed: task_type = Task.TYPE_IDS['Approve'] else: task_type = Task.TYPE_IDS['Subtitle'] if task_type: task = Task(team=team_video.team, team_video=team_video, language=language.language, type=task_type, subtitle_version=new_version) if not self._sl_created: task.assignee = task._find_previous_assignee( Task.TYPE_NAMES[task_type]) else: if task_type == Task.TYPE_IDS['Subtitle']: task.assignee = self.user task.save() return language