示例#1
0
文件: basic.py 项目: wellart/weblate
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = get_object_or_404(Language, code=lang)
    else:
        language = None
    full_stats = obj.stats
    if language:
        try_set_language(lang)
        stats_obj = full_stats.get_single_language_stats(language)
    else:
        stats_obj = full_stats

    return render(
        request,
        'engage.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj,
            'full_stats': full_stats,
            'languages': stats_obj.languages,
            'total': obj.stats.source_strings,
            'percent': stats_obj.translated_percent,
            'language': language,
            'project_link': mark_safe('<a href="{}">{}</a>'.format(
                escape(obj.get_absolute_url()), escape(obj.name)
            )),
            'title': _('Get involved in {0}!').format(obj),
        }
    )
示例#2
0
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = Language.objects.try_get(code=lang)
    else:
        language = None
    if language:
        try_set_language(lang)
        stats_obj = obj.stats.get_single_language_stats(language)
    else:
        stats_obj = obj.stats

    return render(
        request,
        'engage.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj,
            'languages': stats_obj.languages,
            'total': obj.stats.source_strings,
            'percent': stats_obj.translated_percent,
            'language': language,
            'title': _('Get involved in {0}!').format(obj),
        }
    )
示例#3
0
文件: basic.py 项目: nijel/weblate
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = get_object_or_404(Language, code=lang)
    else:
        language = None
    full_stats = obj.stats
    if language:
        try_set_language(lang)
        stats_obj = full_stats.get_single_language_stats(language)
    else:
        stats_obj = full_stats

    return render(
        request,
        'engage.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj,
            'full_stats': full_stats,
            'languages': stats_obj.languages,
            'total': obj.stats.source_strings,
            'percent': stats_obj.translated_percent,
            'language': language,
            'project_link': mark_safe('<a href="{}">{}</a>'.format(
                escape(obj.get_absolute_url()), escape(obj.name)
            )),
            'title': _('Get involved in {0}!').format(obj),
        }
    )
示例#4
0
文件: basic.py 项目: dekoza/weblate
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = Language.objects.try_get(code=lang)
    else:
        language = None
    if language:
        try_set_language(lang)
        stats_obj = obj.stats.get_single_language_stats(language)
    else:
        stats_obj = obj.stats

    return render(
        request,
        'engage.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj,
            'languages': stats_obj.languages,
            'total': obj.stats.source_strings,
            'percent': stats_obj.translated_percent,
            'language': language,
            'title': _('Get involved in {0}!').format(obj),
        }
    )
示例#5
0
文件: widgets.py 项目: nijel/weblate
def render_widget(
    request,
    project,
    widget="287x66",
    color=None,
    lang=None,
    component=None,
    extension="png",
):
    # We intentionally skip ACL here to allow widget sharing
    if component is None:
        obj = get_project(request, project, skip_acl=True)
    elif component == "-":
        project = get_project(request, project, skip_acl=True)
        lang = get_object_or_404(Language, code=lang)
        obj = ProjectLanguage(project, lang)
    else:
        obj = get_component(request, project, component, skip_acl=True)

    # Handle language parameter
    if lang is not None and isinstance(lang, str):
        lang = Language.objects.fuzzy_get(code=lang, strict=True)
        if lang is None:
            raise Http404()
        if "native" not in request.GET:
            try_set_language(lang.code)
    else:
        try_set_language("en")

    # Get widget class
    try:
        widget_class = WIDGETS[widget]
    except KeyError:
        raise Http404()

    # Construct object
    widget_obj = widget_class(obj, color, lang)

    # Redirect widget
    if hasattr(widget_obj, "redirect"):
        return redirect(widget_obj.redirect(), permanent=True)

    # Invalid extension
    if extension != widget_obj.extension or color != widget_obj.color:
        kwargs = {
            "project": project,
            "widget": widget,
            "color": widget_obj.color,
            "extension": widget_obj.extension,
        }
        if lang:
            kwargs["lang"] = lang.code
            return redirect("widget-image", permanent=True, **kwargs)
        return redirect("widget-image", permanent=True, **kwargs)

    # Render widget
    response = HttpResponse(content_type=widget_obj.content_type)
    widget_obj.render(response)
    return response
