def rollback(request, version): is_writelocked = version.subtitle_language.is_writelocked team_video = version.video.get_team_video() if team_video and not can_rollback_language(request.user, version.subtitle_language): messages.error( request, _(u"You don't have permission to rollback " "this language")) elif is_writelocked: messages.error( request, u'Can not rollback now, because someone is editing subtitles.') elif not version.next_version(): messages.error(request, message=u'Can not rollback to the last version') else: messages.success(request, message=u'Rollback successful') version = rollback_to(version.video, version.subtitle_language.language_code, version_number=version.version_number, rollback_author=request.user) video_changed_tasks.delay(version.video.id, version.id) return redirect(version.subtitle_language.get_absolute_url() + '#revisions') return redirect(version)
def save(self): # If the primary audio language code was given, we adjust it on the # video NOW, before saving the subtitles, so that the pipeline can take # it into account when determining task types. self._save_primary_audio_language_code() language_code = self.cleaned_data['language_code'] from_language_code = self.cleaned_data['from_language_code'] complete = self.cleaned_data['complete'] subtitles = self._parsed_subtitles if from_language_code: # If this is a translation, its subtitles should use the timing data # from the source. We know that the source has at least as many # subtitles as the new version, so we can just match them up # first-come, first-serve. source_subtitles = self.from_sv.get_subtitles() i = 0 # instead of translating to subtitle_items, we're updating the # dfxp elements in place. This guarantees no monkey business with # escaping / styling for old, new in izip(source_subtitles.subtitle_items(), subtitles.get_subtitles()): subtitles.update(i, from_ms=old.start_time, to_ms=old.end_time) i += 1 else: # Otherwise we can just use the subtitles the user uploaded as-is. # No matter what, text files that aren't translations cannot be # complete because they don't have timing data. if self.extension == 'txt': complete = False title, description = self._find_title_description(language_code) parents = self._find_parents(from_language_code) version = pipeline.add_subtitles(self.video, language_code, subtitles, title=title, description=description, author=self.user, parents=parents, committer=self.user, complete=complete, origin=ORIGIN_UPLOAD) # Handle forking SubtitleLanguages that were translations when # a standalone version is uploaded. # # For example: assume there is a French translation of English. # Uploading a "straight from video" version of French should fork it. sl = version.subtitle_language if not from_language_code and is_dependent(sl): sl.fork() # TODO: Pipeline this. video_changed_tasks.delay(sl.video_id, version.id) return version
def reset_metadata(request, video_id): video = get_object_or_404(Video, video_id=video_id) video_changed_tasks.delay(video.id) return HttpResponse('ok')