Esempio n. 1
0
def update_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if obj.do_update(request):
        messages.info(request, _('All repositories were updated.'))

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 2
0
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    form = NewLanguageForm(request.POST)

    if form.is_valid():
        language = Language.objects.get(code=form.cleaned_data['lang'])
        same_lang = obj.translation_set.filter(language=language)
        if same_lang.exists():
            messages.error(
                request,
                _('Chosen translation already exists in this project!')
            )
        elif obj.project.new_lang == 'contact':
            notify_new_language(obj, language, request.user)
            messages.info(
                request,
                _(
                    "A request for a new translation has been "
                    "sent to the project's maintainers."
                )
            )
        elif obj.project.new_lang == 'add':
            obj.add_new_language(language, request)
    else:
        messages.error(
            request,
            _('Failed to process new translation request!')
        )

    return HttpResponseRedirect(reverse(
        'subproject',
        kwargs={'subproject': obj.slug, 'project': obj.project.slug}
    ))
Esempio n. 3
0
def update_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if obj.do_update(request):
        messages.info(request, _('All repositories were updated.'))

    return redirect(obj)
Esempio n. 4
0
def export_stats(request, project, subproject):
    """
    Exports stats in JSON format.
    """
    subprj = get_subproject(request, project, subproject)
    response = []
    site = Site.objects.get_current()
    for trans in subprj.translation_set.all():
        response.append(
            {
                "code": trans.language.code,
                "name": trans.language.name,
                "total": trans.total,
                "last_change": trans.get_last_change(),
                "last_author": trans.get_last_author(False),
                "translated": trans.translated,
                "translated_percent": trans.get_translated_percent(),
                "fuzzy": trans.fuzzy,
                "fuzzy_percent": trans.get_fuzzy_percent(),
                "failing": trans.get_failing_checks(),
                "failing_percent": trans.get_failing_checks_percent(),
                "url": trans.get_share_url(),
                "url_translate": "http://%s%s" % (site.domain, trans.get_absolute_url()),
            }
        )
    return HttpResponse(json.dumps(response, default=dt_handler), mimetype="application/json")
Esempio n. 5
0
def export_stats(request, project, subproject):
    '''
    Exports stats in JSON format.
    '''
    subprj = get_subproject(request, project, subproject)
    response = []
    for trans in subprj.translation_set.all():
        response.append({
            'code': trans.language.code,
            'name': trans.language.name,
            'total': trans.total,
            'last_change': trans.get_last_change(),
            'last_author': trans.get_last_author(False),
            'translated': trans.translated,
            'translated_percent': trans.get_translated_percent(),
            'fuzzy': trans.fuzzy,
            'fuzzy_percent': trans.get_fuzzy_percent(),
            'failing': trans.get_failing_checks(),
            'failing_percent': trans.get_failing_checks_percent(),
            'url': trans.get_share_url(),
            'url_translate': get_site_url(trans.get_absolute_url()),
        })
    return HttpResponse(
        json.dumps(response, default=dt_handler),
        mimetype='application/json'
    )
Esempio n. 6
0
def push_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if obj.do_push(request):
        messages.info(request, _('All repositories were pushed.'))

    return redirect(obj)
Esempio n. 7
0
def reset_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if obj.do_reset(request):
        messages.info(request, _('All repositories have been reset.'))

    return redirect(obj)
Esempio n. 8
0
def git_status_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    return render_to_response('js/git-status.html',
                              RequestContext(request, {
                                  'object': obj,
                              }))
Esempio n. 9
0
def commit_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)
    obj.commit_pending(request)

    messages.info(request, _('All pending translations were committed.'))

    return redirect(obj)
Esempio n. 10
0
def show_check_subproject(request, name, project, subproject):
    '''
    Show checks failing in a subproject.
    '''
    subprj = get_subproject(request, project, subproject)
    try:
        check = CHECKS[name]
    except KeyError:
        raise Http404('No check matches the given query.')
    units = Unit.objects.none()
    if check.target:
        langs = Check.objects.filter(
            check=name,
            project=subprj.project,
            ignore=False
        ).values_list(
            'language', flat=True
        ).distinct()
        for lang in langs:
            checks = Check.objects.filter(
                check=name,
                project=subprj.project,
                language=lang,
                ignore=False
            ).values_list('checksum', flat=True)
            res = Unit.objects.filter(
                translation__subproject=subprj,
                checksum__in=checks,
                translation__language=lang,
                translated=True
            ).values(
                'translation__language__code'
            ).annotate(count=Count('id'))
            units |= res
    source_checks = []
    if check.source:
        checks = Check.objects.filter(
            check=name, project=subprj.project,
            language=None,
            ignore=False
        ).values_list('checksum', flat=True)
        lang = subprj.translation_set.all()[0].language
        res = Unit.objects.filter(
            translation__subproject=subprj,
            checksum__in=checks,
            translation__language=lang
        ).count()
        if res > 0:
            source_checks.append(res)
    return render_to_response(
        'check_subproject.html',
        RequestContext(request, {
            'checks': units,
            'source_checks': source_checks,
            'anychecks': len(units) + len(source_checks) > 0,
            'title': '%s/%s' % (subprj.__unicode__(), check.name),
            'check': check,
            'subproject': subprj,
        })
    )
