Exemple #1
0
def ajax_add_tag_to_tp_in_project(request, project):
    """Return an HTML snippet with the failed form or blank if valid."""

    add_tag_form = TranslationProjectTagForm(request.POST, project=project)

    if add_tag_form.is_valid():
        translation_project = add_tag_form.cleaned_data['translation_project']
        new_tag_like_object = add_tag_form.save()
        return _add_tag(request, translation_project, new_tag_like_object)
    else:
        # If the form is invalid, perhaps it is because the tag already
        # exists, so instead of creating the tag just retrieve it and add
        # it to the translation project.
        try:
            # Try to retrieve the translation project.
            kwargs = {
                'pk': add_tag_form.data['translation_project'],
            }
            translation_project = TranslationProject.objects.get(**kwargs)

            # Check if the tag (or goal) is already added to the translation
            # project, or try adding it.
            criteria = {
                'name': add_tag_form.data['name'],
                'slug': add_tag_form.data['slug'],
            }
            if len(translation_project.tags.filter(**criteria)) == 1:
                # If the tag is already applied to the translation project then
                # avoid reloading the page.
                return HttpResponse(status=204)
            elif len(translation_project.goals.filter(**criteria)) == 1:
                # If the goal is already applied to the translation project
                # then avoid reloading the page.
                return HttpResponse(status=204)
            else:
                # Else add the tag (or goal) to the translation project.
                if criteria['name'].startswith("goal:"):
                    tag_like_object = Goal.objects.get(**criteria)
                else:
                    tag_like_object = Tag.objects.get(**criteria)
                return _add_tag(request, translation_project, tag_like_object)
        except Exception:
            # If the form is invalid and the tag (or goal) doesn't exist yet
            # then display the form with the error messages.
            url_kwargs = {
                'project_code': project.code,
            }
            context = {
                'add_tag_form':
                add_tag_form,
                'add_tag_action_url':
                reverse('pootle-xhr-tag-tp-in-project', kwargs=url_kwargs)
            }
            return render_to_response('core/xhr_add_tag_form.html', context,
                                      RequestContext(request))
Exemple #2
0
def ajax_add_tag_to_tp_in_project(request, project_code):
    """Return an HTML snippet with the failed form or blank if valid."""

    if not check_permission('administrate', request):
        raise PermissionDenied(_("You do not have rights to add tags."))

    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST'])

    project = get_object_or_404(Project, code=project_code)

    add_tag_form = TranslationProjectTagForm(request.POST, project=project)

    if add_tag_form.is_valid():
        translation_project = add_tag_form.cleaned_data['translation_project']
        new_tag = add_tag_form.save()
        return _add_tag(request, translation_project, new_tag)
    else:
        # If the form is invalid, perhaps it is because the tag already
        # exists, so instead of creating the tag just retrieve it and add
        # it to the translation project.
        try:
            # Try to retrieve the translation project.
            kwargs = {
                'pk': add_tag_form.data['translation_project'],
            }
            translation_project = TranslationProject.objects.get(**kwargs)

            # Check if the tag is already added to the translation project, or
            # try adding it.
            criteria = {
                'name': add_tag_form.data['name'],
                'slug': add_tag_form.data['slug'],
            }
            if len(translation_project.tags.filter(**criteria)) == 1:
                # If the tag is already applied to the translation project then
                # avoid reloading the page.
                return HttpResponse(status=204)
            else:
                # Else add the tag to the translation project.
                tag = Tag.objects.get(**criteria)
                return _add_tag(request, translation_project, tag)
        except Exception:
            # If the form is invalid and the tag doesn't exist yet then display
            # the form with the error messages.
            url_kwargs = {
                'project_code': project.code,
            }
            context = {
                'add_tag_form': add_tag_form,
                'add_tag_action_url': reverse('project.ajax_add_tag_to_tp',
                                              kwargs=url_kwargs)
            }
            return render_to_response('common/xhr_add_tag_form.html',
                                      context, RequestContext(request))
