コード例 #1
0
def create_subtitles(request, video_id):
    try:
        video = Video.cache.get_instance_by_video_id(video_id, 'video-page')
    except Video.DoesNotExist:
        raise Http404

    workflow = video.get_workflow()
    if not workflow.user_can_create_new_subtitles(request.user):
        raise PermissionDenied()

    team_slug = request.GET.get('team', None)
    if request.method == 'POST':
        if team_slug:
            form = TeamCreateSubtitlesForm(request, video, team_slug, request.POST)
        else:
            form = CreateSubtitlesForm(request, video, request.POST)

        if form.is_valid():
            form.set_primary_audio_language()
            response_renderer = AJAXResponseRenderer(request)
            response_renderer.redirect(form.editor_url())
            return response_renderer.render()
    else:
        if team_slug:
            form = TeamCreateSubtitlesForm(request, video, team_slug)
        else:
            form = CreateSubtitlesForm(request, video)

    response_renderer = AJAXResponseRenderer(request)
    response_renderer.show_modal('future/videos/create-subtitles-modal.html', {
        'form': form,
        'video': video,
    })
    return response_renderer.render()
コード例 #2
0
 def __init__(self, request, video, video_url, tab, workflow,
              tab_only=False):
     dict.__init__(self)
     self.workflow = workflow
     self['video'] = video
     self['create_subtitles_form'] = CreateSubtitlesForm(
         request, video, request.POST or None)
     self['extra_tabs'] = workflow.extra_tabs(request.user)
     if not tab_only:
         self.setup(request, video, video_url)
     self.setup_tab(request, video, video_url, tab)
コード例 #3
0
 def __init__(self, request, video, lang_code, lang_id, version_id,
              tab_only=False):
     dict.__init__(self)
     language = self._get_language(video, lang_code, lang_id)
     self.public_only = self.calc_public_only(request, video,
                                              language.language_code)
     version = self._get_version(request, video, language, version_id)
     self['video'] = video
     self['language'] = language
     self['version'] = version
     self['user'] = request.user
     self['create_subtitles_form'] = CreateSubtitlesForm(
         request, video, request.POST or None)
     if not tab_only:
         self.setup(request, video, language, version)
     self.setup_tab(request, video, language, version)
コード例 #4
0
def video(request, video_id, video_url=None, title=None):
    if should_use_old_view(request):
        return oldviews.video(request, video_id, video_url, title)
    if request.is_ajax() and 'form' in request.POST:
        return video_ajax_form(request, video_id)
    request.use_cached_user()
    try:
        video = Video.cache.get_instance_by_video_id(video_id, 'video-page')
    except Video.DoesNotExist:
        raise Http404
    if not video.can_user_see(request.user):
        raise PermissionDenied()

    if video_url:
        video_url = get_object_or_404(video.videourl_set, pk=video_url)
    else:
        video_url = video.get_primary_videourl_obj()

    workflow = video.get_workflow()
    if workflow.user_can_create_new_subtitles(request.user):
        form_name = request.GET.get('form', '')
        if form_name == 'create-subtitles':
            return create_subtitles(request, video_id)
        else:
            # this is the old code for creating the CreateSubtitlesForm
            create_subtitles_form = CreateSubtitlesForm(request,video)
    else:
        create_subtitles_form = None
    if request.user.is_authenticated():
        comment_form = CommentForm(video)
    else:
        comment_form = None
    if permissions.can_user_edit_video_urls(video, request.user):
        create_url_form = NewCreateVideoUrlForm(video, request.user)
        allow_delete = allow_make_primary = True
    else:
        create_url_form = None
        allow_delete = allow_make_primary = False

    customization = behaviors.video_page_customize(request, video)
    all_activities = ActivityRecord.objects.for_video(
        video, customization.team)

    if request.is_ajax() and request.GET.get('show-all', None):
        response_renderer = AJAXResponseRenderer(request)
        response_renderer.replace(
            '#video_activity', "future/videos/tabs/activity.html", {
                'activity': all_activities,
            },
        )
        return response_renderer.render()

    activity = all_activities[:ACTIVITY_PER_PAGE]
    show_all = False if len(activity) >= len(all_activities) else True

    sanity_check_video_urls(request, video)

    return render(request, 'future/videos/video.html', {
        'video': video,
        'player_url': video_url.url,
        'team': video.get_team(),
        'team_video': video.get_team_video(),
        'tab': request.GET.get('tab', 'info'),
        'allow_delete': allow_delete,
        'allow_make_primary': allow_make_primary,
        'create_subtitles_form': create_subtitles_form,
        'comment_form': comment_form,
        'create_url_form': create_url_form,
        'comments': Comment.get_for_object(video),
        'activity': activity,
        'activity_count': 1,
        'show_all': show_all,
        'metadata': video.get_metadata().convert_for_display(),
        'custom_sidebar': customization.sidebar,
        'header': customization.header,
        'use_old_messages': True,
        'video_urls': [
            (vurl, get_sync_account(video, vurl))
            for vurl in video.get_video_urls()
        ],
    })
コード例 #5
0
 def make_form(self, data=None):
     return CreateSubtitlesForm(self.make_mock_request(),
                                self.video,
                                data=data)
コード例 #6
0
ファイル: forms.py プロジェクト: norayr/unisubs
 def handle_post(self):
     self.task.language = self.cleaned_data['subtitle_language_code']
     self.task.save()
     return CreateSubtitlesForm.handle_post(self)
コード例 #7
0
ファイル: forms.py プロジェクト: norayr/unisubs
 def __init__(self, request, task, data=None):
     CreateSubtitlesForm.__init__(self, request, task.team_video.video,
                                  data)
     self.task = task