示例#6
0
def render_widget(
    request,
    project,
    widget='287x66',
    color=None,
    lang=None,
    component=None,
    extension='png',
):
    # We intentionally skip ACL here to allow widget sharing
    if component is None:
        obj = get_project(request, project, skip_acl=True)
    else:
        obj = get_component(request, project, component, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        lang = Language.objects.fuzzy_get(code=lang, strict=True)
        if lang is None:
            raise Http404()
        if 'native' not in request.GET:
            try_set_language(lang.code)
    else:
        try_set_language('en')

    # Get widget class
    try:
        widget_class = WIDGETS[widget]
    except KeyError:
        raise Http404()

    # Construct object
    widget_obj = widget_class(obj, color, lang)

    # Redirect widget
    if hasattr(widget_obj, 'redirect'):
        return redirect(widget_obj.redirect(), permanent=True)

    # Invalid extension
    if extension != widget_obj.extension or color != widget_obj.color:
        kwargs = {
            'project': project,
            'widget': widget,
            'color': widget_obj.color,
            'extension': widget_obj.extension,
        }
        if lang:
            kwargs['lang'] = lang.code
            return redirect('widget-image', permanent=True, **kwargs)
        return redirect('widget-image', permanent=True, **kwargs)

    # Render widget
    response = HttpResponse(content_type=widget_obj.content_type)
    widget_obj.render(response)
    return response
示例#7
0
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = Language.objects.try_get(code=lang)
    else:
        language = None
    if language:
        try_set_language(lang)
        stats_obj = obj.stats.get_single_language_stats(language)
    else:
        stats_obj = obj.stats

    context = {
        'allow_index': True,
        'object': obj,
        'project': obj,
        'languages': stats_obj.languages,
        'total': obj.stats.source_strings,
        'percent': stats_obj.translated_percent,
        'url': obj.get_absolute_url(),
        'lang_url': obj.get_absolute_url() + '#languages',
        'language': language,
        'title': _('Get involved in {0}!').format(obj),
    }

    # Render text
    if language is None:
        status_text = _(
            '<a href="%(url)s">Translation project for %(project)s</a> '
            'currently contains %(total)s strings for translation and is '
            '<a href="%(lang_url)s">being translated into %(languages)s '
            'languages</a>. Overall, these translations are %(percent)s%% '
            'complete.'
        )
    else:
        # Translators: line of text in engagement page, please use your
        # language name instead of English
        status_text = _('<a href="%(url)s">Translation project for '
                        '%(project)s</a> into English currently contains '
                        '%(total)s strings for translation and is '
                        '%(percent)s%% complete.')
        if 'English' in status_text:
            status_text = status_text.replace('English', language.name)

    context['status_text'] = mark_safe(status_text % context)

    return render(
        request,
        'engage.html',
        context
    )
示例#8
0
文件: widgets.py 项目: dekoza/weblate
def render_widget(request, project, widget='287x66', color=None, lang=None,
                  component=None, extension='png'):
    # We intentionally skip ACL here to allow widget sharing
    if component is None:
        obj = get_project(request, project, skip_acl=True)
    else:
        obj = get_component(request, project, component, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        if 'native' not in request.GET:
            try_set_language(lang)
        lang = Language.objects.try_get(code=lang)
    else:
        try_set_language('en')

    # Get widget class
    try:
        widget_class = WIDGETS[widget]
    except KeyError:
        raise Http404()

    # Construct object
    widget_obj = widget_class(obj, color, lang)

    # Redirect widget
    if hasattr(widget_obj, 'redirect'):
        return redirect(widget_obj.redirect(), permanent=True)

    # Invalid extension
    if extension != widget_obj.extension or color != widget_obj.color:
        kwargs = {
            'project': project,
            'widget': widget,
            'color': widget_obj.color,
            'extension': widget_obj.extension,
        }
        if lang:
            kwargs['lang'] = lang.code
            return redirect('widget-image', permanent=True, **kwargs)
        return redirect('widget-image', permanent=True, **kwargs)

    # Render widget
    widget_obj.render()

    return HttpResponse(
        content_type=widget_obj.content_type,
        content=widget_obj.get_content()
    )
示例#9
0
def show_engage(request, project, lang=None):
    # Get project object, skipping ACL
    obj = get_project(request, project, skip_acl=True)

    # Handle language parameter
    if lang is not None:
        language = get_object_or_404(Language, code=lang)
    else:
        language = None
    full_stats = obj.stats
    if language:
        try_set_language(lang)
        stats_obj = full_stats.get_single_language_stats(language)
    else:
        stats_obj = full_stats

    return render(
        request,
        "engage.html",
        {
            "allow_index":
            True,
            "object":
            obj,
            "project":
            obj,
            "full_stats":
            full_stats,
            "languages":
            stats_obj.languages,
            "total":
            obj.stats.source_strings,
            "percent":
            stats_obj.translated_percent,
            "language":
            language,
            "project_link":
            mark_safe('<a href="{}">{}</a>'.format(
                escape(obj.get_absolute_url()), escape(obj.name))),
            "title":
            _("Get involved in {0}!").format(obj),
        },
    )