コード例 #1
0
ファイル: helpers.py プロジェクト: JeroenKnoops/pootle
def get_translation_context(request, is_terminology=False):
    """Return a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    :param is_terminology: boolean indicating if the translation context
        is relevant to a terminology project.
    """
    return {
        'cantranslate':
        check_permission("translate", request),
        'cansuggest':
        check_permission("suggest", request),
        'canreview':
        check_permission("review", request),
        'is_admin':
        check_permission('administrate', request),
        'profile':
        request.profile,
        'pootle_path':
        request.pootle_path,
        'ctx_path':
        request.ctx_path,
        'resource_path':
        (request.resource_path if hasattr(request, 'resource_path') else ''),
        'check_categories':
        get_qualitycheck_schema(),
        'search_form':
        make_search_form(request=request, terminology=is_terminology),
        'MT_BACKENDS':
        settings.MT_BACKENDS,
        'LOOKUP_BACKENDS':
        settings.LOOKUP_BACKENDS,
        'AMAGAMA_URL':
        settings.AMAGAMA_URL,
    }
コード例 #2
0
ファイル: project.py プロジェクト: gitter-badger/pootle
def _test_translate_view(project, request, response, kwargs, settings):
    ctx = response.context
    user = request.profile
    kwargs["project_code"] = project.code
    ctx_path = "/projects/%(project_code)s/" % kwargs
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    pootle_path = "%s%s" % (ctx_path, resource_path)
    view_context_test(
        ctx,
        **dict(
            page="translate",
            is_admin=False,
            language=None,
            project=project,
            profile=user,
            pootle_path="%s%s" % (ctx_path, resource_path),
            ctx_path=ctx_path,
            resource_path=resource_path,
            resource_path_parts=get_path_parts(resource_path),
            editor_extends="projects/base.html",
            check_categories=get_qualitycheck_schema(),
            previous_url=get_previous_url(request),
            display_priority=(VirtualFolderTreeItem.objects.filter(pootle_path__startswith=pootle_path).exists()),
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL,
        )
    )
コード例 #3
0
ファイル: helpers.py プロジェクト: hakanai/pootle
def get_overview_context(request):
    """Returns a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    url_action_continue = resource_obj.get_translate_url(state='incomplete')
    url_action_fixcritical = resource_obj.get_critical_url()
    url_action_review = resource_obj.get_translate_url(state='suggestions')
    url_action_view_all = resource_obj.get_translate_url(state='all')

    return {
        'page': 'overview',
        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),
        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),
        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
    }
コード例 #4
0
ファイル: project.py プロジェクト: nathan-lewis/pootle
def _test_translate_view(project, request, response, kwargs, settings):
    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = ("/projects/%(project_code)s/" % kwargs)
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    view_context_test(
        ctx,
        **dict(page="translate",
               is_admin=False,
               language=None,
               project=project,
               pootle_path=pootle_path,
               ctx_path=ctx_path,
               resource_path=resource_path,
               resource_path_parts=get_path_parts(resource_path),
               editor_extends="projects/base.html",
               check_categories=get_qualitycheck_schema(),
               previous_url=get_previous_url(request),
               display_priority=(VirtualFolderTreeItem.objects.filter(
                   pootle_path__startswith=pootle_path).exists()),
               cantranslate=check_permission("translate", request),
               cansuggest=check_permission("suggest", request),
               canreview=check_permission("review", request),
               search_form=make_search_form(request=request),
               current_vfolder_pk="",
               POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
               AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #5
0
ファイル: helpers.py プロジェクト: henriksa/pootle
def get_overview_context(request):
    """Return a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    url_action_continue = resource_obj.get_translate_url(state='incomplete')
    url_action_fixcritical = resource_obj.get_critical_url()
    url_action_review = resource_obj.get_translate_url(state='suggestions')
    url_action_view_all = resource_obj.get_translate_url(state='all')
    url_action_next_goal = resource_obj.get_next_goal_url()

    return {
        'page': 'overview',

        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),

        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
        'url_action_next_goal': url_action_next_goal,
    }
コード例 #6
0
ファイル: helpers.py プロジェクト: JeroenKnoops/pootle
def get_translation_context(request, is_terminology=False):
    """Return a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    :param is_terminology: boolean indicating if the translation context
        is relevant to a terminology project.
    """
    return {
        'cantranslate': check_permission("translate", request),
        'cansuggest': check_permission("suggest", request),
        'canreview': check_permission("review", request),
        'is_admin': check_permission('administrate', request),
        'profile': request.profile,

        'pootle_path': request.pootle_path,
        'ctx_path': request.ctx_path,
        'resource_path': (request.resource_path
                          if hasattr(request, 'resource_path') else ''),

        'check_categories': get_qualitycheck_schema(),

        'search_form': make_search_form(request=request,
                                        terminology=is_terminology),

        'MT_BACKENDS': settings.MT_BACKENDS,
        'LOOKUP_BACKENDS': settings.LOOKUP_BACKENDS,
        'AMAGAMA_URL': settings.AMAGAMA_URL,
    }