Exemple #3
0
def ajax_add_tag_to_tp_in_project(request, project):
    """Return an HTML snippet with the failed form or blank if valid."""

    add_tag_form = TranslationProjectTagForm(request.POST, project=project)

    if add_tag_form.is_valid():
        translation_project = add_tag_form.cleaned_data['translation_project']
        new_tag_like_object = add_tag_form.save()
        return _add_tag(request, translation_project, new_tag_like_object)
    else:
        # If the form is invalid, perhaps it is because the tag already
        # exists, so instead of creating the tag just retrieve it and add
        # it to the translation project.
        try:
            # Try to retrieve the translation project.
            kwargs = {
                'pk': add_tag_form.data['translation_project'],
            }
            translation_project = TranslationProject.objects.get(**kwargs)

            # Check if the tag (or goal) is already added to the translation
            # project, or try adding it.
            criteria = {
                'name': add_tag_form.data['name'],
                'slug': add_tag_form.data['slug'],
            }
            if len(translation_project.tags.filter(**criteria)) == 1:
                # If the tag is already applied to the translation project then
                # avoid reloading the page.
                return HttpResponse(status=204)
            elif len(translation_project.goals.filter(**criteria)) == 1:
                # If the goal is already applied to the translation project
                # then avoid reloading the page.
                return HttpResponse(status=204)
            else:
                # Else add the tag (or goal) to the translation project.
                if criteria['name'].startswith("goal:"):
                    tag_like_object = Goal.objects.get(**criteria)
                else:
                    tag_like_object = Tag.objects.get(**criteria)
                return _add_tag(request, translation_project, tag_like_object)
        except Exception:
            # If the form is invalid and the tag (or goal) doesn't exist yet
            # then display the form with the error messages.
            url_kwargs = {
                'project_code': project.code,
            }
            context = {
                'add_tag_form': add_tag_form,
                'add_tag_action_url': reverse('project.ajax_add_tag_to_tp',
                                              kwargs=url_kwargs)
            }
            return render_to_response('common/xhr_add_tag_form.html',
                                      context, RequestContext(request))
Exemple #4
0
def ajax_add_tag_to_tp_in_project(request, project):
    """Return an HTML snippet with the failed form or blank if valid."""

    add_tag_form = TranslationProjectTagForm(request.POST, project=project)

    if add_tag_form.is_valid():
        translation_project = add_tag_form.cleaned_data["translation_project"]
        new_tag_like_object = add_tag_form.save()
        return _add_tag(request, translation_project, new_tag_like_object)
    else:
        # If the form is invalid, perhaps it is because the tag already
        # exists, so instead of creating the tag just retrieve it and add
        # it to the translation project.
        try:
            # Try to retrieve the translation project.
            kwargs = {"pk": add_tag_form.data["translation_project"]}
            translation_project = TranslationProject.objects.get(**kwargs)

            # Check if the tag (or goal) is already added to the translation
            # project, or try adding it.
            criteria = {"name": add_tag_form.data["name"], "slug": add_tag_form.data["slug"]}
            if len(translation_project.tags.filter(**criteria)) == 1:
                # If the tag is already applied to the translation project then
                # avoid reloading the page.
                return HttpResponse(status=204)
            elif len(translation_project.goals.filter(**criteria)) == 1:
                # If the goal is already applied to the translation project
                # then avoid reloading the page.
                return HttpResponse(status=204)
            else:
                # Else add the tag (or goal) to the translation project.
                if criteria["name"].startswith("goal:"):
                    tag_like_object = Goal.objects.get(**criteria)
                else:
                    tag_like_object = Tag.objects.get(**criteria)
                return _add_tag(request, translation_project, tag_like_object)
        except Exception:
            # If the form is invalid and the tag (or goal) doesn't exist yet
            # then display the form with the error messages.
            url_kwargs = {"project_code": project.code}
            ctx = {
                "add_tag_form": add_tag_form,
                "add_tag_action_url": reverse("pootle-xhr-tag-tp-in-project", kwargs=url_kwargs),
            }
            return render(request, "core/xhr_add_tag_form.html", ctx)
Exemple #5
0
def overview(request, project):
    """Page listing all languages added to project."""
    from locale import strcoll

    items = [
        make_language_item(translation_project)
        for translation_project in project.get_children().iterator()
    ]
    items.sort(lambda x, y: strcoll(x['title'], y['title']))

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]

    ctx = get_overview_context(request)
    ctx.update({
        'project': project,
        'can_edit': check_permission("administrate", request),
        'table': {
            'id': 'project',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'browser_extends': 'projects/base.html',
        'browser_body_id': 'projectoverview',
    })

    if ctx['can_edit']:
        from pootle_project.forms import DescriptionForm
        tag_action_url = reverse('pootle-xhr-tag-tp-in-project',
                                 kwargs={'project_code': project.code})
        ctx.update({
            'form':
            DescriptionForm(instance=project),
            'form_action':
            reverse('pootle-project-admin-settings', args=[project.code]),
            'add_tag_form':
            TranslationProjectTagForm(project=project),
            'add_tag_action_url':
            tag_action_url,
        })

    return render(request, 'browser/overview.html', ctx)
Exemple #6
0
def overview(request, project):
    """Page listing all languages added to project."""
    can_edit = check_permission('administrate', request)
    templatevars = get_project_base_template_vars(request, project, can_edit)

    if can_edit:
        from pootle_project.forms import DescriptionForm
        url_kwargs = {
            'project_code': project.code,
        }
        templatevars.update({
            'form': DescriptionForm(instance=project),
            'add_tag_form': TranslationProjectTagForm(project=project),
            'add_tag_action_url': reverse('project.ajax_add_tag_to_tp',
                                          kwargs=url_kwargs),
        })

    return render_to_response('project/overview.html', templatevars,
                              context_instance=RequestContext(request))