Ejemplo n.º 1
0
def video(request, video_id, video_url=None, title=None):
    video = get_object_or_404(Video, video_id=video_id)
    if video_url:
        video_url = get_object_or_404(VideoUrl, pk=video_url)
    
    if not video_url and ((video.title_for_url() and not video.title_for_url() == title) or (not video.title and title)):
        return redirect(video, permanent=True)

    video.update_view_counter()
    
    # TODO: make this more pythonic, prob using kwargs
    context = widget.add_onsite_js_files({})
    context['video'] = video
    original = video.subtitle_language()
    if original:
        original.pending_moderation_count =  get_pending_count(video.subtitle_language())
    context['autosub'] = 'true' if request.GET.get('autosub', False) else 'false'
    translations = list(video.subtitlelanguage_set.filter(had_version=True) \
        .filter(is_original=False).select_related('video'))
    translations.sort(key=lambda f: f.get_language_display())
    context['translations'] = translations

    context["user_can_moderate"] = user_can_moderate(video, request.user)
    if context["user_can_moderate"]:
        # FIXME: use  amore efficient count
        for l in translations:
            l.pending_moderation_count = get_pending_count(l)
            
    context['widget_params'] = _widget_params(request, video, language=None, video_url=video_url and video_url.effective_url)
    _add_share_panel_context_for_video(context, video)
    context['lang_count'] = video.subtitlelanguage_set.filter(has_version=True).count()
    context['original'] = video.subtitle_language()
    
    return render_to_response('videos/video.html', context,
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def video(request, video_id, video_url=None, title=None):
    video = get_object_or_404(Video, video_id=video_id)
    if video_url:
        video_url = get_object_or_404(VideoUrl, pk=video_url)

    if not video_url and (
        (video.title_for_url() and not video.title_for_url() == title) or
        (not video.title and title)):
        return redirect(video, permanent=True)

    video.update_view_counter()

    # TODO: make this more pythonic, prob using kwargs
    context = widget.add_onsite_js_files({})
    context['video'] = video
    original = video.subtitle_language()
    if original:
        original.pending_moderation_count = get_pending_count(
            video.subtitle_language())
    context['autosub'] = 'true' if request.GET.get('autosub',
                                                   False) else 'false'
    translations = list(video.subtitlelanguage_set.filter(had_version=True) \
        .filter(is_original=False).select_related('video'))
    translations.sort(key=lambda f: f.get_language_display())
    context['translations'] = translations

    context["user_can_moderate"] = user_can_moderate(video, request.user)
    if context["user_can_moderate"]:
        # FIXME: use  amore efficient count
        for l in translations:
            l.pending_moderation_count = get_pending_count(l)

    context['widget_params'] = _widget_params(request,
                                              video,
                                              language=None,
                                              video_url=video_url
                                              and video_url.effective_url)
    _add_share_panel_context_for_video(context, video)
    context['lang_count'] = video.subtitlelanguage_set.filter(
        has_version=True).count()
    context['original'] = video.subtitle_language()

    return render_to_response('videos/video.html',
                              context,
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def history(request, video_id, lang=None, lang_id=None):
    video = get_object_or_404(Video, video_id=video_id)
    video.update_view_counter()

    context = widget.add_onsite_js_files({})

    if lang_id:
        try:
            language = video.subtitlelanguage_set.get(pk=lang_id)
        except SubtitleLanguage.DoesNotExist:
            raise Http404
    else:
        language = video.subtitle_language(lang)

    if not language:
        if lang in dict(settings.ALL_LANGUAGES):
            config = {}
            config["videoID"] = video.video_id
            config["languageCode"] = lang
            url = reverse('onsite_widget')+'?config='+urlquote_plus(json.dumps(config))
            return redirect(url)
        elif video.subtitlelanguage_set.count() > 0:
            language = video.subtitlelanguage_set.all()[0]
        else:
            raise Http404

    qs = language.subtitleversion_set.select_related('user')
    ordering, order_type = request.GET.get('o'), request.GET.get('ot')
    order_fields = {
        'date': 'datetime_started', 
        'user': '******', 
        'note': 'note', 
        'time': 'time_change', 
        'text': 'text_change'
    }
    if ordering in order_fields and order_type in ['asc', 'desc']:
        qs = qs.order_by(('-' if order_type == 'desc' else '')+order_fields[ordering])
        context['ordering'], context['order_type'] = ordering, order_type

    context['video'] = video
    original = video.subtitle_language()
    if original:
        original.pending_moderation_count =  get_pending_count(video.subtitle_language())
    translations = list(video.subtitlelanguage_set.filter(is_original=False) \
        .filter(had_version=True).select_related('video'))
    context["user_can_moderate"] = user_can_moderate(video, request.user)
    if context["user_can_moderate"]:
        # FIXME: use  amore efficient count
        for l in translations:
            l.pending_moderation_count = get_pending_count(l)
        
    translations.sort(key=lambda f: f.get_language_display())
    context['translations'] = translations    
    context['last_version'] = language.latest_version(public_only=False)
    context['widget_params'] = _widget_params(request, video, version_no=None, language=language)
    context['language'] = language
    context['edit_url'] = language.get_widget_url()
    
    _add_share_panel_context_for_history(context, video, lang)
    return object_list(request, queryset=qs, allow_empty=True,
                       paginate_by=settings.REVISIONS_ONPAGE, 
                       page=request.GET.get('page', 1),
                       template_name='videos/history.html',
                       template_object_name='revision',
                       extra_context=context)
Ejemplo n.º 4
0
def history(request, video_id, lang=None, lang_id=None):
    video = get_object_or_404(Video, video_id=video_id)
    video.update_view_counter()

    context = widget.add_onsite_js_files({})

    if lang_id:
        try:
            language = video.subtitlelanguage_set.get(pk=lang_id)
        except SubtitleLanguage.DoesNotExist:
            raise Http404
    else:
        language = video.subtitle_language(lang)

    if not language:
        if lang in dict(settings.ALL_LANGUAGES):
            config = {}
            config["videoID"] = video.video_id
            config["languageCode"] = lang
            url = reverse('onsite_widget') + '?config=' + urlquote_plus(
                json.dumps(config))
            return redirect(url)
        elif video.subtitlelanguage_set.count() > 0:
            language = video.subtitlelanguage_set.all()[0]
        else:
            raise Http404

    qs = language.subtitleversion_set.select_related('user')
    ordering, order_type = request.GET.get('o'), request.GET.get('ot')
    order_fields = {
        'date': 'datetime_started',
        'user': '******',
        'note': 'note',
        'time': 'time_change',
        'text': 'text_change'
    }
    if ordering in order_fields and order_type in ['asc', 'desc']:
        qs = qs.order_by(('-' if order_type == 'desc' else '') +
                         order_fields[ordering])
        context['ordering'], context['order_type'] = ordering, order_type

    context['video'] = video
    original = video.subtitle_language()
    if original:
        original.pending_moderation_count = get_pending_count(
            video.subtitle_language())
    translations = list(video.subtitlelanguage_set.filter(is_original=False) \
        .filter(had_version=True).select_related('video'))

    context["user_can_moderate"] = False
    if feature_is_on("MODERATION"):
        context["user_can_moderate"] = user_can_moderate(video, request.user)
        if context["user_can_moderate"]:
            # FIXME: use  amore efficient count
            for l in translations:
                l.pending_moderation_count = get_pending_count(l)

    translations.sort(key=lambda f: f.get_language_display())
    context['translations'] = translations
    context['last_version'] = language.latest_version(public_only=False)
    context['widget_params'] = _widget_params(request,
                                              video,
                                              version_no=None,
                                              language=language)
    context['language'] = language
    context['edit_url'] = language.get_widget_url()

    _add_share_panel_context_for_history(context, video, lang)
    return object_list(request,
                       queryset=qs,
                       allow_empty=True,
                       paginate_by=settings.REVISIONS_ONPAGE,
                       page=request.GET.get('page', 1),
                       template_name='videos/history.html',
                       template_object_name='revision',
                       extra_context=context)