def show_subproject(request, project, subproject): obj = get_subproject(request, project, subproject) last_changes = Change.objects.prefetch().filter( translation__subproject=obj )[:10] new_lang_form = get_new_language_form(request, obj)(obj) return render( request, 'subproject.html', { 'object': obj, 'project': obj.project, 'translations': sort_objects(obj.translation_set.enabled()), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'subproject': obj.slug, 'project': obj.project.slug} ), 'new_lang_form': new_lang_form, } )
def show_languages(request): return render( request, 'languages.html', { 'languages': sort_objects( Language.objects.have_translation() ), 'title': _('Languages'), } )
def show_languages(request): return render( request, 'languages.html', { 'allow_index': True, 'languages': prefetch_stats( sort_objects( Language.objects.have_translation() ) ), 'title': _('Languages'), } )
def show_component(request, project, component): obj = get_component(request, project, component) user = request.user last_changes = Change.objects.prefetch().filter(component=obj)[:10] return render( request, 'component.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects( prefetch_stats(obj.translation_set.all()) ), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'component': obj.slug, 'project': obj.project.slug} ), 'language_count': Language.objects.filter( translation__component=obj ).distinct().count(), 'replace_form': optional_form(ReplaceForm, user, 'unit.edit', obj), 'bulk_state_form': optional_form( BulkStateForm, user, 'translation.auto', obj, user=user, obj=obj ), 'whiteboard_form': optional_form( WhiteboardForm, user, 'component.edit', obj ), 'delete_form': optional_form( DeleteForm, user, 'component.edit', obj, obj=obj ), 'rename_form': optional_form( ComponentRenameForm, user, 'component.edit', obj, request=request, instance=obj ), 'move_form': optional_form( ComponentMoveForm, user, 'component.edit', obj, request=request, instance=obj ), 'search_form': SearchForm(), } )
def get_unit_translations(request, unit_id): """Return unit's other translations.""" unit = get_object_or_404(Unit, pk=int(unit_id)) request.user.check_access(unit.translation.component.project) return render( request, 'js/translations.html', { 'units': sort_objects( Unit.objects.filter( id_hash=unit.id_hash, translation__component=unit.translation.component, ).exclude( pk=unit.pk ) ), } )
def show_subproject(request, project, subproject): obj = get_subproject(request, project, subproject) last_changes = Change.objects.for_component(obj)[:10] if can_translate(request.user, project=obj.project): replace_form = ReplaceForm() mass_state_form = MassStateForm(request.user, obj) else: replace_form = None mass_state_form = None return render( request, 'subproject.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects(prefetch_stats(obj.translation_set.all())), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode({ 'subproject': obj.slug, 'project': obj.project.slug }), 'language_count': Language.objects.filter( translation__subproject=obj).distinct().count(), 'replace_form': replace_form, 'mass_state_form': mass_state_form, 'search_form': SearchForm(), })
def show_component(request, project, component): obj = get_component(request, project, component) last_changes = Change.objects.for_component(obj)[:10] # Is user allowed to do automatic translation? if request.user.has_perm('translation.auto', obj): mass_state_form = MassStateForm(request.user, obj) else: mass_state_form = None if not request.user.has_perm('unit.edit', obj): replace_form = ReplaceForm() else: replace_form = None return render( request, 'component.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects( prefetch_stats(obj.translation_set.all()) ), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'component': obj.slug, 'project': obj.project.slug} ), 'language_count': Language.objects.filter( translation__component=obj ).distinct().count(), 'replace_form': replace_form, 'mass_state_form': mass_state_form, 'search_form': SearchForm(), } )
def show_subproject(request, project, subproject): obj = get_subproject(request, project, subproject) last_changes = Change.objects.for_component(obj)[:10] new_lang_form = get_new_language_form(request, obj)(obj) if (request.method == 'POST' and can_edit_subproject(request.user, obj.project)): settings_form = SubprojectSettingsForm(request.POST, instance=obj) if settings_form.is_valid(): settings_form.save() messages.success(request, _('Settings saved')) return redirect(obj) else: messages.error( request, _('Invalid settings, please check the form for errors!') ) else: settings_form = SubprojectSettingsForm(instance=obj) return render( request, 'subproject.html', { 'object': obj, 'project': obj.project, 'translations': sort_objects(obj.translation_set.enabled()), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'subproject': obj.slug, 'project': obj.project.slug} ), 'new_lang_form': new_lang_form, 'settings_form': settings_form, } )
def show_component(request, project, component): obj = get_component(request, project, component) user = request.user last_changes = Change.objects.prefetch().filter(component=obj)[:10] return render( request, 'component.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects( prefetch_stats(obj.translation_set.all()) ), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'component': obj.slug, 'project': obj.project.slug} ), 'language_count': Language.objects.filter( translation__component=obj ).distinct().count(), 'replace_form': optional_form(ReplaceForm, user, 'unit.edit', obj), 'mass_state_form': optional_form( MassStateForm, user, 'translation.auto', obj, user=user, obj=obj ), 'delete_form': optional_form( DeleteForm, user, 'component.edit', obj, obj=obj ), 'search_form': SearchForm(), } )
def __init__(self, project, post_data, user): self.project = project self.glossaries = ( Glossary.objects.for_project(project).order_by("name").distinct()) self.data = {(item["term__language"], item["pk"]): item["term__count"] for item in self.glossaries.values( "term__language", "pk").annotate(Count("term"))} try: self.post_id = int(post_data.get("edit_glossary", -1)) except ValueError: self.post_id = -1 self.languages = sort_objects( Language.objects.filter( translation__component__project=project).distinct()) self.forms = { glossary.id: GlossaryForm( user, glossary.project, post_data if self.post_id == glossary.id else None, instance=glossary, auto_id=f"id_edit_{glossary.id}_%s", ) for glossary in self.glossaries }
def order_translated(self): return sort_objects(self)
def show_languages(request): return render( request, 'languages.html', { 'languages': sort_objects(Language.objects.have_translation()), 'title': _('Languages'), })
def show_component(request, project, component): obj = get_component(request, project, component) user = request.user last_changes = Change.objects.prefetch().order().filter(component=obj)[:10] translations = prefetch_stats(list(obj.translation_set.prefetch())) # Show ghost translations for user languages if obj.can_add_new_language(request.user): existing = {translation.language.code for translation in translations} for language in user.profile.languages.all(): if language.code in existing: continue translations.append(GhostTranslation(obj, language)) return render( request, "component.html", { "allow_index": True, "object": obj, "project": obj.project, "translations": sort_objects(translations), "reports_form": ReportsForm(), "last_changes": last_changes, "last_changes_url": urlencode({ "component": obj.slug, "project": obj.project.slug }), "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.project, auto_id="id_bulk_%s", ), "announcement_form": optional_form(AnnouncementForm, user, "component.edit", obj), "delete_form": optional_form( ComponentDeleteForm, user, "component.edit", obj, obj=obj), "rename_form": optional_form( ComponentRenameForm, user, "component.edit", obj, request=request, instance=obj, ), "move_form": optional_form( ComponentMoveForm, user, "component.edit", obj, request=request, instance=obj, ), "search_form": SearchForm(request.user), "alerts": obj.all_alerts, }, )
def show_component(request, project, component): obj = get_component(request, project, component) user = request.user last_changes = Change.objects.prefetch().order().filter(component=obj)[:10] return render( request, 'component.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects(prefetch_stats(obj.translation_set.prefetch())), 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode({ 'component': obj.slug, 'project': obj.project.slug }), 'language_count': Language.objects.filter( translation__component=obj).distinct().count(), '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.project, auto_id="id_bulk_%s", ), 'whiteboard_form': optional_form(WhiteboardForm, user, 'component.edit', obj), 'delete_form': optional_form(DeleteForm, user, 'component.edit', obj, obj=obj), 'rename_form': optional_form( ComponentRenameForm, user, 'component.edit', obj, request=request, instance=obj, ), 'move_form': optional_form( ComponentMoveForm, user, 'component.edit', obj, request=request, instance=obj, ), 'search_form': SearchForm(request.user), 'alerts': obj.all_alerts, }, )
def show_subproject(request, project, subproject): obj = get_subproject(request, project, subproject) last_changes = Change.objects.for_component(obj)[:10] if (request.method == 'POST' and can_edit_subproject(request.user, obj.project)): settings_form = SubprojectSettingsForm(request.POST, instance=obj) if settings_form.is_valid(): settings_form.save() messages.success(request, _('Settings saved')) return redirect(obj) else: messages.error( request, _('Invalid settings, please check the form for errors!') ) else: settings_form = SubprojectSettingsForm(instance=obj) try: sample = obj.translation_set.all()[0] source_words = sample.total_words total_strings = sample.total except IndexError: source_words = 0 total_strings = 0 if can_translate(request.user, project=obj.project): replace_form = ReplaceForm() else: replace_form = None return render( request, 'subproject.html', { 'allow_index': True, 'object': obj, 'project': obj.project, 'translations': sort_objects(obj.translation_set.enabled()), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode( {'subproject': obj.slug, 'project': obj.project.slug} ), 'settings_form': settings_form, 'unit_count': Unit.objects.filter( translation__subproject=obj ).count(), 'words_count': obj.get_total_words(), 'language_count': Language.objects.filter( translation__subproject=obj ).distinct().count(), 'strings_count': total_strings, 'source_words_count': source_words, 'replace_form': replace_form, 'search_form': SearchForm(), } )
def show_subproject(request, project, subproject): obj = get_subproject(request, project, subproject) last_changes = Change.objects.for_component(obj)[:10] if (request.method == 'POST' and can_edit_subproject(request.user, obj.project)): settings_form = SubprojectSettingsForm(request.POST, instance=obj) if settings_form.is_valid(): settings_form.save() messages.success(request, _('Settings saved')) return redirect(obj) else: messages.error( request, _('Invalid settings, please check the form for errors!')) else: settings_form = SubprojectSettingsForm(instance=obj) try: sample = obj.translation_set.all()[0] source_words = sample.total_words total_strings = sample.total except IndexError: source_words = 0 total_strings = 0 if can_translate(request.user, project=obj.project): replace_form = ReplaceForm() else: replace_form = None return render( request, 'subproject.html', { 'object': obj, 'project': obj.project, 'translations': sort_objects(obj.translation_set.enabled()), 'show_language': 1, 'reports_form': ReportsForm(), 'last_changes': last_changes, 'last_changes_url': urlencode({ 'subproject': obj.slug, 'project': obj.project.slug }), 'settings_form': settings_form, 'unit_count': Unit.objects.filter(translation__subproject=obj).count(), 'words_count': obj.get_total_words(), 'language_count': Language.objects.filter( translation__subproject=obj).distinct().count(), 'strings_count': total_strings, 'source_words_count': source_words, 'replace_form': replace_form, 'search_form': SearchForm(), })
def show_component(request, project, component): obj = get_component(request, project, component) user = request.user last_changes = Change.objects.prefetch().order().filter(component=obj)[:10] return render( request, "component.html", { "allow_index": True, "object": obj, "project": obj.project, "translations": sort_objects(prefetch_stats(obj.translation_set.prefetch())), "reports_form": ReportsForm(), "last_changes": last_changes, "last_changes_url": urlencode({ "component": obj.slug, "project": obj.project.slug }), "language_count": Language.objects.filter( translation__component=obj).distinct().count(), "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.project, auto_id="id_bulk_%s", ), "announcement_form": optional_form(AnnouncementForm, user, "component.edit", obj), "delete_form": optional_form(DeleteForm, user, "component.edit", obj, obj=obj), "rename_form": optional_form( ComponentRenameForm, user, "component.edit", obj, request=request, instance=obj, ), "move_form": optional_form( ComponentMoveForm, user, "component.edit", obj, request=request, instance=obj, ), "search_form": SearchForm(request.user), "alerts": obj.all_alerts, }, )