Ejemplo n.º 1
0
def show_translation(request, project, component, lang):
    obj = get_translation(request, project, component, lang)
    obj.stats.ensure_all()
    last_changes = Change.objects.prefetch().order().filter(
        translation=obj)[:10]
    user = request.user

    # Get form
    form = get_upload_form(user, obj)

    search_form = SearchForm(request.user)

    # Translations to same language from other components in this project
    other_translations = prefetch_stats(
        list(Translation.objects.prefetch().filter(
            component__project=obj.component.project,
            language=obj.language).exclude(pk=obj.pk)))

    # Include ghost translations for other components, this
    # adds quick way to create translations in other components
    existing = {
        translation.component.slug
        for translation in other_translations
    }
    existing.add(obj.component.slug)
    for test_component in obj.component.project.component_set.filter_access(
            user).exclude(slug__in=existing):
        if test_component.can_add_new_language(user):
            other_translations.append(
                GhostTranslation(test_component, obj.language))

    # Limit the number of other components displayed to 10, preferring untranslated ones
    other_translations = sorted(other_translations,
                                key=lambda t: t.stats.translated_percent)[:10]

    return render(
        request,
        "translation.html",
        {
            "allow_index":
            True,
            "object":
            obj,
            "project":
            obj.component.project,
            "form":
            form,
            "download_form":
            DownloadForm(auto_id="id_dl_%s"),
            "autoform":
            optional_form(
                AutoForm, user, "translation.auto", obj, obj=obj.component),
            "search_form":
            search_form,
            "replace_form":
            optional_form(ReplaceForm, user, "unit.edit", obj),
            "bulk_state_form":
            optional_form(
                BulkEditForm,
                user,
                "translation.auto",
                obj,
                user=user,
                obj=obj,
                project=obj.component.project,
                auto_id="id_bulk_%s",
            ),
            "new_unit_form":
            NewUnitForm(user,
                        initial={"value": Unit(translation=obj, id_hash=-1)}),
            "announcement_form":
            optional_form(AnnouncementForm, user, "component.edit", obj),
            "delete_form":
            optional_form(TranslationDeleteForm,
                          user,
                          "translation.delete",
                          obj,
                          obj=obj),
            "last_changes":
            last_changes,
            "last_changes_url":
            urlencode(obj.get_reverse_url_kwargs()),
            "other_translations":
            other_translations,
            "exporters":
            EXPORTERS.list_exporters(obj),
        },
    )
Ejemplo n.º 2
0
    if letterform.is_valid() and letterform.cleaned_data["letter"] != "":
        terms = terms.filter(source__istartswith=letterform.cleaned_data["letter"])
        letter = letterform.cleaned_data["letter"]
    else:
        letter = ""

    terms = get_paginator(request, terms)

    last_changes = (
        Change.objects.last_changes(request.user)
        .filter(project=prj, language=lang)
        .exclude(glossary_term=None)[:10]
    )

<<<<<<< HEAD
    exporters = [exp for exp in EXPORTERS.list_exporters() if exp['name'] in EXPORT_TYPES]

=======
>>>>>>> f6937a3fbb89f367a68077c658a1823b2f69f80a
    exporters = EXPORTERS.list_exporters_filter(EXPORT_TYPES)

    return render(
        request,
        "glossary.html",
        {
            "title": dict_title(prj, lang),
            "project": prj,
            "language": lang,
            "page_obj": terms,
            "exporters": exporters,
            "form": form,