Esempio n. 11
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.filter(
        translation__subproject=obj).order_by('-timestamp')[:10]

    return render_to_response(
        'subproject.html',
        RequestContext(
            request, {
                'object':
                obj,
                'last_changes':
                last_changes,
                'last_changes_rss':
                reverse('rss-subproject',
                        kwargs={
                            'subproject': obj.slug,
                            'project': obj.project.slug
                        }),
                'last_changes_url':
                urlencode({
                    'subproject': obj.slug,
                    'project': obj.project.slug
                }),
            }))
Esempio n. 12
0
def reset_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if obj.do_reset(request):
        messages.info(request, _('All repositories have been reset.'))

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 13
0
def commit_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)
    obj.commit_pending(request)

    messages.info(request, _('All pending translations were committed.'))

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 14
0
def export_stats(request, project, subproject):
    """
    Exports stats in JSON format.
    """
    subprj = get_subproject(request, project, subproject)

    try:
        indent = int(request.GET["indent"])
    except:
        indent = None

    response = []
    for trans in subprj.translation_set.all():
        response.append(
            {
                "code": trans.language.code,
                "name": trans.language.name,
                "total": trans.total,
                "last_change": trans.get_last_change(),
                "last_author": trans.get_last_author(False),
                "translated": trans.translated,
                "translated_percent": trans.get_translated_percent(),
                "fuzzy": trans.fuzzy,
                "fuzzy_percent": trans.get_fuzzy_percent(),
                "failing": trans.get_failing_checks(),
                "failing_percent": trans.get_failing_checks_percent(),
                "url": trans.get_share_url(),
                "url_translate": get_site_url(trans.get_absolute_url()),
            }
        )
    return HttpResponse(json.dumps(response, default=json_dt_handler, indent=indent), mimetype="application/json")
Esempio n. 15
0
def update_subproject(request, project, subproject):
    '''
    API hook for updating git repos.
    '''
    if not appsettings.ENABLE_HOOKS:
        return HttpResponseNotAllowed([])
    obj = get_subproject(request, project, subproject, True)
    perform_update(obj)
    return HttpResponse('update triggered')
Esempio n. 16
0
def unlock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.locked = False
    obj.save()

    messages.info(request, _("Subproject is now open for translation updates."))

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 17
0
def lock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.commit_pending(request)

    obj.locked = True
    obj.save()

    messages.info(request, _("Subproject is now locked for translation updates!"))

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 18
0
def unlock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.locked = False
    obj.save()

    messages.info(
        request,
        _('Subproject is now open for translation updates.')
    )

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 19
0
def unlock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.locked = False
    obj.save()

    messages.info(
        request,
        _('Subproject is now open for translation updates.')
    )

    return redirect(obj)
Esempio n. 20
0
def update_subproject(request, project, subproject):
    '''
    API hook for updating git repos.
    '''
    if not appsettings.ENABLE_HOOKS:
        return HttpResponseNotAllowed([])
    obj = get_subproject(request, project, subproject, True)
    if appsettings.BACKGROUND_HOOKS:
        thread = threading.Thread(target=obj.do_update)
        thread.start()
    else:
        obj.do_update()
    return HttpResponse('update triggered')
Esempio n. 21
0
def update_subproject(request, project, subproject):
    '''
    API hook for updating git repos.
    '''
    if not appsettings.ENABLE_HOOKS:
        return HttpResponseNotAllowed([])
    obj = get_subproject(request, project, subproject, True)
    if appsettings.BACKGROUND_HOOKS:
        thread = threading.Thread(target=obj.do_update)
        thread.start()
    else:
        obj.do_update()
    return HttpResponse('update triggered')
Esempio n. 22
0
def lock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.commit_pending(request)

    obj.locked = True
    obj.save()

    messages.info(
        request,
        _('Subproject is now locked for translation updates!')
    )

    return redirect(obj)
