Exemple #1
0
def onsite_widget(request):
    """Used for subtitle dialog"""

    context = widget.add_config_based_js_files({}, settings.JS_API,
                                               'unisubs-api.js')
    config = request.GET.get('config', '{}')
    # strip any query string parama as that chokes the json string
    match = re.search(r'(?P<qs>}\?.*)', config)
    if match:
        config = config[:match.start() + 1]
    try:
        config = json.loads(config)
    except (ValueError, KeyError):
        raise Http404

    if config.get('task'):
        task = get_object_or_404(Task, pk=config.get('task'))
        if task.completed:
            messages.error(request,
                           _(u'That task has already been completed.'))
            return HttpResponseRedirect(
                reverse('teams:team_tasks', kwargs={'slug': task.team.slug}))

    if not config.get('nullWidget'):
        video_id = config.get('videoID')

        if not video_id:
            raise Http404

        video = get_object_or_404(models.Video, video_id=video_id)
        config['returnURL'] = video.get_absolute_url()

        if not 'effectiveVideoURL' in config:
            config['effectiveVideoURL'] = video.get_video_url()

        tv = video.get_team_video()
        if tv:
            team = tv.team

            config['guidelines'] = dict([
                (s.key_name.split('_', 1)[-1],
                 linebreaks(urlize(force_escape(s.data))))
                for s in team.settings.guidelines() if s.data.strip()
            ])

            # TODO: Go to the tasks panel once the history stuff is implemented
            config['team_url'] = reverse('teams:settings_basic',
                                         kwargs={'slug': team.slug})
        else:
            config['guidelines'] = {}

    context['widget_params'] = json.dumps(config)
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    response = render_to_response('widget/onsite_widget.html',
                                  context,
                                  context_instance=RequestContext(request))
    response['X-XSS-Protection'] = '0'
    return response
Exemple #2
0
def onsite_widget(request):
    """Used for subtitle dialog"""
    context = widget.add_config_based_js_files(
        {}, settings.JS_API, 'mirosubs-api.js')
    config = request.GET.get('config', '{}')

    try:
        config = json.loads(config)
    except (ValueError, KeyError):
        raise Http404

    if 'HTTP_REFERER' in request.META:
        config['returnURL'] = request.META['HTTP_REFERER']

    if not config.get('nullWidget'): 
        video_id = config.get('videoID')

        if not video_id:
            raise Http404

        video = get_object_or_404(models.Video, video_id=video_id)

        if not 'returnURL' in config:
            config['returnURL'] = video.get_absolute_url()

        if not 'effectiveVideoURL' in config:
            config['effectiveVideoURL'] = video.get_video_url()

    context['widget_params'] = json.dumps(config)
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    return render_to_response('widget/onsite_widget.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #3
0
def onsite_widget(request):
    """Used for subtitle dialog"""
    context = widget.add_config_based_js_files({}, settings.JS_API,
                                               'mirosubs-api.js')
    config = request.GET.get('config', '{}')

    try:
        config = json.loads(config)
    except (ValueError, KeyError):
        raise Http404

    if 'HTTP_REFERER' in request.META:
        config['returnURL'] = request.META['HTTP_REFERER']

    if not config.get('nullWidget'):
        video_id = config.get('videoID')

        if not video_id:
            raise Http404

        video = get_object_or_404(models.Video, video_id=video_id)

        if not 'returnURL' in config:
            config['returnURL'] = video.get_absolute_url()

        if not 'effectiveVideoURL' in config:
            config['effectiveVideoURL'] = video.get_video_url()

    context['widget_params'] = json.dumps(config)
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    return render_to_response('widget/onsite_widget.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #4
0
def bug(request):
    from widget.rpc import add_general_settings
    context = widget.add_config_based_js_files({}, settings.JS_API, 'mirosubs-api.js')
    context['all_videos'] = Video.objects.count()
    try:
        context['video_url_obj'] = VideoUrl.objects.filter(type=VIDEO_TYPE_YOUTUBE)[:1].get()
    except VideoUrl.DoesNotExist:
        raise Http404
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)    
    return render_to_response('bug.html', context,
                              context_instance=RequestContext(request))
Exemple #5
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 #6
0
def bug(request):
    from widget.rpc import add_general_settings
    context = widget.add_config_based_js_files({}, settings.JS_API,
                                               'mirosubs-api.js')
    context['all_videos'] = Video.objects.count()
    try:
        context['video_url_obj'] = VideoUrl.objects.filter(
            type=VIDEO_TYPE_YOUTUBE)[:1].get()
    except VideoUrl.DoesNotExist:
        raise Http404
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    return render_to_response('bug.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #7
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 #8
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 #9
0
def onsite_widget_resume(request):
    context = widget.add_config_based_js_files({}, settings.JS_API,
                                               'unisubs-api.js')
    config = request.GET.get('config', '{}')

    try:
        config = json.loads(config)
    except (ValueError, KeyError):
        raise Http404

    video_id = config.get('videoID')
    if not video_id:
        raise Http404

    get_object_or_404(models.Video, video_id=video_id)

    context['widget_params'] = json.dumps(config)
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    return render(request, 'widget/onsite_widget_resume.html', context)
Exemple #10
0
def onsite_widget_resume(request):
    context = widget.add_config_based_js_files(
        {}, settings.JS_API, 'unisubs-api.js')
    config = request.GET.get('config', '{}')

    try:
        config = json.loads(config)
    except (ValueError, KeyError):
        raise Http404

    video_id = config.get('videoID')
    if not video_id:
        raise Http404

    video = get_object_or_404(models.Video, video_id=video_id)

    context['widget_params'] = json.dumps(config)
    general_settings = {}
    add_general_settings(request, general_settings)
    context['general_settings'] = json.dumps(general_settings)
    return render_to_response('widget/onsite_widget_resume.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #11
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 #12
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')