Exemplo n.º 1
0
def change_project(request, project):
    obj = get_project(request, project)

    if not can_edit_project(request.user, obj):
        raise Http404()

    if request.method == 'POST':
        settings_form = ProjectSettingsForm(request.POST, instance=obj)
        if settings_form.is_valid():
            settings_form.save()
            messages.success(request, _('Settings saved'))
            return redirect('settings', project=obj.slug)
        else:
            messages.error(
                request,
                _('Invalid settings, please check the form for errors!')
            )
    else:
        settings_form = ProjectSettingsForm(instance=obj)

    return render(
        request,
        'project-settings.html',
        {
            'object': obj,
            'settings_form': settings_form,
        }
    )
Exemplo n.º 2
0
def show_project(request, project):
    obj = get_project(request, project)

    dict_langs = Language.objects.filter(dictionary__project=obj).annotate(
        Count('dictionary'))

    if request.method == 'POST' and can_edit_project(request.user, obj):
        settings_form = ProjectSettingsForm(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 = ProjectSettingsForm(instance=obj)

    last_changes = Change.objects.for_project(obj)[:10]

    language_stats = sort_unicode(get_per_language_stats(obj),
                                  lambda tup: force_text(tup[0]))

    language_stats = [(tup[0], translation_percent(tup[1], tup[2]),
                       translation_percent(tup[3], tup[4]))
                      for tup in language_stats]

    if can_translate(request.user, project=obj):
        replace_form = ReplaceForm()
    else:
        replace_form = None

    return render(
        request, 'project.html', {
            'object':
            obj,
            'project':
            obj,
            'dicts':
            dict_langs,
            'last_changes':
            last_changes,
            'last_changes_url':
            urlencode({'project': obj.slug}),
            'settings_form':
            settings_form,
            'language_stats':
            language_stats,
            'unit_count':
            Unit.objects.filter(translation__subproject__project=obj).count(),
            'words_count':
            obj.get_total_words(),
            'language_count':
            Language.objects.filter(
                translation__subproject__project=obj).distinct().count(),
            'strings_count':
            obj.get_total(),
            'source_words_count':
            obj.get_source_words(),
            'search_form':
            SearchForm(),
            'replace_form':
            replace_form,
        })
Exemplo n.º 3
0
def show_project(request, project):
    obj = get_project(request, project)

    dict_langs = Language.objects.filter(
        dictionary__project=obj
    ).annotate(Count('dictionary'))

    if request.method == 'POST' and can_edit_project(request.user, obj):
        settings_form = ProjectSettingsForm(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 = ProjectSettingsForm(instance=obj)

    last_changes = Change.objects.for_project(obj)[:10]

    language_stats = sort_unicode(
        get_per_language_stats(obj), lambda tup: force_text(tup[0])
    )

    language_stats = [
        (
            tup[0],
            translation_percent(tup[1], tup[2]),
            translation_percent(tup[3], tup[4])
        )
        for tup in language_stats
    ]

    if can_translate(request.user, project=obj):
        replace_form = ReplaceForm()
    else:
        replace_form = None

    return render(
        request,
        'project.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj,
            'dicts': dict_langs,
            'last_changes': last_changes,
            'last_changes_url': urlencode(
                {'project': obj.slug}
            ),
            'settings_form': settings_form,
            'language_stats': language_stats,
            'unit_count': Unit.objects.filter(
                translation__subproject__project=obj
            ).count(),
            'words_count': obj.get_total_words(),
            'language_count': Language.objects.filter(
                translation__subproject__project=obj
            ).distinct().count(),
            'strings_count': obj.get_total(),
            'source_words_count': obj.get_source_words(),
            'search_form': SearchForm(),
            'replace_form': replace_form,
        }
    )