def show_glossary(request, project, lang): prj = get_project(request, project) lang = get_object_or_404(Language, code=lang) if request.method == "POST" and request.user.has_perm("glossary.add", prj): form = TermForm(prj, request.POST) if form.is_valid(): Term.objects.create( request.user, language=lang, source=form.cleaned_data["source"], target=form.cleaned_data["target"], glossary=form.cleaned_data["glossary"], ) return redirect_next(request.POST.get("next"), request.get_full_path()) form = TermForm(prj) uploadform = GlossaryUploadForm(prj) terms = Term.objects.for_project(prj).filter(language=lang).order() letterform = LetterForm(request.GET) searchform = OneTermForm(request.GET) if searchform.is_valid() and searchform.cleaned_data["term"] != "": terms = terms.filter(source__substring=searchform.cleaned_data["term"]) search = searchform.cleaned_data["term"] else: search = "" 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]) 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, "query_string": urlencode({ "term": search, "letter": letter }), "uploadform": uploadform, "letterform": letterform, "searchform": searchform, "letter": letter, "last_changes": last_changes, "last_changes_url": urlencode(( ("project", prj.slug), ("lang", lang.code), ("action", Change.ACTION_DICTIONARY_NEW), ("action", Change.ACTION_DICTIONARY_EDIT), ("action", Change.ACTION_DICTIONARY_UPLOAD), )), }, )
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), }, )
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,