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 _create_review_or_approve_task(self, subtitle_version): team_video = subtitle_version.video.get_team_video() lang = subtitle_version.subtitle_language.language_code workflow = Workflow.get_for_team_video(team_video) if workflow.review_allowed: type = Task.TYPE_IDS['Review'] can_do = partial(can_review, allow_own=True) elif workflow.approve_allowed: type = Task.TYPE_IDS['Approve'] can_do = can_approve else: return None # TODO: Dedupe this and Task._find_previous_assignee # Find the assignee. # # For now, we'll assign the review/approval task to whomever did # it last time (if it was indeed done), but only if they're # still eligible to perform it now. last_task = team_video.task_set.complete().filter( language=lang, type=type).order_by('-completed')[:1] assignee = None if last_task: candidate = last_task[0].assignee if candidate and can_do(team_video, candidate, lang): assignee = candidate task = Task(team=team_video.team, team_video=team_video, assignee=assignee, language=lang, type=type) task.set_expiration() task.new_subtitle_version = subtitle_version if task.get_type_display() in ['Review', 'Approve']: task.new_review_base_version = subtitle_version task.save()