コード例 #1
0
ファイル: basic.py プロジェクト: joaopaulo164/weblate
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if not can_add_translation(request.user, obj.project):
        raise PermissionDenied()

    form = get_new_language_form(request, obj)(obj, request.POST)

    if form.is_valid():
        langs = form.cleaned_data['lang']
        if isinstance(langs, string_types):
            langs = [langs]
        for language in Language.objects.filter(code__in=langs):
            if obj.new_lang == 'contact':
                notify_new_language(obj, language, request.user)
                messages.success(
                    request,
                    _("A request for a new translation has been "
                      "sent to the project's maintainers."))
            elif obj.new_lang == 'add':
                obj.add_new_language(language, request)
    else:
        messages.error(request, _('Invalid language chosen!'))

    return redirect(obj)
コード例 #2
0
ファイル: basic.py プロジェクト: blockgiven/weblate
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    form = NewLanguageForm(request.POST)

    if form.is_valid():
        language = Language.objects.get(code=form.cleaned_data['lang'])
        same_lang = obj.translation_set.filter(language=language)
        if same_lang.exists():
            messages.error(
                request,
                _('Chosen translation already exists in this project!'))
        elif obj.new_lang == 'contact':
            notify_new_language(obj, language, request.user)
            messages.success(
                request,
                _("A request for a new translation has been "
                  "sent to the project's maintainers."))
        elif obj.new_lang == 'add':
            obj.add_new_language(language, request)
    else:
        messages.error(request,
                       _('Failed to process new translation request!'))

    return redirect('subproject',
                    subproject=obj.slug,
                    project=obj.project.slug)
コード例 #3
0
ファイル: basic.py プロジェクト: Insoleet/weblate
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    form = NewLanguageForm(request.POST)

    if form.is_valid():
        language = Language.objects.get(code=form.cleaned_data['lang'])
        same_lang = obj.translation_set.filter(language=language)
        if same_lang.exists():
            messages.error(
                request,
                _('Chosen translation already exists in this project!')
            )
        elif obj.new_lang == 'contact':
            notify_new_language(obj, language, request.user)
            messages.success(
                request,
                _(
                    "A request for a new translation has been "
                    "sent to the project's maintainers."
                )
            )
        elif obj.new_lang == 'add':
            obj.add_new_language(language, request)
    else:
        messages.error(
            request,
            _('Failed to process new translation request!')
        )

    return redirect(
        'subproject',
        subproject=obj.slug,
        project=obj.project.slug
    )
コード例 #4
0
    def test_notify_new_language(self):
        second_user = self.second_user()
        notify_new_language(
            self.subproject,
            Language.objects.filter(code='de'),
            second_user
        )

        # Check mail (second one is for admin)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New language request in Test/Test'
        )

        # Add project owner
        self.subproject.project.owners.add(second_user)
        notify_new_language(
            self.subproject,
            Language.objects.filter(code='de'),
            second_user,
        )

        # Check mail (second one is for admin)
        self.assertEqual(len(mail.outbox), 5)
コード例 #5
0
ファイル: basic.py プロジェクト: ccfwwm/weblate
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if not can_add_translation(request.user, obj.project):
        raise PermissionDenied()

    form = get_new_language_form(request, obj)(obj, request.POST)

    if form.is_valid():
        langs = form.cleaned_data['lang']
        if isinstance(langs, string_types):
            langs = [langs]
        for language in Language.objects.filter(code__in=langs):
            if obj.new_lang == 'contact':
                notify_new_language(obj, language, request.user)
                messages.success(
                    request,
                    _(
                        "A request for a new translation has been "
                        "sent to the project's maintainers."
                    )
                )
            elif obj.new_lang == 'add':
                obj.add_new_language(language, request)
    else:
        messages.error(
            request,
            _('Invalid language chosen!')
        )

    return redirect(obj)
コード例 #6
0
ファイル: test_notifications.py プロジェクト: nleduc/weblate
    def test_notify_new_language(self):
        second_user = self.second_user()
        notify_new_language(
            self.subproject,
            Language.objects.filter(code='de'),
            second_user
        )

        # Check mail (second one is for admin)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Weblate] New language request in Test/Test'
        )

        # Add project owner
        self.subproject.project.owners.add(second_user)
        notify_new_language(
            self.subproject,
            Language.objects.filter(code='de'),
            second_user,
        )

        # Check mail (second one is for admin)
        self.assertEqual(len(mail.outbox), 5)
コード例 #7
0
def new_language(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    form_class = get_new_language_form(request, obj)

    if request.method == 'POST':
        form = form_class(obj, request.POST)

        if form.is_valid():
            langs = form.cleaned_data['lang']
            for language in Language.objects.filter(code__in=langs):
                if obj.new_lang == 'contact':
                    notify_new_language(obj, language, request.user)
                    messages.success(
                        request,
                        _("A request for a new translation has been "
                          "sent to the project's maintainers."))
                elif obj.new_lang == 'add':
                    obj.add_new_language(language, request)
            return redirect(obj)
        else:
            messages.error(request, _('Please fix errors in the form.'))
    else:
        form = form_class(obj)

    return render(request, 'new-language.html', {
        'object': obj,
        'project': obj.project,
        'form': form,
    })