Exemple #1
0
def detail_members(request, slug):
    #just other tab of detail view
    q = request.REQUEST.get('q')
    
    team = Team.get(slug, request.user)
    
    qs = team.members.all()
    if q:
        qs = qs.filter(Q(user__first_name__icontains=q)|Q(user__last_name__icontains=q) \
                       |Q(user__username__icontains=q)|Q(user__biography__icontains=q))

    extra_context = widget.add_onsite_js_files({})  

    extra_context.update({
        'team': team,
        'query': q
    })
    
    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })    
    return object_list(request, queryset=qs, 
                       paginate_by=MEMBERS_ON_PAGE, 
                       template_name='teams/detail_members.html', 
                       extra_context=extra_context, 
                       template_object_name='team_member')
Exemple #2
0
def _widget_params(request,
                   video,
                   version_no=None,
                   language=None,
                   video_url=None,
                   size=None):
    primary_url = video_url or video.get_video_url()
    alternate_urls = [
        vu.effective_url for vu in video.videourl_set.all()
        if vu.effective_url != primary_url
    ]
    params = {
        'video_url': primary_url,
        'alternate_video_urls': alternate_urls,
        'base_state': {}
    }

    if version_no:
        params['base_state']['revision'] = version_no

    if language:
        params['base_state']['language_code'] = language.language_code
        params['base_state']['language_pk'] = language.pk
    if size:
        params['video_config'] = {"width": size[0], "height": size[1]}

    return base_widget_params(request, params)
Exemple #3
0
def detail_members(request, slug):
    #just other tab of detail view
    q = request.REQUEST.get('q')

    team = Team.get(slug, request.user)

    qs = team.members.all()
    if q:
        qs = qs.filter(Q(user__first_name__icontains=q)|Q(user__last_name__icontains=q) \
                       |Q(user__username__icontains=q)|Q(user__biography__icontains=q))

    extra_context = widget.add_onsite_js_files({})

    extra_context.update({'team': team, 'query': q})

    if team.video:
        extra_context['widget_params'] = base_widget_params(
            request, {
                'video_url': team.video.get_video_url(),
                'base_state': {}
            })
    return object_list(request,
                       queryset=qs,
                       paginate_by=MEMBERS_ON_PAGE,
                       template_name='teams/detail_members.html',
                       extra_context=extra_context,
                       template_object_name='team_member')