Esempio n. 23
0
def lock_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    obj.commit_pending(request)

    obj.locked = True
    obj.save()

    messages.info(
        request,
        _('Subproject is now locked for translation updates!')
    )

    return HttpResponseRedirect(obj.get_absolute_url())
Esempio n. 24
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.filter(
        translation__subproject=obj
    ).order_by('-timestamp')[:10]

    return render_to_response('subproject.html', RequestContext(request, {
        'object': obj,
        'last_changes': last_changes,
        'last_changes_rss': reverse(
            'rss-subproject',
            kwargs={'subproject': obj.slug, 'project': obj.project.slug}
        ),
    }))
Esempio n. 25
0
def review_source(request, project, subproject):
    """
    Listing of source strings to review.
    """
    obj = get_subproject(request, project, subproject)

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    try:
        source = obj.translation_set.all()[0]
    except Translation.DoesNotExist:
        raise Http404("No translation exists in this subproject.")

    # Grab search type and page number
    rqtype = request.GET.get("type", "all")
    limit = request.GET.get("limit", 50)
    page = request.GET.get("page", 1)
    ignored = "ignored" in request.GET

    # Fiter units
    sources = source.unit_set.filter_type(rqtype, source, ignored)

    paginator = Paginator(sources, limit)

    try:
        sources = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        sources = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        sources = paginator.page(paginator.num_pages)

    return render_to_response(
        "source-review.html",
        RequestContext(
            request,
            {
                "object": obj,
                "source": source,
                "sources": sources,
                "rqtype": rqtype,
                "title": _("Review source strings in %s") % obj.__unicode__(),
            },
        ),
    )
Esempio n. 26
0
def show_source(request, project, subproject):
    '''
    Show source strings summary and checks.
    '''
    obj = get_subproject(request, project, subproject)
    if not obj.translation_set.exists():
        raise Http404('No translation exists in this subproject.')

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    source = obj.translation_set.all()[0]

    return render_to_response('source.html', RequestContext(request, {
        'object': obj,
        'source': source,
        'title': _('Source strings in %s') % obj.__unicode__(),
    }))
Esempio n. 27
0
def show_source(request, project, subproject):
    """
    Show source strings summary and checks.
    """
    obj = get_subproject(request, project, subproject)
    if not obj.translation_set.exists():
        raise Http404("No translation exists in this subproject.")

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    source = obj.translation_set.all()[0]

    return render_to_response(
        "source.html",
        RequestContext(
            request, {"object": obj, "source": source, "title": _("Source strings in %s") % obj.__unicode__()}
        ),
    )
Esempio n. 28
0
def get_detail(request, project, subproject, checksum):
    '''
    Returns source translation detail in all languages.
    '''
    subproject = get_subproject(request, project, subproject)
    units = Unit.objects.filter(
        checksum=checksum,
        translation__subproject=subproject
    )

    return render_to_response(
        'js/detail.html',
        RequestContext(
            request,
            {
                'units': units,
            }
        )
    )
Esempio n. 29
0
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    form = NewLanguageForm(request.POST)

    if form.is_valid():
        language = Language.objects.get(code=form.cleaned_data["lang"])
        same_lang = obj.translation_set.filter(language=language)
        if same_lang.exists():
            messages.error(request, _("Chosen translation already exists in this project!"))
        elif obj.project.new_lang == "contact":
            notify_new_language(obj, language, request.user)
            messages.info(request, _("A request for a new translation has been " "sent to the project's maintainers."))
        elif obj.project.new_lang == "add":
            obj.add_new_language(language, request)
    else:
        messages.error(request, _("Failed to process new translation request!"))

    return redirect("subproject", subproject=obj.slug, project=obj.project.slug)
Esempio n. 30
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.filter(translation__subproject=obj).order_by("-timestamp")[:10]

    return render_to_response(
        "subproject.html",
        RequestContext(
            request,
            {
                "object": obj,
                "last_changes": last_changes,
                "last_changes_rss": reverse(
                    "rss-subproject", kwargs={"subproject": obj.slug, "project": obj.project.slug}
                ),
                "last_changes_url": urlencode({"subproject": obj.slug, "project": obj.project.slug}),
            },
        ),
    )
Esempio n. 31
0
def show_source(request, project, subproject):
    '''
    Show source strings summary and checks.
    '''
    obj = get_subproject(request, project, subproject)
    if not obj.translation_set.exists():
        raise Http404('No translation exists in this subproject.')

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    source = obj.translation_set.all()[0]

    return render_to_response(
        'source.html',
        RequestContext(
            request, {
                'object': obj,
                'source': source,
                'title': _('Source strings in %s') % obj.__unicode__(),
            }))
