예제 #1
0
def test_get_edit_unit(project0_nongnu, get_edit_unit, client,
                       request_users, settings):
    user = request_users["user"]
    if user.username != "nobody":
        client.login(
            username=user.username,
            password=request_users["password"])
    unit = get_edit_unit
    store = unit.store
    filetype = unit.store.filetype.name
    directory = store.parent
    translation_project = store.translation_project
    project = translation_project.project
    language = translation_project.language

    response = client.get(
        "/xhr/units/%s/edit/" % unit.id,
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    request = response.wsgi_request
    result = json.loads(response.content)

    src_lang = unit.store.translation_project.project.source_language
    alt_src_langs = get_alt_src_langs(request, user, translation_project)
    altsrcs = find_altsrcs(unit, alt_src_langs, store=store, project=project)
    altsrcs = {x.id: x.data for x in altsrcs}
    sources = {altsrcs[x]['language_code']: altsrcs[x]['target'] for x in altsrcs}
    sources[src_lang.code] = unit.source

    assert result["is_obsolete"] is False
    assert result["sources"] == sources
    assert response.context["unit"] == unit
    assert response.context["priority"] == store.priority
    assert response.context["store"] == store
    assert response.context["filetype"] == filetype
    assert response.context["directory"] == directory
    assert response.context["project"] == project
    assert response.context["language"] == language
    assert response.context["source_language"] == src_lang
    assert response.context["altsrcs"] == altsrcs

    assert response.context["cantranslate"] == check_user_permission(
        user, "translate", directory)
    assert response.context["cansuggest"] == check_user_permission(
        user, "suggest", directory)
    assert response.context["canreview"] == check_user_permission(
        user, "review", directory)
    assert response.context["has_admin_access"] == check_user_permission(
        user, "administrate", directory)
예제 #2
0
def test_get_edit_unit(client, request_users, settings):

    user = request_users["user"]
    if user.username != "nobody":
        client.login(
            username=user.username,
            password=request_users["password"])

    unit = Unit.objects.get_translatable(user).first()
    store = unit.store
    directory = store.parent
    translation_project = store.translation_project
    project = translation_project.project
    language = translation_project.language

    response = client.get(
        "/xhr/units/%s/edit/" % unit.id,
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    request = response.wsgi_request
    result = json.loads(response.content)

    src_lang = unit.store.translation_project.project.source_language
    alt_src_langs = get_alt_src_langs(request, user, translation_project)
    altsrcs = find_altsrcs(unit, alt_src_langs, store=store, project=project)

    assert result["is_obsolete"] is False
    assert result["sources"] == {src_lang.code: unit.source}

    assert response.context["unit"] == unit
    assert response.context["priority"] == unit.priority
    assert response.context["store"] == store
    assert response.context["directory"] == directory
    assert response.context["project"] == project
    assert response.context["language"] == language
    assert response.context["source_language"] == src_lang
    assert response.context["altsrcs"] == altsrcs

    assert response.context["cantranslate"] == check_user_permission(
        user, "translate", directory)
    assert response.context["cansuggest"] == check_user_permission(
        user, "suggest", directory)
    assert response.context["canreview"] == check_user_permission(
        user, "review", directory)
    assert response.context["has_admin_access"] == check_user_permission(
        user, "administrate", directory)
예제 #3
0
def test_get_edit_unit(client, request_users, settings):

    user = request_users["user"]
    if user.username != "nobody":
        client.login(username=user.username,
                     password=request_users["password"])

    unit = Unit.objects.get_translatable(user).first()
    store = unit.store
    directory = store.parent
    translation_project = store.translation_project
    project = translation_project.project
    language = translation_project.language

    response = client.get("/xhr/units/%s/edit/" % unit.id,
                          HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    request = response.wsgi_request
    result = json.loads(response.content)

    src_lang = unit.store.translation_project.project.source_language
    alt_src_langs = get_alt_src_langs(request, user, translation_project)
    altsrcs = find_altsrcs(unit, alt_src_langs, store=store, project=project)

    assert result["is_obsolete"] is False
    assert result["sources"] == {src_lang.code: unit.source}

    assert response.context["unit"] == unit
    assert response.context["priority"] == unit.priority
    assert response.context["store"] == store
    assert response.context["directory"] == directory
    assert response.context["project"] == project
    assert response.context["language"] == language
    assert response.context["source_language"] == src_lang
    assert response.context["altsrcs"] == altsrcs

    assert response.context["cantranslate"] == check_user_permission(
        user, "translate", directory)
    assert response.context["cansuggest"] == check_user_permission(
        user, "suggest", directory)
    assert response.context["canreview"] == check_user_permission(
        user, "review", directory)
    assert response.context["has_admin_access"] == check_user_permission(
        user, "administrate", directory)
예제 #4
0
def test_get_edit_unit(project0_nongnu, get_edit_unit, client, request_users,
                       settings):
    user = request_users["user"]
    if user.username != "nobody":
        client.login(username=user.username,
                     password=request_users["password"])
    unit = get_edit_unit
    store = unit.store
    filetype = unit.store.filetype.name
    directory = store.parent
    translation_project = store.translation_project
    project = translation_project.project
    language = translation_project.language

    response = client.get("/xhr/units/%s/edit/" % unit.id,
                          HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    request = response.wsgi_request
    result = json.loads(response.content)

    special_characters = []
    for specialchar in language.specialchars:
        code = ord(specialchar)
        special_characters.append({
            'display':
            CHARACTERS_NAMES.get(code, specialchar),
            'code':
            code,
            'hex_code':
            "U+" + hex(code)[2:].upper(),
            'name':
            unicodedata.name(specialchar, ''),
        })

    src_lang = unit.store.translation_project.project.source_language
    alt_src_langs = get_alt_src_langs(request, user, translation_project)
    altsrcs = find_altsrcs(unit, alt_src_langs, store=store, project=project)
    altsrcs = {x.id: x.data for x in altsrcs}
    sources = {
        altsrcs[x]['language_code']: altsrcs[x]['target']
        for x in altsrcs
    }
    sources[src_lang.code] = unit.source
    suggestions_dict = {
        x.id: dict(id=x.id, target=x.target.strings)
        for x in unit.get_suggestions()
    }

    assert result["is_obsolete"] is False
    assert result["sources"] == sources
    assert response.context["unit"] == unit
    assert response.context["priority"] == store.priority
    assert response.context["store"] == store
    assert response.context["filetype"] == filetype
    assert response.context["directory"] == directory
    assert response.context["project"] == project
    assert response.context["language"] == language
    assert response.context["special_characters"] == special_characters
    assert response.context["source_language"] == src_lang
    assert response.context["altsrcs"] == altsrcs
    assert response.context["suggestions_dict"] == suggestions_dict

    assert response.context["cantranslate"] == check_user_permission(
        user, "translate", directory)
    assert response.context["cansuggest"] == check_user_permission(
        user, "suggest", directory)
    assert response.context["canreview"] == check_user_permission(
        user, "review", directory)
    assert response.context["has_admin_access"] == check_user_permission(
        user, "administrate", directory)
예제 #5
0
파일: views.py 프로젝트: notz/pootle
def get_edit_unit(request, unit):
    """Given a store path ``pootle_path`` and unit id ``uid``, gathers all the
    necessary information to build the editing widget.

    :return: A templatised editing widget is returned within the ``editor``
             variable and paging information is also returned if the page
             number has changed.
    """
    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(instance=unit)
    comment_form_class = unit_comment_form_factory(language)
    comment_form = comment_form_class({}, instance=unit)

    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    report_target = ensure_uri(project.report_target)

    suggestions = get_sugg_list(unit)
    template_vars = {
        'unit': unit,
        'form': form,
        'comment_form': comment_form,
        'store': store,
        'directory': directory,
        'profile': profile,
        'user': request.user,
        'language': language,
        'source_language': translation_project.project.source_language,
        'cantranslate': check_profile_permission(profile, "translate",
                                                 directory),
        'cansuggest': check_profile_permission(profile, "suggest", directory),
        'canreview': check_profile_permission(profile, "review", directory),
        'altsrcs': find_altsrcs(unit,
                                alt_src_langs,
                                store=store,
                                project=project),
        'report_target': report_target,
        'suggestions': suggestions,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template('unit/term_edit.html')
    else:
        t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json['editor'] = t.render(c)

    rcode = 200

    # Return context rows if filtering is applied but
    # don't return any if the user has asked not to have it
    current_filter = request.GET.get('filter', 'all')
    show_ctx = request.COOKIES.get('ctxShow', 'true')

    if ((_is_filtered(request) or current_filter not in ('all', ))
            and show_ctx == 'true'):
        # TODO: review if this first 'if' branch makes sense
        if translation_project.project.is_terminology or store.is_terminology:
            json['ctx'] = _filter_ctx_units(store.units, unit, 0)
        else:
            ctx_qty = int(request.COOKIES.get('ctxQty', 1))
            json['ctx'] = _filter_ctx_units(store.units, unit, ctx_qty)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #6
0
파일: views.py 프로젝트: SinSiXX/pootle
def get_edit_unit(request, unit):
    """Given a store path ``pootle_path`` and unit id ``uid``, gathers all the
    necessary information to build the editing widget.

    :return: A templatised editing widget is returned within the ``editor``
             variable and paging information is also returned if the page
             number has changed.
    """
    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(instance=unit)
    comment_form_class = unit_comment_form_factory(language)
    comment_form = comment_form_class({}, instance=unit)

    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    report_target = ensure_uri(project.report_target)

    suggestions = get_sugg_list(unit)
    template_vars = {
        'unit': unit,
        'form': form,
        'comment_form': comment_form,
        'store': store,
        'directory': directory,
        'profile': profile,
        'user': request.user,
        'language': language,
        'source_language': translation_project.project.source_language,
        'cantranslate': check_profile_permission(profile, "translate",
                                                 directory),
        'cansuggest': check_profile_permission(profile, "suggest", directory),
        'canreview': check_profile_permission(profile, "review", directory),
        'altsrcs': find_altsrcs(unit, alt_src_langs, store=store,
                                project=project),
        'report_target': report_target,
        'suggestions': suggestions,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template('unit/term_edit.html')
    else:
        t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json['editor'] = t.render(c)

    rcode = 200

    # Return context rows if filtering is applied but
    # don't return any if the user has asked not to have it
    current_filter = request.GET.get('filter', 'all')
    show_ctx = request.COOKIES.get('ctxShow', 'true')

    if ((_is_filtered(request) or current_filter not in ('all',)) and
        show_ctx == 'true'):
        # TODO: review if this first 'if' branch makes sense
        if translation_project.project.is_terminology or store.is_terminology:
            json['ctx'] = _filter_ctx_units(store.units, unit, 0)
        else:
            ctx_qty = int(request.COOKIES.get('ctxQty', 1))
            json['ctx'] = _filter_ctx_units(store.units, unit, ctx_qty)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #7
0
def test_get_edit_unit(project0_nongnu, get_edit_unit, client,
                       request_users, settings):
    user = request_users["user"]
    if user.username != "nobody":
        client.login(
            username=user.username,
            password=request_users["password"])
    unit = get_edit_unit
    store = unit.store
    filetype = unit.store.filetype.name
    directory = store.parent
    translation_project = store.translation_project
    project = translation_project.project
    language = translation_project.language

    response = client.get(
        "/xhr/units/%s/edit/" % unit.id,
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    request = response.wsgi_request
    result = json.loads(response.content)

    special_characters = []
    for specialchar in language.specialchars:
        code = ord(specialchar)
        special_characters.append({
            'display': CHARACTERS_NAMES.get(code, specialchar),
            'code': code,
            'hex_code': "U+" + hex(code)[2:].upper(),
            'name': unicodedata.name(specialchar, ''),
        })

    src_lang = unit.store.translation_project.project.source_language
    alt_src_langs = get_alt_src_langs(request, user, translation_project)
    altsrcs = find_altsrcs(unit, alt_src_langs, store=store, project=project)
    altsrcs = {x.id: x.data for x in altsrcs}
    sources = {altsrcs[x]['language_code']: altsrcs[x]['target'] for x in altsrcs}
    sources[src_lang.code] = unit.source
    suggestions_dict = {x.id: dict(id=x.id, target=x.target.strings)
                        for x in unit.get_suggestions()}

    assert result["is_obsolete"] is False
    assert result["sources"] == sources
    assert response.context["unit"] == unit
    assert response.context["priority"] == store.priority
    assert response.context["store"] == store
    assert response.context["filetype"] == filetype
    assert response.context["directory"] == directory
    assert response.context["project"] == project
    assert response.context["language"] == language
    assert response.context["special_characters"] == special_characters
    assert response.context["source_language"] == src_lang
    assert response.context["altsrcs"] == altsrcs
    assert response.context["suggestions_dict"] == suggestions_dict

    assert response.context["cantranslate"] == check_user_permission(
        user, "translate", directory)
    assert response.context["cansuggest"] == check_user_permission(
        user, "suggest", directory)
    assert response.context["canreview"] == check_user_permission(
        user, "review", directory)
    assert response.context["has_admin_access"] == check_user_permission(
        user, "administrate", directory)