Exemple #4
0
def detail(request, slug):
    team = Team.get(slug, request.user)
    
    languages = get_user_languages_from_request(request)
    languages.append('')
    video_ids = team.teamvideo_set.values_list('video_id', flat=True)
    
    qs = SubtitleLanguage.objects.filter(video__in=video_ids).filter(language__in=languages) \
        .exclude(Q(writelock_time__gte=datetime.datetime.now()-datetime.timedelta(seconds=WRITELOCK_EXPIRATION))) \
        .extra(where=['NOT ((SELECT COUNT(vs.id) FROM videos_subtitleversion AS vs INNER JOIN videos_subtitlelanguage AS vsl ON (vsl.id = vs.language_id) WHERE vsl.is_original = %s AND vsl.video_id = videos_subtitlelanguage.video_id) <= 0 AND videos_subtitlelanguage.is_original=%s)'], params=(True, False,)) \
        .distinct()

    qs1 = qs.filter(is_forked=False, is_original=False).filter(percent_done__lt=100, percent_done__gt=0)
    qs2 = qs.filter(is_forked=False, is_original=False).filter(percent_done=0)
    qs3 = qs.filter(is_original=True).filter(subtitleversion__isnull=True)
    qs4 = qs.filter(is_forked=False, is_original=False).filter(percent_done=100)
    qs5 = qs.filter(Q(is_forked=True)|Q(is_original=True)).filter(subtitleversion__isnull=False)
       
    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team
    })

    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })
    return object_list(request, queryset=MultyQuerySet(qs1, qs2, qs3, qs4, qs5), 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/detail.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video_lang')
Exemple #5
0
def team_video(request, team_video_pk):
    team_video = get_object_or_404(TeamVideo, pk=team_video_pk)

    if not team_video.can_edit(request.user):
        raise Http404

    form = EditTeamVideoForm(request.POST or None,
                             request.FILES or None,
                             instance=team_video)

    if form.is_valid():
        form.save()
        messages.success(request, _('Video has been updated.'))
        return redirect(team_video)

    context = widget.add_onsite_js_files({})

    context.update({
        'team':
        team_video.team,
        'team_video':
        team_video,
        'form':
        form,
        'widget_params':
        base_widget_params(request, {
            'video_url': team_video.video.get_video_url(),
            'base_state': {}
        })
    })
    return context
Exemple #6
0
def team_video_detail(context, team_video):
    context['team_video'] = team_video
    video_url = team_video.video.get_video_url()
    context['team_video_widget_params'] = base_widget_params(context['request'], {
        'video_url': video_url, 
        'base_state': {},
        'effectiveVideoURL': video_url
    })
    return context
Exemple #7
0
def team_video_detail(context, team_video_search_record):
    context['search_record'] = team_video_search_record
    video_url = team_video_search_record.video_url
    context['team_video_widget_params'] = base_widget_params(context['request'], {
        'video_url': video_url, 
        'base_state': {},
        'effectiveVideoURL': video_url
    })
    return context
Exemple #8
0
def _widget_params(request, video_url, version_no=None, language_code=None):
    params = {'video_url': video_url, 'base_state': {}}
    
    if version_no:
        params['base_state']['revision'] = version_no
        
    if language_code:
        params['base_state']['language'] = language_code

    return base_widget_params(request, params)
Exemple #9
0
def team_video_detail(context, team_video):
    context['team_video'] = team_video
    video_url = team_video.video.get_video_url()
    context['team_video_widget_params'] = base_widget_params(
        context['request'], {
            'video_url': video_url,
            'base_state': {},
            'effectiveVideoURL': video_url
        })
    return context
def team_video_detail(context, team_video_search_record):
    context['search_record'] = team_video_search_record
    video_url = team_video_search_record.video_url
    context['team_video_widget_params'] = base_widget_params(
        context['request'], {
            'video_url': video_url,
            'base_state': {},
            'effectiveVideoURL': video_url
        })
    return context
Exemple #11
0
def team_video_summary(context, video):
    context['video'] = video
    context['team_video'] = video.get_team_video()
    context['video_url'] = video_url = video.get_video_url()
    context['team_video_widget_params'] = base_widget_params(context['request'], {
        'video_url': video_url,
        'base_state': {},
        'effectiveVideoURL': video_url
    })
    return context
Exemple #12
0
def _widget_params(request, video, version_no=None, language_code=None):
    primary_url = video.get_video_url()
    alternate_urls = [vu.effective_url for vu in video.videourl_set.all() if vu.effective_url != primary_url]
    params = {"video_url": primary_url, "alternate_video_urls": alternate_urls, "base_state": {}}

    if version_no:
        params["base_state"]["revision"] = version_no

    if language_code:
        params["base_state"]["language"] = language_code

    return base_widget_params(request, params)
Exemple #13
0
def detail(request, slug):
    team = Team.get(slug, request.user)
    
    languages = get_user_languages_from_request(request)
    languages.extend([l[:l.find('-')] for l in languages if l.find('-') > -1])
    
    langs_pairs = []
    
    for l1 in languages:
        for l0 in languages:
            if not l1 == l0:
                langs_pairs.append('%s_%s' % (l1, l0))
    
    qs = TeamVideoLanguagePair.objects.filter(language_pair__in=langs_pairs, team=team) \
        .select_related('team_video', 'team_video__video')
    lqs = TeamVideoLanguage.objects.filter(team=team).select_related('team_video', 'team_video__video')
    
    qs1 = qs.filter(percent_complete__gt=0,percent_complete__lt=100)
    qs2 = qs.filter(percent_complete=0)
    qs3 = lqs.filter(is_original=True, is_complete=False)
    qs4 = lqs.filter(is_original=False, forked=True, is_complete=True)
    
    mqs = TeamMultyQuerySet(qs1, qs2, qs3, qs4)

    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team,
        'can_edit_video': team.can_edit_video(request.user)
    })

    if len(mqs) == 0:
        mqs = TeamMultyQuerySet(TeamVideoLanguagePair.objects.filter(team=team) \
                                .select_related('team_video', 'team_video__video'))

    general_settings = {}
    add_general_settings(request, general_settings)
    extra_context['general_settings'] = json.dumps(general_settings)

    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })
        
    return object_list(request, queryset=mqs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/detail.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video_md')
Exemple #14
0
def _widget_params(request, video, version_no=None, language_code=None):
    primary_url = video.get_video_url()
    alternate_urls = [vu.effective_url for vu in video.videourl_set.all() 
                      if vu.effective_url != primary_url]
    params = {'video_url': primary_url, 
              'alternate_video_urls': alternate_urls, 
              'base_state': {}}

    if version_no:
        params['base_state']['revision'] = version_no
        
    if language_code:
        params['base_state']['language'] = language_code

    return base_widget_params(request, params)
Exemple #15
0
def detail_old(request, slug, is_debugging=False, languages=None):
    team = Team.get(slug, request.user)

    if languages is None:
        languages = get_user_languages_from_request(request)
    if bool(is_debugging):
        languages = request.GET.get("langs", "").split(",")

    data = team.get_videos_for_languages(
        languages, CUTTOFF_DUPLICATES_NUM_VIDEOS_ON_TEAMS)
    mqs = data['videos']

    extra_context = widget.add_onsite_js_files({})
    extra_context.update({
        'team': team,
        'can_edit_video': team.can_edit_video(request.user)
    })

    general_settings = {}
    add_general_settings(request, general_settings)
    extra_context['general_settings'] = json.dumps(general_settings)

    if team.video:
        extra_context['widget_params'] = base_widget_params(
            request, {
                'video_url': team.video.get_video_url(),
                'base_state': {}
            })

    if bool(is_debugging) and request.user.is_staff:
        extra_context.update(data)
        extra_context.update({
            'languages': languages,
        })
        return render_to_response("teams/detail-debug.html", extra_context,
                                  RequestContext(request))

    return object_list(request,
                       queryset=mqs,
                       paginate_by=VIDEOS_ON_PAGE,
                       template_name='teams/detail.html',
                       extra_context=extra_context,
                       template_object_name='team_video_md')
Exemple #16
0
def detail(request, slug, is_debugging=False, languages=None):
    team = Team.get(slug, request.user)

    if languages is None:
        languages = get_user_languages_from_request(request)
    if bool(is_debugging):
        languages = request.GET.get("langs", "").split(",")

    data = team.get_videos_for_languages(languages, CUTTOFF_DUPLICATES_NUM_VIDEOS_ON_TEAMS)
    mqs = data['videos']
    
    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team,
        'can_edit_video': team.can_edit_video(request.user)
    })

    


    general_settings = {}
    add_general_settings(request, general_settings)
    extra_context['general_settings'] = json.dumps(general_settings)


    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })

    if bool(is_debugging) and request.user.is_staff:
        extra_context.update(data)
        extra_context.update({
            'languages': languages,
            })
        return render_to_response("teams/detail-debug.html", extra_context, RequestContext(request))
    
    return object_list(request, queryset=mqs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/detail.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video_md')
Exemple #17
0
def _widget_params(request, video, version_no=None, language_code=None):
    primary_url = video.get_video_url()
    alternate_urls = [
        vu.effective_url for vu in video.videourl_set.all()
        if vu.effective_url != primary_url
    ]
    params = {
        'video_url': primary_url,
        'alternate_video_urls': alternate_urls,
        'base_state': {}
    }

    if version_no:
        params['base_state']['revision'] = version_no

    if language_code:
        params['base_state']['language'] = language_code

    return base_widget_params(request, params)
Exemple #18
0
def completed_videos(request, slug):
    team = Team.get(slug, request.user)
    
    qs = SearchQuerySet().models(TeamVideo).filter(team_id=team.id) \
        .filter(is_complete=True).order_by('-video_complete_date')

    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team
    })
    
    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })

    return object_list(request, queryset=qs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/completed_videos.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video')    
Exemple #19
0
def completed_videos(request, slug):
    team = Team.get(slug, request.user)
    
    qs = SearchQuerySet().models(TeamVideo).filter(team_id=team.id) \
        .filter(is_complete=True).order_by('-video_complete_date')

    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team
    })
    
    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })

    return object_list(request, queryset=qs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/completed_videos.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video')    
Exemple #20
0
def team_video(request, team_video_pk):
    team_video = get_object_or_404(TeamVideo, pk=team_video_pk)
    
    if not team_video.can_edit(request.user):
        raise Http404
    
    form = EditTeamVideoForm(request.POST or None, request.FILES or None, instance=team_video)

    if form.is_valid():
        form.save()
        messages.success(request, _('Video has been updated.'))
        return redirect(team_video)

    context = widget.add_onsite_js_files({})
    
    context.update({
        'team': team_video.team,
        'team_video': team_video,
        'form': form,
        'widget_params': base_widget_params(request, {'video_url': team_video.video.get_video_url(), 'base_state': {}})
    })
    return context
Exemple #21
0
def completed_videos(request, slug):
    team = Team.get(slug, request.user)

    qs = team.teamvideo_set.exclude(video__complete_date__isnull=True) \
        .select_related('video').order_by('-video__complete_date')

    extra_context = widget.add_onsite_js_files({})
    extra_context.update({'team': team})

    if team.video:
        extra_context['widget_params'] = base_widget_params(
            request, {
                'video_url': team.video.get_video_url(),
                'base_state': {}
            })

    qs = qs._clone(CompletedVideosQS)

    return object_list(request,
                       queryset=qs,
                       paginate_by=VIDEOS_ON_PAGE,
                       template_name='teams/completed_videos.html',
                       extra_context=extra_context,
                       template_object_name='team_video')
Exemple #22
0
def completed_videos(request, slug):
    team = Team.get(slug, request.user)
    
    qs = team.teamvideo_set.exclude(video__complete_date__isnull=True) \
        .select_related('video').order_by('-video__complete_date')
        
    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team
    })
    
    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })

    qs = qs._clone(CompletedVideosQS)

    return object_list(request, queryset=qs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/completed_videos.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video')    
Exemple #23
0
def detail(request, slug, is_debugging=False):
    team = Team.get(slug, request.user)
    
    languages = get_user_languages_from_request(request)
    if bool(is_debugging):
        languages = request.GET.get("langs", "").split(",")
    languages.extend([l[:l.find('-')] for l in languages if l.find('-') > -1])
    
    langs_pairs = []
    
    for l1 in languages:
        for l0 in languages:
            if not l1 == l0:
                langs_pairs.append('%s_%s' % (l1, l0))
    
    qs = TeamVideoLanguagePair.objects.filter(language_pair__in=langs_pairs, team=team) \
        .select_related('team_video', 'team_video__video')
    lqs = TeamVideoLanguage.objects.filter(team=team).select_related('team_video', 'team_video__video')
    
    qs1 = qs.filter(percent_complete__gt=0,percent_complete__lt=100)
    qs2 = qs.filter(percent_complete=0)
    qs3 = lqs.filter(is_original=True, is_complete=False, language__in=languages)
    qs4 = lqs.filter(is_original=False, forked=True, is_complete=False, language__in=languages)
    mqs = TeamMultyQuerySet(qs1, qs2, qs3, qs4)

    extra_context = widget.add_onsite_js_files({})    
    extra_context.update({
        'team': team,
        'can_edit_video': team.can_edit_video(request.user)
    })
    total_count = TeamVideo.objects.filter(team=team).count()

    additional = TeamVideoLanguagePair.objects.none()
    all_videos = TeamVideo.objects.filter(team=team).select_related('video')

    if total_count == 0:
        mqs = all_videos
    else:
        if  total_count < CUTTOFF_DUPLICATES_NUM_VIDEOS_ON_TEAMS:
            additional = all_videos.exclude(pk__in=[x.id for x in mqs ])
        else:
            additional = all_videos
        mqs = TeamMultyQuerySet(qs1, qs2, qs3, qs4 , additional)    


    general_settings = {}
    add_general_settings(request, general_settings)
    extra_context['general_settings'] = json.dumps(general_settings)


    if team.video:
        extra_context['widget_params'] = base_widget_params(request, {
            'video_url': team.video.get_video_url(), 
            'base_state': {}
        })

    if bool(is_debugging) and request.user.is_staff:
        extra_context.update({
            'languages': languages,
            'qs': qs,
            'lqs': lqs,
            'qs1': qs1,
            'qs2': qs2,
            'qs3': qs3,
            'qs4': qs4,
            'mqs':mqs,
            'mqs_count': len(mqs),
            'additional_count': additional.count(),
            'additional': additional[:50]
            })
        return render_to_response("teams/detail-debug.html", extra_context, RequestContext(request))
    
    return object_list(request, queryset=mqs, 
                       paginate_by=VIDEOS_ON_PAGE, 
                       template_name='teams/detail.html', 
                       extra_context=extra_context, 
                       template_object_name='team_video_md')
Exemple #24
0
def detail(request, slug, is_debugging=False):
    team = Team.get(slug, request.user)

    languages = get_user_languages_from_request(request)
    if bool(is_debugging):
        languages = request.GET.get("langs", "").split(",")
    languages.extend([l[:l.find('-')] for l in languages if l.find('-') > -1])

    langs_pairs = []

    for l1 in languages:
        for l0 in languages:
            if not l1 == l0:
                langs_pairs.append('%s_%s' % (l1, l0))

    qs = TeamVideoLanguagePair.objects.filter(language_pair__in=langs_pairs, team=team) \
        .select_related('team_video', 'team_video__video')
    lqs = TeamVideoLanguage.objects.filter(team=team).select_related(
        'team_video', 'team_video__video')

    qs1 = qs.filter(percent_complete__gt=0, percent_complete__lt=100)
    qs2 = qs.filter(percent_complete=0)
    qs3 = lqs.filter(is_original=True,
                     is_complete=False,
                     language__in=languages)
    qs4 = lqs.filter(is_original=False,
                     forked=True,
                     is_complete=False,
                     language__in=languages)
    mqs = TeamMultyQuerySet(qs1, qs2, qs3, qs4)

    extra_context = widget.add_onsite_js_files({})
    extra_context.update({
        'team': team,
        'can_edit_video': team.can_edit_video(request.user)
    })
    total_count = TeamVideo.objects.filter(team=team).count()

    additional = TeamVideoLanguagePair.objects.none()
    all_videos = TeamVideo.objects.filter(team=team).select_related('video')

    if total_count == 0:
        mqs = all_videos
    else:
        if total_count < CUTTOFF_DUPLICATES_NUM_VIDEOS_ON_TEAMS:
            additional = all_videos.exclude(pk__in=[x.id for x in mqs])
        else:
            additional = all_videos
        mqs = TeamMultyQuerySet(qs1, qs2, qs3, qs4, additional)

    general_settings = {}
    add_general_settings(request, general_settings)
    extra_context['general_settings'] = json.dumps(general_settings)

    if team.video:
        extra_context['widget_params'] = base_widget_params(
            request, {
                'video_url': team.video.get_video_url(),
                'base_state': {}
            })

    if bool(is_debugging) and request.user.is_staff:
        extra_context.update({
            'languages': languages,
            'qs': qs,
            'lqs': lqs,
            'qs1': qs1,
            'qs2': qs2,
            'qs3': qs3,
            'qs4': qs4,
            'mqs': mqs,
            'mqs_count': len(mqs),
            'additional_count': additional.count(),
            'additional': additional[:50]
        })
        return render_to_response("teams/detail-debug.html", extra_context,
                                  RequestContext(request))

    return object_list(request,
                       queryset=mqs,
                       paginate_by=VIDEOS_ON_PAGE,
                       template_name='teams/detail.html',
                       extra_context=extra_context,
                       template_object_name='team_video_md')