Esempio n. 32
0
def review_source(request, project, subproject):
    '''
    Listing of source strings to review.
    '''
    obj = get_subproject(request, project, subproject)

    if not obj.translation_set.exists():
        raise Http404('No translation exists in this subproject.')

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    source = obj.translation_set.all()[0]

    # Grab search type and page number
    rqtype = request.GET.get('type', 'all')
    limit = request.GET.get('limit', 50)
    page = request.GET.get('page', 1)

    # Fiter units
    sources = source.unit_set.filter_type(rqtype, source)

    paginator = Paginator(sources, limit)

    try:
        sources = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        sources = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        sources = paginator.page(paginator.num_pages)

    return render_to_response(
        'source-review.html',
        RequestContext(
            request, {
                'object': obj,
                'source': source,
                'sources': sources,
                'title': _('Review source strings in %s') % obj.__unicode__(),
            }))
Esempio n. 33
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.prefetch().filter(
        translation__subproject=obj
    ).order_by('-timestamp')[:10]

    new_lang_form = NewLanguageForm()

    return render_to_response('subproject.html', RequestContext(request, {
        'object': obj,
        'last_changes': last_changes,
        'last_changes_rss': reverse(
            'rss-subproject',
            kwargs={'subproject': obj.slug, 'project': obj.project.slug}
        ),
        'last_changes_url': urlencode(
            {'subproject': obj.slug, 'project': obj.project.slug}
        ),
        'new_lang_form': new_lang_form,
    }))
Esempio n. 34
0
def review_source(request, project, subproject):
    '''
    Listing of source strings to review.
    '''
    obj = get_subproject(request, project, subproject)

    # Grab first translation in subproject
    # (this assumes all have same source strings)
    try:
        source = obj.translation_set.all()[0]
    except Translation.DoesNotExist:
        raise Http404('No translation exists in this subproject.')

    # Grab search type and page number
    rqtype = request.GET.get('type', 'all')
    limit = request.GET.get('limit', 50)
    page = request.GET.get('page', 1)
    ignored = 'ignored' in request.GET

    # Fiter units
    sources = source.unit_set.filter_type(rqtype, source, ignored)

    paginator = Paginator(sources, limit)

    try:
        sources = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        sources = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        sources = paginator.page(paginator.num_pages)

    return render_to_response('source-review.html', RequestContext(request, {
        'object': obj,
        'source': source,
        'sources': sources,
        'rqtype': rqtype,
        'title': _('Review source strings in %s') % obj.__unicode__(),
    }))
Esempio n. 35
0
def export_stats(request, project, subproject):
    '''
    Exports stats in JSON format.
    '''
    subprj = get_subproject(request, project, subproject)

    try:
        indent = int(request.GET['indent'])
    except:
        indent = None

    response = []
    for trans in subprj.translation_set.all():
        response.append({
            'code': trans.language.code,
            'name': trans.language.name,
            'total': trans.total,
            'last_change': trans.get_last_change(),
            'last_author': trans.get_last_author(False),
            'translated': trans.translated,
            'translated_percent': trans.get_translated_percent(),
            'fuzzy': trans.fuzzy,
            'fuzzy_percent': trans.get_fuzzy_percent(),
            'failing': trans.get_failing_checks(),
            'failing_percent': trans.get_failing_checks_percent(),
            'url': trans.get_share_url(),
            'url_translate': get_site_url(trans.get_absolute_url()),
        })
    return HttpResponse(
        json.dumps(
            response,
            default=json_dt_handler,
            indent=indent,
        ),
        mimetype='application/json'
    )
Esempio n. 36
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.prefetch().filter(translation__subproject=obj).order_by("-timestamp")[:10]

    new_lang_form = NewLanguageForm()

    return render_to_response(
        "subproject.html",
        RequestContext(
            request,
            {
                "object": obj,
                "translations": obj.translation_set.enabled(),
                "show_language": 1,
                "last_changes": last_changes,
                "last_changes_rss": reverse(
                    "rss-subproject", kwargs={"subproject": obj.slug, "project": obj.project.slug}
                ),
                "last_changes_url": urlencode({"subproject": obj.slug, "project": obj.project.slug}),
                "new_lang_form": new_lang_form,
            },
        ),
    )
Esempio n. 37
0
 def get_object(self, request, project, subproject):
     return get_subproject(request, project, subproject)
Esempio n. 38
0
 def get_object(self, request, project, subproject):
     return get_subproject(request, project, subproject)
Esempio n. 39
0
def git_status_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    return render_to_response('js/git-status.html', RequestContext(request, {
        'object': obj,
    }))