コード例 #7
0
ファイル: project.py プロジェクト: sjhale/pootle
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = ("/projects/%(project_code)s/" % kwargs)
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False
    view_context_test(
        ctx,
        **dict(page="translate",
               has_admin_access=request.user.is_superuser,
               language=None,
               project=project,
               pootle_path=pootle_path,
               ctx_path=ctx_path,
               resource_path=resource_path,
               resource_path_parts=get_path_parts(resource_path),
               editor_extends="projects/base.html",
               check_categories=get_qualitycheck_schema(),
               previous_url=get_previous_url(request),
               display_priority=display_priority,
               cantranslate=check_permission("translate", request),
               cansuggest=check_permission("suggest", request),
               canreview=check_permission("review", request),
               search_form=make_search_form(request=request),
               current_vfolder_pk="",
               POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
               AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #8
0
ファイル: views.py プロジェクト: nathan-lewis/pootle
    def get_context_data(self, *args, **kwargs):
        filters = {}
        if self.has_vfolders:
            filters['sort'] = 'priority'

        url_action_continue = self.object.get_translate_url(
            state='incomplete',
            **filters)
        url_action_fixcritical = self.object.get_critical_url(
            **filters)
        url_action_review = self.object.get_translate_url(
            state='suggestions',
            **filters)
        url_action_view_all = self.object.get_translate_url(state='all')
        ctx, cookie_data = self.sidebar_announcements
        ctx.update(
            super(PootleBrowseView, self).get_context_data(*args, **kwargs))
        ctx.update(
            {'page': 'browse',
             'stats': jsonify(self.stats),
             'translation_states': get_translation_states(self.object),
             'check_categories': get_qualitycheck_schema(self.object),
             'url_action_continue': url_action_continue,
             'url_action_fixcritical': url_action_fixcritical,
             'url_action_review': url_action_review,
             'url_action_view_all': url_action_view_all,
             'table': self.table,
             'is_store': self.is_store,
             'browser_extends': self.template_extends})
        return ctx
コード例 #9
0
def get_overview_context(request):
    """Returns a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    filters = {}

    if (not isinstance(resource_obj, Store)
            and VirtualFolder.get_matching_for(request.pootle_path).count()):
        filters['sort'] = 'priority'

    url_action_continue = resource_obj.get_translate_url(state='incomplete',
                                                         **filters)
    url_action_fixcritical = resource_obj.get_critical_url(**filters)
    url_action_review = resource_obj.get_translate_url(state='suggestions',
                                                       **filters)
    url_action_view_all = resource_obj.get_translate_url(state='all')

    return {
        'page': 'overview',
        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),
        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),
        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
    }
コード例 #10
0
ファイル: tp.py プロジェクト: haf/pootle
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)
    vfolder, pootle_path = extract_vfolder_from_path(request_path)
    current_vfolder_pk = vfolder.pk if vfolder else ""
    display_priority = not current_vfolder_pk and (
        VirtualFolderTreeItem.objects.filter(pootle_path__startswith=pootle_path).exists()
    )
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        is_admin=False,
        profile=request.profile,
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        check_categories=get_qualitycheck_schema(),
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL,
    )
    view_context_test(ctx, **assertions)
コード例 #11
0
ファイル: project.py プロジェクト: paxswill/pootle
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(username=user.username, password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    request = response.wsgi_request
    assertions = dict(page="translate",
                      is_admin=False,
                      language=None,
                      project=None,
                      pootle_path="/projects/",
                      ctx_path="/projects/",
                      resource_path="",
                      resource_path_parts=[],
                      editor_extends="projects/all/base.html",
                      check_categories=get_qualitycheck_schema(),
                      previous_url=get_previous_url(request),
                      display_priority=False,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      current_vfolder_pk="",
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #12
0
ファイル: tp.py プロジェクト: Cedric31/pootle
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)
    vfolder, pootle_path = extract_vfolder_from_path(request_path)
    current_vfolder_pk = (vfolder.pk if vfolder else "")
    display_priority = (not current_vfolder_pk and not kwargs['filename']
                        and ctx['object'].has_vfolders)
    assertions = dict(page="translate",
                      translation_project=tp,
                      language=tp.language,
                      project=tp.project,
                      is_admin=check_permission('administrate', request),
                      ctx_path=tp.pootle_path,
                      pootle_path=request_path,
                      resource_path=resource_path,
                      resource_path_parts=get_path_parts(resource_path),
                      editor_extends="translation_projects/base.html",
                      check_categories=get_qualitycheck_schema(),
                      previous_url=get_previous_url(request),
                      current_vfolder_pk=current_vfolder_pk,
                      display_priority=display_priority,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #13
0
ファイル: helpers.py プロジェクト: mail-apps/pootle
def get_browser_context(request):
    """Returns a common context for browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    filters = {}

    if ((isinstance(resource_obj, Directory) and resource_obj.has_vfolders)
            or (isinstance(resource_obj, TranslationProject)
                and resource_obj.directory.has_vfolders)):
        filters['sort'] = 'priority'

    url_action_continue = resource_obj.get_translate_url(state='incomplete',
                                                         **filters)
    url_action_fixcritical = resource_obj.get_critical_url(**filters)
    url_action_review = resource_obj.get_translate_url(state='suggestions',
                                                       **filters)
    url_action_view_all = resource_obj.get_translate_url(state='all')

    return {
        'page': 'browse',
        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),
        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),
        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
    }
コード例 #14
0
ファイル: project.py プロジェクト: gitter-badger/pootle
def test_view_projects_translate(site_permissions, site_matrix_with_vfolders, client, nobody, default, settings):
    response = client.get(reverse("pootle-projects-translate"))
    ctx = response.context
    request = response.wsgi_request
    assertions = dict(
        page="translate",
        is_admin=False,
        language=None,
        project=None,
        profile=request.profile,
        pootle_path="/projects/",
        ctx_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        editor_extends="projects/all/base.html",
        check_categories=get_qualitycheck_schema(),
        previous_url=get_previous_url(request),
        display_priority=False,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        current_vfolder_pk="",
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL,
    )
    view_context_test(ctx, **assertions)
コード例 #15
0
ファイル: views.py プロジェクト: haf/pootle
    def get_context_data(self, *args, **kwargs):
        filters = {}
        if self.has_vfolders:
            filters['sort'] = 'priority'

        url_action_continue = self.object.get_translate_url(
            state='incomplete',
            **filters)
        url_action_fixcritical = self.object.get_critical_url(
            **filters)
        url_action_review = self.object.get_translate_url(
            state='suggestions',
            **filters)
        url_action_view_all = self.object.get_translate_url(state='all')
        ctx, cookie_data = self.sidebar_announcements
        ctx.update(
            super(PootleBrowseView, self).get_context_data(*args, **kwargs))
        ctx.update(
            {'page': 'browse',
             'stats': jsonify(self.stats),
             'translation_states': get_translation_states(self.object),
             'check_categories': get_qualitycheck_schema(self.object),
             'url_action_continue': url_action_continue,
             'url_action_fixcritical': url_action_fixcritical,
             'url_action_review': url_action_review,
             'url_action_view_all': url_action_view_all,
             'table': self.table,
             'is_store': self.is_store,
             'browser_extends': self.template_extends})
        return ctx
コード例 #16
0
ファイル: project.py プロジェクト: phlax/pootle
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    request = response.wsgi_request
    assertions = dict(
        page="translate",
        has_admin_access=user.is_superuser,
        language=None,
        project=None,
        pootle_path="/projects/",
        ctx_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        editor_extends="projects/all/base.html",
        check_categories=get_qualitycheck_schema(),
        previous_url=get_previous_url(request),
        display_priority=False,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        current_vfolder_pk="",
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #17
0
ファイル: helpers.py プロジェクト: mail-apps/pootle
def get_translation_context(request):
    """Returns a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_path = getattr(request, 'resource_path', '')
    vfolder_pk = getattr(request, 'current_vfolder', '')
    display_priority = False

    if not vfolder_pk:
        display_priority = VirtualFolder.objects.filter(
            units__store__pootle_path__startswith=request.pootle_path).exists(
            )

    return {
        'page': 'translate',
        'cantranslate': check_permission("translate", request),
        'cansuggest': check_permission("suggest", request),
        'canreview': check_permission("review", request),
        'is_admin': check_permission('administrate', request),
        'profile': request.profile,
        'pootle_path': request.pootle_path,
        'ctx_path': request.ctx_path,
        'current_vfolder_pk': vfolder_pk,
        'display_priority': display_priority,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),
        'check_categories': get_qualitycheck_schema(),
        'search_form': make_search_form(request=request),
        'previous_url': get_previous_url(request),
        'POOTLE_MT_BACKENDS': settings.POOTLE_MT_BACKENDS,
        'AMAGAMA_URL': settings.AMAGAMA_URL,
    }
コード例 #18
0
ファイル: helpers.py プロジェクト: gitter-badger/pootle
def get_translation_context(request):
    """Returns a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_path = getattr(request, 'resource_path', '')
    vfolder_pk = getattr(request, 'current_vfolder', '')

    return {
        'page': 'translate',

        'cantranslate': check_permission("translate", request),
        'cansuggest': check_permission("suggest", request),
        'canreview': check_permission("review", request),
        'is_admin': check_permission('administrate', request),
        'profile': request.profile,

        'pootle_path': request.pootle_path,
        'ctx_path': request.ctx_path,
        'current_vfolder_pk': vfolder_pk,
        'display_priority': display_vfolder_priority(request),
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'check_categories': get_qualitycheck_schema(),

        'search_form': make_search_form(request=request),

        'previous_url': get_previous_url(request),

        'POOTLE_MT_BACKENDS': settings.POOTLE_MT_BACKENDS,
        'AMAGAMA_URL': settings.AMAGAMA_URL,
    }
コード例 #19
0
ファイル: language.py プロジェクト: haf/pootle
def _test_translate_view(language, request, response, kwargs, settings):
    ctx = response.context
    view_context_test(
        ctx,
        **dict(
            project=None,
            language=language,
            page="translate",
            ctx_path=language.directory.pootle_path,
            pootle_path=language.directory.pootle_path,
            resource_path="",
            resource_path_parts=[],
            profile=request.profile,
            editor_extends="languages/base.html",
            check_categories=get_qualitycheck_schema(),
            previous_url=get_previous_url(request),
            display_priority=False,
            is_admin=check_permission('administrate', request),
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #20
0
ファイル: project.py プロジェクト: nathan-lewis/pootle
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    project_path = ("%s/%s" % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        ob = project
    elif not kwargs["filename"]:
        ob = ProjectResource(Directory.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                             pootle_path="/projects/%s" % project_path)
    else:
        ob = ProjectResource(Store.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                             pootle_path="/projects/%s" % project_path)

    item_func = (make_xlanguage_item if
                 (kwargs["dir_path"]
                  or kwargs["filename"]) else make_language_item)
    items = [
        item_func(item) for item in ob.get_children_for_user(request.user)
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'project',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items
    }

    assertions = dict(
        page="browse",
        project=project,
        browser_extends="projects/base.html",
        pootle_path="/projects/%s" % project_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        url_action_continue=ob.get_translate_url(state='incomplete'),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state='suggestions'),
        url_action_view_all=ob.get_translate_url(state='all'),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        table=table,
        stats=jsonify(ob.get_stats()))
    sidebar = get_sidebar_announcements_context(request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
コード例 #21
0
ファイル: project.py プロジェクト: gitter-badger/pootle
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    project_path = "%s/%s" % (kwargs["project_code"], resource_path)
    if not (kwargs["dir_path"] or kwargs["filename"]):
        ob = project
    elif not kwargs["filename"]:
        ob = ProjectResource(
            Directory.objects.live().filter(pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path,
        )
    else:
        ob = ProjectResource(
            Store.objects.live().filter(pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path,
        )

    item_func = make_xlanguage_item if (kwargs["dir_path"] or kwargs["filename"]) else make_language_item
    items = [item_func(item) for item in ob.get_children_for_user(request.profile)]
    items.sort(lambda x, y: locale.strcoll(x["title"], y["title"]))

    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]
    table = {"id": "project", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items}

    assertions = dict(
        page="browse",
        project=project,
        resource_obj=ob,
        browser_extends="projects/base.html",
        pootle_path="/projects/%s" % project_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        url_action_continue=ob.get_translate_url(state="incomplete"),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state="suggestions"),
        url_action_view_all=ob.get_translate_url(state="all"),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        table=table,
        stats=jsonify(ob.get_stats()),
    )
    sidebar = get_sidebar_announcements_context(request, (project,))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
コード例 #22
0
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (
        Project.objects.for_user(request.user)
                       .filter(code__in=user_projects))
    obj = ProjectSet(user_projects)
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    assertions = dict(
        page="translate",
        has_admin_access=user.is_superuser,
        language=None,
        project=None,
        pootle_path="/projects/",
        ctx_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        editor_extends="projects/all/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        display_priority=False,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        current_vfolder_pk="",
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #23
0
ファイル: tp.py プロジェクト: ainslied/pootle
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    current_vfolder_pk = ""
    display_priority = False
    if not kwargs["filename"]:
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        display_priority = vf_view.has_data
    unit_api_root = "/xhr/units/"
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        unit_api_root=unit_api_root,
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #24
0
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = (
        "/projects/%(project_code)s/" % kwargs)
    resource_path = (
        "%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = ctx["object"].data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    view_context_test(
        ctx,
        **dict(
            page="translate",
            has_admin_access=request.user.is_superuser,
            language=None,
            project=project,
            pootle_path=pootle_path,
            ctx_path=ctx_path,
            resource_path=resource_path,
            resource_path_parts=get_path_parts(resource_path),
            editor_extends="projects/base.html",
            checks=_checks,
            previous_url=get_previous_url(request),
            display_priority=display_priority,
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #25
0
def test_view_projects_browse(client, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(reverse("pootle-projects-browse"))
    assert response.cookies["pootle-language"].value == "projects"
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (
        Project.objects.for_user(request.user)
                       .filter(code__in=user_projects))
    ob = ProjectSet(user_projects)
    items = [
        make_project_list_item(project)
        for project in ob.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    table_fields = [
        'name', 'progress', 'total', 'need-translation',
        'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'projects',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items}

    if request.user.is_superuser:
        url_action_continue = ob.get_translate_url(state='incomplete')
        url_action_fixcritical = ob.get_critical_url()
        url_action_review = ob.get_translate_url(state='suggestions')
        url_action_view_all = ob.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4

    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=ob,
        table=table,
        browser_extends="projects/all/base.html",
        stats=jsonify(ob.get_stats()),
        check_categories=get_qualitycheck_schema(ob),
        translation_states=get_translation_states(ob),
        url_action_continue=url_action_continue,
        url_action_fixcritical=url_action_fixcritical,
        url_action_review=url_action_review,
        url_action_view_all=url_action_view_all)
    view_context_test(ctx, **assertions)
コード例 #26
0
ファイル: project.py プロジェクト: Cedric31/pootle
def test_view_projects_browse(client, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(reverse("pootle-projects-browse"))
    assert response.cookies["pootle-language"].value == "projects"
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (
        Project.objects.for_user(request.user)
                       .filter(code__in=user_projects))
    ob = ProjectSet(user_projects)
    items = [
        make_project_list_item(project)
        for project in ob.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    table_fields = [
        'name', 'progress', 'total', 'need-translation',
        'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'projects',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items}

    if request.user.is_superuser:
        url_action_continue = ob.get_translate_url(state='incomplete')
        url_action_fixcritical = ob.get_critical_url()
        url_action_review = ob.get_translate_url(state='suggestions')
        url_action_view_all = ob.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4

    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=ob,
        table=table,
        browser_extends="projects/all/base.html",
        stats=jsonify(ob.get_stats()),
        check_categories=get_qualitycheck_schema(ob),
        translation_states=get_translation_states(ob),
        url_action_continue=url_action_continue,
        url_action_fixcritical=url_action_fixcritical,
        url_action_review=url_action_review,
        url_action_view_all=url_action_view_all)
    view_context_test(ctx, **assertions)
コード例 #27
0
ファイル: translate.py プロジェクト: translate/pootle
 def checks(self):
     check_data = self.check_data
     checks = get_qualitychecks()
     schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
     _checks = {}
     for check, checkid in checks.items():
         if check not in check_data:
             continue
         _checkid = schema[checkid]["name"]
         _checks[_checkid] = _checks.get(_checkid, dict(checks=[], title=schema[checkid]["title"]))
         _checks[_checkid]["checks"].append(dict(code=check, title=check_names[check], count=check_data[check]))
     return OrderedDict((k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
コード例 #28
0
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    current_vfolder_pk = ""
    display_priority = False
    if not kwargs["filename"]:
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        display_priority = vf_view.has_data
    unit_api_root = "/xhr/units/"
    assertions = dict(page="translate",
                      translation_project=tp,
                      language=tp.language,
                      project=tp.project,
                      has_admin_access=check_permission(
                          'administrate', request),
                      ctx_path=tp.pootle_path,
                      pootle_path=request_path,
                      resource_path=resource_path,
                      resource_path_parts=get_path_parts(resource_path),
                      editor_extends="translation_projects/base.html",
                      checks=_checks,
                      previous_url=get_previous_url(request),
                      current_vfolder_pk=current_vfolder_pk,
                      display_priority=display_priority,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      unit_api_root=unit_api_root,
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #29
0
ファイル: tp.py プロジェクト: phlax/pootle
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)
    if request.path.startswith("/++vfolder"):
        vfolder = VirtualFolder.objects.get(
            name=request.resolver_match.kwargs["vfolder_name"])
        current_vfolder_pk = vfolder.pk
        display_priority = False
        unit_api_root = reverse(
            "vfolder-pootle-xhr-units",
            kwargs=dict(vfolder_name=vfolder.name))
        resource_path = (
            "/".join(
                ["++vfolder",
                 vfolder.name,
                 ctx['object'].pootle_path.replace(tp.pootle_path, "")]))
    else:
        vfolder = None
        current_vfolder_pk = ""
        display_priority = False
        if not kwargs["filename"]:
            vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
            display_priority = vf_view.has_data
        unit_api_root = "/xhr/units/"
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        check_categories=get_qualitycheck_schema(),
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        unit_api_root=unit_api_root,
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #30
0
ファイル: project.py プロジェクト: rmoch/pootle
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = ("/projects/%(project_code)s/" % kwargs)
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = ctx["object"].data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    view_context_test(
        ctx,
        **dict(page="translate",
               has_admin_access=request.user.is_superuser,
               language=None,
               project=project,
               pootle_path=pootle_path,
               ctx_path=ctx_path,
               resource_path=resource_path,
               resource_path_parts=get_path_parts(resource_path),
               editor_extends="projects/base.html",
               checks=_checks,
               previous_url=get_previous_url(request),
               display_priority=display_priority,
               cantranslate=check_permission("translate", request),
               cansuggest=check_permission("suggest", request),
               canreview=check_permission("review", request),
               search_form=make_search_form(request=request),
               current_vfolder_pk="",
               POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
               AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #31
0
ファイル: project.py プロジェクト: rmoch/pootle
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(username=user.username, password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (Project.objects.for_user(
        request.user).filter(code__in=user_projects))
    obj = ProjectSet(user_projects)
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    assertions = dict(page="translate",
                      has_admin_access=user.is_superuser,
                      language=None,
                      project=None,
                      pootle_path="/projects/",
                      ctx_path="/projects/",
                      resource_path="",
                      resource_path_parts=[],
                      editor_extends="projects/all/base.html",
                      checks=_checks,
                      previous_url=get_previous_url(request),
                      display_priority=False,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      current_vfolder_pk="",
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #32
0
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)
    if request.path.startswith("/++vfolder"):
        vfolder = VirtualFolder.objects.get(
            name=request.resolver_match.kwargs["vfolder_name"])
        current_vfolder_pk = vfolder.pk
        display_priority = False
        unit_api_root = reverse("vfolder-pootle-xhr-units",
                                kwargs=dict(vfolder_name=vfolder.name))
        resource_path = ("/".join([
            "++vfolder", vfolder.name,
            ctx['object'].pootle_path.replace(tp.pootle_path, "")
        ]))
    else:
        vfolder = None
        current_vfolder_pk = ""
        display_priority = False
        if not kwargs["filename"]:
            vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
            display_priority = vf_view.has_data
        unit_api_root = "/xhr/units/"
    assertions = dict(page="translate",
                      translation_project=tp,
                      language=tp.language,
                      project=tp.project,
                      has_admin_access=check_permission(
                          'administrate', request),
                      ctx_path=tp.pootle_path,
                      pootle_path=request_path,
                      resource_path=resource_path,
                      resource_path_parts=get_path_parts(resource_path),
                      editor_extends="translation_projects/base.html",
                      check_categories=get_qualitycheck_schema(),
                      previous_url=get_previous_url(request),
                      current_vfolder_pk=current_vfolder_pk,
                      display_priority=display_priority,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      unit_api_root=unit_api_root,
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #33
0
 def get_context_data(self, *args, **kwargs):
     ctx = super(PootleTranslateView, self).get_context_data(*args, **kwargs)
     ctx.update({
         'page': 'translate',
         'ctx_path': self.ctx_path,
         'check_categories': get_qualitycheck_schema(),
         'cantranslate': check_permission("translate", self.request),
         'cansuggest': check_permission("suggest", self.request),
         'canreview': check_permission("review", self.request),
         'search_form': make_search_form(request=self.request),
         'previous_url': get_previous_url(self.request),
         'ZING_MT_BACKENDS': settings.ZING_MT_BACKENDS,
         'editor_extends': self.template_extends,
     })
     return ctx
コード例 #34
0
ファイル: helpers.py プロジェクト: JeroenKnoops/pootle
def get_overview_context(request):
    """Return a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj

    return {
        'resource_obj': resource_obj,
        'resource_path': (request.resource_path
                          if hasattr(request, 'resource_path') else ''),

        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),
    }
コード例 #35
0
ファイル: helpers.py プロジェクト: shayanb/pootle
def get_translation_context(request, is_terminology=False):
    """Return a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    :param is_terminology: boolean indicating if the translation context
        is relevant to a terminology project.
    """
    resource_path = getattr(request, 'resource_path', '')

    user = request.user
    if not user.is_authenticated():
        user = User.objects.get_nobody_user()

    return {
        'page':
        'translate',
        'cantranslate':
        check_permission("translate", request),
        'cansuggest':
        check_permission("suggest", request),
        'canreview':
        check_permission("review", request),
        'is_admin':
        check_permission('administrate', request),
        'pootle_path':
        request.pootle_path,
        'ctx_path':
        request.ctx_path,
        'resource_path':
        resource_path,
        'resource_path_parts':
        get_path_parts(resource_path),
        'check_categories':
        get_qualitycheck_schema(),
        'unit_rows':
        user.unit_rows,
        'search_form':
        make_search_form(request=request, terminology=is_terminology),
        'previous_url':
        get_previous_url(request),
        'MT_BACKENDS':
        settings.MT_BACKENDS,
        'LOOKUP_BACKENDS':
        settings.LOOKUP_BACKENDS,
        'AMAGAMA_URL':
        settings.AMAGAMA_URL,
    }
コード例 #36
0
ファイル: helpers.py プロジェクト: JeroenKnoops/pootle
def get_overview_context(request):
    """Return a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj

    return {
        'resource_obj':
        resource_obj,
        'resource_path':
        (request.resource_path if hasattr(request, 'resource_path') else ''),
        'translation_states':
        get_translation_states(resource_obj),
        'check_categories':
        get_qualitycheck_schema(resource_obj),
    }
コード例 #37
0
 def get_context_data(self, *args, **kwargs):
     ctx = super().get_context_data(*args, **kwargs)
     ctx.update(
         {
             "page": "translate",
             "ctx_path": self.ctx_path,
             "check_categories": get_qualitycheck_schema(),
             "cantranslate": check_permission("translate", self.request),
             "cansuggest": check_permission("suggest", self.request),
             "canreview": check_permission("review", self.request),
             "search_form": make_search_form(request=self.request),
             "previous_url": get_previous_url(self.request),
             "ZING_MT_BACKENDS": settings.ZING_MT_BACKENDS,
             "editor_extends": self.template_extends,
         }
     )
     return ctx
コード例 #38
0
ファイル: translate.py プロジェクト: phlax/pootle
 def get_context_data(self, *args, **kwargs):
     ctx = super(PootleTranslateView, self).get_context_data(*args, **kwargs)
     ctx.update(
         {'page': 'translate',
          'current_vfolder_pk': self.vfolder_pk,
          'ctx_path': self.ctx_path,
          'display_priority': self.display_vfolder_priority,
          'check_categories': get_qualitycheck_schema(),
          'cantranslate': check_permission("translate", self.request),
          'cansuggest': check_permission("suggest", self.request),
          'canreview': check_permission("review", self.request),
          'search_form': make_search_form(request=self.request),
          'previous_url': get_previous_url(self.request),
          'POOTLE_MT_BACKENDS': settings.POOTLE_MT_BACKENDS,
          'AMAGAMA_URL': settings.AMAGAMA_URL,
          'editor_extends': self.template_extends})
     return ctx
コード例 #39
0
ファイル: translate.py プロジェクト: YESLTD/pootle
 def checks(self):
     check_data = self.check_data
     checks = get_qualitychecks()
     schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
     _checks = {}
     for check, checkid in checks.items():
         if check not in check_data:
             continue
         _checkid = schema[checkid]["name"]
         _checks[_checkid] = _checks.get(
             _checkid, dict(checks=[], title=schema[checkid]["title"]))
         _checks[_checkid]["checks"].append(
             dict(code=check,
                  title=check_names[check],
                  count=check_data[check]))
     return OrderedDict(
         (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
コード例 #40
0
 def get_context_data(self, *args, **kwargs):
     ctx = super(
         PootleTranslateView, self).get_context_data(*args, **kwargs)
     ctx.update(
         {'page': 'translate',
          'current_vfolder_pk': self.vfolder_pk,
          'ctx_path': self.ctx_path,
          'display_priority': self.display_vfolder_priority,
          'check_categories': get_qualitycheck_schema(),
          'cantranslate': check_permission("translate", self.request),
          'cansuggest': check_permission("suggest", self.request),
          'canreview': check_permission("review", self.request),
          'search_form': make_search_form(request=self.request),
          'previous_url': get_previous_url(self.request),
          'POOTLE_MT_BACKENDS': settings.POOTLE_MT_BACKENDS,
          'AMAGAMA_URL': settings.AMAGAMA_URL,
          'editor_extends': self.template_extends})
     return ctx
コード例 #41
0
def _test_translate_view(language, request, response, kwargs, settings):
    ctx = response.context
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = language.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    view_context_test(
        ctx,
        **dict(
            project=None,
            language=language,
            page="translate",
            ctx_path=language.directory.pootle_path,
            pootle_path=language.directory.pootle_path,
            resource_path="",
            resource_path_parts=[],
            editor_extends="languages/base.html",
            checks=_checks,
            previous_url=get_previous_url(request),
            display_priority=False,
            has_admin_access=check_permission('administrate', request),
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #42
0
ファイル: helpers.py プロジェクト: cedk/pootle
def get_translation_context(request, is_terminology=False):
    """Returns a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    :param is_terminology: boolean indicating if the translation context
        is relevant to a terminology project.
    """
    resource_path = getattr(request, 'resource_path', '')
    vfolder_pk = getattr(request, 'current_vfolder', '')
    display_priority = False

    if not vfolder_pk:
        display_priority = VirtualFolder.objects.filter(
            units__store__pootle_path__startswith=request.pootle_path
        ).exists()

    return {
        'page': 'translate',

        'cantranslate': check_permission("translate", request),
        'cansuggest': check_permission("suggest", request),
        'canreview': check_permission("review", request),
        'is_admin': check_permission('administrate', request),
        'profile': request.profile,

        'pootle_path': request.pootle_path,
        'ctx_path': request.ctx_path,
        'current_vfolder_pk': vfolder_pk,
        'display_priority': display_priority,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'check_categories': get_qualitycheck_schema(),

        'search_form': make_search_form(request=request,
                                        terminology=is_terminology),

        'previous_url': get_previous_url(request),

        'POOTLE_MT_BACKENDS': settings.POOTLE_MT_BACKENDS,
        'AMAGAMA_URL': settings.AMAGAMA_URL,
    }
コード例 #43
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                "code": cat,
                "name": get_category_code(cat),
                "title": get_category_name(cat),
                "checks": [],
            }
        d[cat]["checks"].append(
            {"code": check, "title": u"%s" % check_names.get(check, check)}
        )
        d[cat]["checks"] = sorted(d[cat]["checks"], key=lambda x: x["code"])

    result = sorted(
        [item for item in d.values()], key=lambda x: x["code"], reverse=True
    )

    assert result == get_qualitycheck_schema()
コード例 #44
0
ファイル: project.py プロジェクト: haf/pootle
def test_view_projects_browse(site_permissions, site_matrix_with_vfolders,
                              site_matrix_with_announcements,
                              client, nobody, default):
    response = client.get(reverse("pootle-projects-browse"))
    assert response.cookies["pootle-language"].value == "projects"
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (
        Project.objects.for_user(request.user)
                       .filter(code__in=user_projects))
    ob = ProjectSet(user_projects)
    items = [
        make_project_list_item(project)
        for project in ob.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    table_fields = [
        'name', 'progress', 'total', 'need-translation',
        'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'projects',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items}
    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=ob,
        table=table,
        browser_extends="projects/all/base.html",
        stats=jsonify(ob.get_stats()),
        check_categories=get_qualitycheck_schema(ob),
        translation_states=get_translation_states(ob),
        url_action_continue=ob.get_translate_url(state='incomplete'),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state='suggestions'),
        url_action_view_all=ob.get_translate_url(state='all'))
    view_context_test(ctx, **assertions)
コード例 #45
0
ファイル: project.py プロジェクト: gitter-badger/pootle
def test_view_projects_browse(
    site_permissions, site_matrix_with_vfolders, site_matrix_with_announcements, client, nobody, default
):
    response = client.get(reverse("pootle-projects-browse"))
    assert response.cookies["pootle-language"].value == "projects"
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = Project.objects.for_user(request.user).filter(code__in=user_projects)
    ob = ProjectSet(user_projects)
    items = [make_project_list_item(project) for project in ob.children]
    items.sort(lambda x, y: locale.strcoll(x["title"], y["title"]))
    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]
    table = {"id": "projects", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items}
    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        resource_obj=ob,
        table=table,
        browser_extends="projects/all/base.html",
        stats=jsonify(ob.get_stats()),
        check_categories=get_qualitycheck_schema(ob),
        translation_states=get_translation_states(ob),
        url_action_continue=ob.get_translate_url(state="incomplete"),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state="suggestions"),
        url_action_view_all=ob.get_translate_url(state="all"),
    )
    view_context_test(ctx, **assertions)
コード例 #46
0
ファイル: helpers.py プロジェクト: JohnnyKing94/pootle
def get_browser_context(request):
    """Returns a common context for browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    filters = {}

    if ((isinstance(resource_obj, Directory) and
         resource_obj.has_vfolders) or
        (isinstance(resource_obj, TranslationProject) and
         resource_obj.directory.has_vfolders)):
        filters['sort'] = 'priority'

    url_action_continue = resource_obj.get_translate_url(state='incomplete',
                                                         **filters)
    url_action_fixcritical = resource_obj.get_critical_url(**filters)
    url_action_review = resource_obj.get_translate_url(state='suggestions',
                                                       **filters)
    url_action_view_all = resource_obj.get_translate_url(state='all')

    return {
        'page': 'browse',

        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),

        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
    }
コード例 #47
0
ファイル: checks.py プロジェクト: ratanasoth/zing
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
        })
        d[cat]['checks'] = sorted(d[cat]['checks'], key=lambda x: x['code'])

    result = sorted([item for item in d.values()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
コード例 #48
0
ファイル: checks.py プロジェクト: yar0d/pootle
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
            'url': ''
        })

    result = sorted([item for code, item in d.items()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
コード例 #49
0
ファイル: helpers.py プロジェクト: alain-andre/pootle
def get_translation_context(request, is_terminology=False):
    """Return a common context for translation views.

    :param request: a :cls:`django.http.HttpRequest` object.
    :param is_terminology: boolean indicating if the translation context
        is relevant to a terminology project.
    """
    resource_path = getattr(request, 'resource_path', '')

    user = request.user
    if not user.is_authenticated():
        user = User.objects.get_nobody_user()

    return {
        'page': 'translate',

        'cantranslate': check_permission("translate", request),
        'cansuggest': check_permission("suggest", request),
        'canreview': check_permission("review", request),
        'is_admin': check_permission('administrate', request),

        'pootle_path': request.pootle_path,
        'ctx_path': request.ctx_path,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'check_categories': get_qualitycheck_schema(),

        'unit_rows': user.unit_rows,

        'search_form': make_search_form(request=request,
                                        terminology=is_terminology),

        'previous_url': get_previous_url(request),

        'MT_BACKENDS': settings.MT_BACKENDS,
        'LOOKUP_BACKENDS': settings.LOOKUP_BACKENDS,
        'AMAGAMA_URL': settings.AMAGAMA_URL,
    }
コード例 #50
0
ファイル: language.py プロジェクト: nathan-lewis/pootle
def _test_translate_view(language, request, response, kwargs, settings):
    ctx = response.context
    view_context_test(
        ctx,
        **dict(project=None,
               language=language,
               page="translate",
               ctx_path=language.directory.pootle_path,
               pootle_path=language.directory.pootle_path,
               resource_path="",
               resource_path_parts=[],
               editor_extends="languages/base.html",
               check_categories=get_qualitycheck_schema(),
               previous_url=get_previous_url(request),
               display_priority=False,
               is_admin=check_permission('administrate', request),
               cantranslate=check_permission("translate", request),
               cansuggest=check_permission("suggest", request),
               canreview=check_permission("review", request),
               search_form=make_search_form(request=request),
               current_vfolder_pk="",
               POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
               AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #51
0
ファイル: helpers.py プロジェクト: Robens/pootle
def get_overview_context(request):
    """Returns a common context for overview browser pages.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    resource_obj = request.resource_obj
    resource_path = getattr(request, 'resource_path', '')

    filters = {}

    if (not isinstance(resource_obj, Store) and
        VirtualFolder.get_matching_for(request.pootle_path).count()):
        filters['sort'] = 'priority'

    url_action_continue = resource_obj.get_translate_url(state='incomplete',
                                                         **filters)
    url_action_fixcritical = resource_obj.get_critical_url(**filters)
    url_action_review = resource_obj.get_translate_url(state='suggestions',
                                                       **filters)
    url_action_view_all = resource_obj.get_translate_url(state='all')

    return {
        'page': 'overview',

        'pootle_path': request.pootle_path,
        'resource_obj': resource_obj,
        'resource_path': resource_path,
        'resource_path_parts': get_path_parts(resource_path),

        'translation_states': get_translation_states(resource_obj),
        'check_categories': get_qualitycheck_schema(resource_obj),

        'url_action_continue': url_action_continue,
        'url_action_fixcritical': url_action_fixcritical,
        'url_action_review': url_action_review,
        'url_action_view_all': url_action_view_all,
    }
コード例 #52
0
ファイル: tp.py プロジェクト: ryuzaki95/pootle
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)
    vfolder, pootle_path = extract_vfolder_from_path(request_path)
    current_vfolder_pk = (
        vfolder.pk
        if vfolder
        else "")
    display_priority = (
        not current_vfolder_pk
        and not kwargs['filename'] and ctx['object'].has_vfolders)
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        check_categories=get_qualitycheck_schema(),
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
コード例 #53
0
ファイル: project.py プロジェクト: phlax/pootle
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = (
        "/projects/%(project_code)s/" % kwargs)
    resource_path = (
        "%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False
    view_context_test(
        ctx,
        **dict(
            page="translate",
            has_admin_access=request.user.is_superuser,
            language=None,
            project=project,
            pootle_path=pootle_path,
            ctx_path=ctx_path,
            resource_path=resource_path,
            resource_path_parts=get_path_parts(resource_path),
            editor_extends="projects/base.html",
            check_categories=get_qualitycheck_schema(),
            previous_url=get_previous_url(request),
            display_priority=display_priority,
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
コード例 #54
0
ファイル: tp.py プロジェクト: ryuzaki95/pootle
def _test_browse_view(tp, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % tp.project.code in cookie_data
    assert "announcements_%s" % tp.language.code in cookie_data
    assert (
        "announcements_%s_%s"
        % (tp.language.code, tp.project.code)
        in cookie_data)
    ctx = response.context
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    pootle_path = "%s%s" % (tp.pootle_path, resource_path)

    if not (kwargs["dir_path"] or kwargs.get("filename")):
        ob = tp.directory
    elif not kwargs.get("filename"):
        ob = Directory.objects.get(
            pootle_path=pootle_path)
    else:
        ob = Store.objects.get(
            pootle_path=pootle_path)
    if not kwargs.get("filename"):
        vftis = ob.vf_treeitems.select_related("vfolder")
        if not ctx["has_admin_access"]:
            vftis = vftis.filter(vfolder__is_public=True)
        vfolders = [
            make_vfolder_treeitem_dict(vfolder_treeitem)
            for vfolder_treeitem
            in vftis.order_by('-vfolder__priority')
            if (ctx["has_admin_access"]
                or vfolder_treeitem.is_visible)]
        stats = {"vfolders": {}}
        for vfolder_treeitem in vfolders or []:
            stats['vfolders'][
                vfolder_treeitem['code']] = vfolder_treeitem["stats"]
            del vfolder_treeitem["stats"]
        if stats["vfolders"]:
            stats.update(ob.get_stats())
        else:
            stats = ob.get_stats()
        stats = jsonify(stats)
    else:
        stats = jsonify(ob.get_stats())
        vfolders = None

    filters = {}
    if vfolders:
        filters['sort'] = 'priority'

    dirs_with_vfolders = vftis_for_child_dirs(ob).values_list(
        "directory__pk", flat=True)
    directories = [
        make_directory_item(
            child,
            **(dict(sort="priority")
               if child.pk in dirs_with_vfolders
               else {}))
        for child in ob.get_children()
        if isinstance(child, Directory)]
    stores = [
        make_store_item(child)
        for child in ob.get_children()
        if isinstance(child, Store)]

    if not kwargs.get("filename"):
        table_fields = [
            'name', 'progress', 'total', 'need-translation',
            'suggestions', 'critical', 'last-updated', 'activity']
        table = {
            'id': 'tp',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': directories + stores}
    else:
        table = None

    assertions = dict(
        page="browse",
        object=ob,
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        is_store=(kwargs.get("filename") and True or False),
        browser_extends="translation_projects/base.html",
        pootle_path=pootle_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        url_action_continue=ob.get_translate_url(
            state='incomplete', **filters),
        url_action_fixcritical=ob.get_critical_url(**filters),
        url_action_review=ob.get_translate_url(
            state='suggestions', **filters),
        url_action_view_all=ob.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(ob))
    if table:
        assertions["table"] = table
    sidebar = get_sidebar_announcements_context(
        request, (tp.project, tp.language, tp))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
    if vfolders:
        for vfolder in ctx["vfolders"]["items"]:
            assert (vfolder["is_grayed"] and not ctx["has_admin_access"]) is False
        assert (
            ctx["vfolders"]["items"]
            == vfolders)

    assert (('display_download' in ctx and ctx['display_download']) ==
            (request.user.is_authenticated()
             and check_permission('translate', request)))
コード例 #55
0
ファイル: tp.py プロジェクト: Cedric31/pootle
def _test_browse_view(tp, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % tp.project.code in cookie_data
    assert "announcements_%s" % tp.language.code in cookie_data
    assert ("announcements_%s_%s" % (tp.language.code, tp.project.code)
            in cookie_data)
    ctx = response.context
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    pootle_path = "%s%s" % (tp.pootle_path, resource_path)

    if not (kwargs["dir_path"] or kwargs.get("filename")):
        ob = tp.directory
    elif not kwargs.get("filename"):
        ob = Directory.objects.get(pootle_path=pootle_path)
    else:
        ob = Store.objects.get(pootle_path=pootle_path)
    if not kwargs.get("filename"):
        vftis = ob.vf_treeitems.select_related("vfolder")
        if not ctx["is_admin"]:
            vftis = vftis.filter(vfolder__is_public=True)
        vfolders = [
            make_vfolder_treeitem_dict(vfolder_treeitem)
            for vfolder_treeitem in vftis.order_by('-vfolder__priority')
            if (ctx["is_admin"] or vfolder_treeitem.is_visible)
        ]
        stats = {"vfolders": {}}
        for vfolder_treeitem in vfolders or []:
            stats['vfolders'][
                vfolder_treeitem['code']] = vfolder_treeitem["stats"]
            del vfolder_treeitem["stats"]
        if stats["vfolders"]:
            stats.update(ob.get_stats())
        else:
            stats = ob.get_stats()
        stats = jsonify(stats)
    else:
        stats = jsonify(ob.get_stats())
        vfolders = None

    filters = {}
    if vfolders:
        filters['sort'] = 'priority'

    dirs_with_vfolders = vftis_for_child_dirs(ob).values_list("directory__pk",
                                                              flat=True)
    directories = [
        make_directory_item(
            child,
            **(dict(
                sort="priority") if child.pk in dirs_with_vfolders else {}))
        for child in ob.get_children() if isinstance(child, Directory)
    ]
    stores = [
        make_store_item(child) for child in ob.get_children()
        if isinstance(child, Store)
    ]

    if not kwargs.get("filename"):
        table_fields = [
            'name', 'progress', 'total', 'need-translation', 'suggestions',
            'critical', 'last-updated', 'activity'
        ]
        table = {
            'id': 'tp',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': directories + stores
        }
    else:
        table = None

    assertions = dict(
        page="browse",
        object=ob,
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        is_admin=check_permission('administrate', request),
        is_store=(kwargs.get("filename") and True or False),
        browser_extends="translation_projects/base.html",
        pootle_path=pootle_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        url_action_continue=ob.get_translate_url(state='incomplete',
                                                 **filters),
        url_action_fixcritical=ob.get_critical_url(**filters),
        url_action_review=ob.get_translate_url(state='suggestions', **filters),
        url_action_view_all=ob.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(ob))
    if table:
        assertions["table"] = table
    sidebar = get_sidebar_announcements_context(request,
                                                (tp.project, tp.language, tp))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
    if vfolders:
        for vfolder in ctx["vfolders"]["items"]:
            assert (vfolder["is_grayed"] and not ctx["is_admin"]) is False
        assert (ctx["vfolders"]["items"] == vfolders)

    assert (('display_download' in ctx
             and ctx['display_download']) == (request.user.is_authenticated()
                                              and check_permission(
                                                  'translate', request)))
コード例 #56
0
ファイル: vf.py プロジェクト: rmoch/pootle
def _test_vf_translate_view(tp, request, response, kwargs, settings):
    from .tp import view_context_test

    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    vfolder_pk = response.context["current_vfolder_pk"]
    check_data = DirectoryVFDataTool(obj).get_checks(
        user=request.user).get(vfolder_pk, {})
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    vfolder = VirtualFolder.objects.get(
        name=request.resolver_match.kwargs["vfolder_name"])
    current_vfolder_pk = vfolder.pk
    display_priority = False
    unit_api_root = reverse(
        "vfolder-pootle-xhr-units",
        kwargs=dict(vfolder_name=vfolder.name))
    resource_path = (
        "/".join(
            ["++vfolder",
             vfolder.name,
             ctx['object'].pootle_path.replace(tp.pootle_path, "")]))
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        unit_api_root=unit_api_root,
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)