Ejemplo n.º 1
0
    def get_context_data(self, *args, **kwargs):
        filters = {}
        can_translate = False
        can_translate_stats = False
        User = get_user_model()
        if self.has_vfolders:
            filters['sort'] = 'priority'

        if self.request.user.is_superuser or self.language:
            can_translate = True
            can_translate_stats = True
            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')
        else:
            if self.project:
                can_translate = True
            url_action_continue = None
            url_action_fixcritical = None
            url_action_review = None
            url_action_view_all = None
        ctx, cookie_data_ = self.sidebar_announcements
        ctx.update(super(PootleBrowseView, self).get_context_data(*args, **kwargs))

        lang_code, proj_code = split_pootle_path(self.pootle_path)[:2]
        top_scorers = User.top_scorers(
            project=proj_code,
            language=lang_code,
            limit=TOP_CONTRIBUTORS_CHUNK_SIZE + 1,
        )

        ctx.update(
            {'page': 'browse',
             'stats_refresh_attempts_count':
                 settings.POOTLE_STATS_REFRESH_ATTEMPTS_COUNT,
             'stats': self.stats,
             'translation_states': get_translation_states(self.object),
             'checks': get_qualitycheck_list(self.object),
             'can_translate': can_translate,
             'can_translate_stats': can_translate_stats,
             '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,
             'top_scorers': top_scorers,
             'top_scorers_data': get_top_scorers_data(
                 top_scorers,
                 TOP_CONTRIBUTORS_CHUNK_SIZE),
             'browser_extends': self.template_extends})

        return ctx
Ejemplo n.º 2
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))
    obj = ProjectSet(user_projects)
    items = [make_project_list_item(project) for project in obj.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    stats = obj.data_tool.get_stats(user=request.user)
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    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 = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue, url_action_fixcritical, url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    User = get_user_model()
    top_scorers = User.top_scorers(limit=10)
    assertions = dict(page="browse",
                      pootle_path="/projects/",
                      resource_path="",
                      resource_path_parts=[],
                      object=obj,
                      table=table,
                      browser_extends="projects/all/base.html",
                      top_scorers=top_scorers,
                      top_scorers_data=get_top_scorers_data(top_scorers, 10),
                      translation_states=get_translation_states(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,
                      checks=checks,
                      stats=stats)
    view_context_test(ctx, **assertions)
Ejemplo n.º 3
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))
    obj = ProjectSet(user_projects)
    items = [
        make_project_list_item(project)
        for project in obj.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 = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4

    User = get_user_model()
    top_scorers = User.top_scorers(limit=10)
    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=obj,
        table=table,
        browser_extends="projects/all/base.html",
        stats=obj.data_tool.get_stats(user=request.user),
        checks=get_qualitycheck_list(obj),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        translation_states=get_translation_states(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)
    view_context_test(ctx, **assertions)
Ejemplo n.º 4
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))
    obj = ProjectSet(user_projects)
    stats = obj.data_tool.get_stats(user=request.user)

    if request.user.is_superuser:
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
    score_data = scores.get(ProjectSet)(obj)

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score
    top_scorers = score_data.display(
        limit=chunk_size,
        formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=obj,
        browser_extends="projects/all/base.html",
        top_scorers=top_scorer_data,
        translation_states=get_translation_states(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,
        checks=checks,
        stats=stats)
    view_context_test(ctx, **assertions)
Ejemplo n.º 5
0
def _test_browse_view(language, request, response, kwargs):
    assert (response.cookies["pootle-language"].value == language.code)
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_%s" % language.code in cookie_data
    ctx = response.context
    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    user_tps = language.get_children_for_user(request.user)
    stats = language.data_tool.get_stats(user=request.user)
    items = [make_project_item(tp) for tp in user_tps]
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items
    }
    checks = ChecksDisplay(language).checks_by_category
    stats = StatsDisplay(language, stats=stats).stats
    del stats["children"]
    top_scorers = get_user_model().top_scorers(language=language.code,
                                               limit=10)
    assertions = dict(
        page="browse",
        object=language,
        language={
            'code': language.code,
            'name': language.name
        },
        browser_extends="languages/base.html",
        pootle_path="/%s/" % language.code,
        resource_path="",
        resource_path_parts=[],
        url_action_continue=language.get_translate_url(state='incomplete'),
        url_action_fixcritical=language.get_critical_url(),
        url_action_review=language.get_translate_url(state='suggestions'),
        url_action_view_all=language.get_translate_url(state='all'),
        # check_categories=get_qualitycheck_schema(language),
        table=table,
        translation_states=get_translation_states(language),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        checks=checks,
        stats=stats)
    sidebar = get_sidebar_announcements_context(request, (language, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 6
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))
    obj = ProjectSet(user_projects)
    stats = obj.data_tool.get_stats(user=request.user)

    if request.user.is_superuser:
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue, url_action_fixcritical, url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
    score_data = scores.get(ProjectSet)(obj)

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score

    top_scorers = score_data.display(limit=chunk_size,
                                     formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(page="browse",
                      pootle_path="/projects/",
                      resource_path="",
                      resource_path_parts=[],
                      object=obj,
                      browser_extends="projects/all/base.html",
                      top_scorers=top_scorer_data,
                      translation_states=get_translation_states(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,
                      checks=checks,
                      stats=stats)
    view_context_test(ctx, **assertions)
Ejemplo n.º 7
0
 def states(self):
     states = get_translation_states(self.object)
     stats = self.stats
     for state in states:
         if state["state"] == "untranslated":
             if stats["total"]:
                 stats[state["state"]] = state["count"] = (
                     stats["total"] - stats["fuzzy"] - stats["translated"])
         else:
             stats[state["state"]] = state["count"] = stats[state["state"]]
         if state.get("count"):
             state["percent"] = round(
                 (float(state["count"]) / stats["total"]) * 100, 1)
     return states
Ejemplo n.º 8
0
def _test_browse_view(language, request, response, kwargs):
    assert response.cookies["pootle-language"].value == language.code
    assert (request.user.is_anonymous
            or "announcements/%s" % language.code in request.session)
    ctx = response.context
    user_tps = language.get_children_for_user(request.user)
    stats = language.data_tool.get_stats(user=request.user)
    items = [make_project_item(tp) for tp in user_tps]
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    checks = ChecksDisplay(language).checks_by_category
    stats = StatsDisplay(language, stats=stats).stats
    del stats["children"]
    score_data = scores.get(language.__class__)(language)
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score

    top_scorers = score_data.display(limit=chunk_size,
                                     formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(
        page="browse",
        object=language,
        language={
            'code': language.code,
            'name': language.name
        },
        browser_extends="languages/base.html",
        pootle_path="/%s/" % language.code,
        resource_path="",
        resource_path_parts=[],
        url_action_continue=language.get_translate_url(state='incomplete'),
        url_action_fixcritical=language.get_critical_url(),
        url_action_review=language.get_translate_url(state='suggestions'),
        url_action_view_all=language.get_translate_url(state='all'),
        # check_categories=get_qualitycheck_schema(language),
        translation_states=get_translation_states(language),
        top_scorers=top_scorer_data,
        checks=checks,
        stats=stats)
    sidebar = get_sidebar_announcements_context(request, (language, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 9
0
def _test_browse_view(language, request, response, kwargs):
    assert response.cookies["pootle-language"].value == language.code
    assert (request.user.is_anonymous
            or "announcements/%s" % language.code in request.session)
    ctx = response.context
    user_tps = language.get_children_for_user(request.user)
    stats = language.data_tool.get_stats(user=request.user)
    items = [make_project_item(tp) for tp in user_tps]
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    checks = ChecksDisplay(language).checks_by_category
    stats = StatsDisplay(language, stats=stats).stats
    del stats["children"]
    score_data = scores.get(language.__class__)(language)
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score
    top_scorers = score_data.display(
        limit=chunk_size,
        formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(
        page="browse",
        object=language,
        language={
            'code': language.code,
            'name': language.name},
        browser_extends="languages/base.html",
        pootle_path="/%s/" % language.code,
        resource_path="",
        resource_path_parts=[],
        url_action_continue=language.get_translate_url(state='incomplete'),
        url_action_fixcritical=language.get_critical_url(),
        url_action_review=language.get_translate_url(state='suggestions'),
        url_action_view_all=language.get_translate_url(state='all'),
        # check_categories=get_qualitycheck_schema(language),
        translation_states=get_translation_states(language),
        top_scorers=top_scorer_data,
        checks=checks,
        stats=stats)
    sidebar = get_sidebar_announcements_context(request, (language, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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))
    obj = ProjectSet(user_projects)
    stats = obj.data_tool.get_stats(user=request.user)

    if request.user.is_superuser:
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    User = get_user_model()
    top_scorers = User.top_scorers(limit=10)
    assertions = dict(
        page="browse",
        pootle_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        object=obj,
        browser_extends="projects/all/base.html",
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        translation_states=get_translation_states(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,
        checks=checks,
        stats=stats)
    view_context_test(ctx, **assertions)
Ejemplo n.º 12
0
 def states(self):
     states = get_translation_states(self.object)
     stats = self.stats
     for state in states:
         if state["state"] == "untranslated":
             if stats["total"]:
                 stats[state["state"]] = state["count"] = (
                     stats["total"] - stats["fuzzy"] - stats["translated"])
         else:
             stats[state["state"]] = state["count"] = stats[state["state"]]
         if state.get("count"):
             state["count_display"] = formatter.number(state["count"])
             state["percent"] = round(
                 float(state["count"]) / stats["total"], 3)
             state["percent_display"] = formatter.percent(
                 state["percent"], "#,##0.0%")
     return states
Ejemplo n.º 13
0
 def states(self):
     states = get_translation_states(self.object)
     stats = self.stats
     for state in states:
         if state["state"] == "untranslated":
             if stats["total"]:
                 stats[state["state"]] = state["count"] = (
                     stats["total"] - stats["fuzzy"] - stats["translated"])
         else:
             stats[state["state"]] = state["count"] = stats[state["state"]]
         if state.get("count"):
             state["count_display"] = formatter.number(state["count"])
             state["percent"] = round(
                 float(state["count"]) / stats["total"], 3)
             state["percent_display"] = formatter.percent(
                 state["percent"], "#,##0.0%")
     return states
Ejemplo n.º 14
0
def _test_browse_view(language, request, response, kwargs):
    assert (
        response.cookies["pootle-language"].value == language.code)
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_%s" % language.code in cookie_data
    ctx = response.context
    table_fields = [
        'name', 'progress', 'total', 'need-translation',
        'suggestions', 'critical', 'last-updated', 'activity']
    user_tps = language.get_children_for_user(request.user)
    items = [make_project_item(tp) for tp in user_tps]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items}
    top_scorers = get_user_model().top_scorers(language=language.code, limit=10)
    assertions = dict(
        page="browse",
        object=language,
        language={
            'code': language.code,
            'name': language.name},
        browser_extends="languages/base.html",
        pootle_path="/%s/" % language.code,
        resource_path="",
        resource_path_parts=[],
        url_action_continue=language.get_translate_url(state='incomplete'),
        url_action_fixcritical=language.get_critical_url(),
        url_action_review=language.get_translate_url(state='suggestions'),
        url_action_view_all=language.get_translate_url(state='all'),
        # check_categories=get_qualitycheck_schema(language),
        table=table,
        translation_states=get_translation_states(language),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        stats=language.data_tool.get_stats(user=request.user)
    )
    sidebar = get_sidebar_announcements_context(
        request, (language, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 15
0
def _test_browse_view(language, request, response, kwargs):
    assert (
        response.cookies["pootle-language"].value == language.code)
    if SIDEBAR_COOKIE_NAME in response.cookies:
        cookie_data = json.loads(
            unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
        assert cookie_data["foo"] == "bar"
    assert "announcements/%s" % language.code in request.session
    ctx = response.context
    user_tps = language.get_children_for_user(request.user)
    stats = language.data_tool.get_stats(user=request.user)
    items = [make_project_item(tp) for tp in user_tps]
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    checks = ChecksDisplay(language).checks_by_category
    stats = StatsDisplay(language, stats=stats).stats
    del stats["children"]
    top_scorers = get_user_model().top_scorers(language=language.code, limit=10)
    assertions = dict(
        page="browse",
        object=language,
        language={
            'code': language.code,
            'name': language.name},
        browser_extends="languages/base.html",
        pootle_path="/%s/" % language.code,
        resource_path="",
        resource_path_parts=[],
        url_action_continue=language.get_translate_url(state='incomplete'),
        url_action_fixcritical=language.get_critical_url(),
        url_action_review=language.get_translate_url(state='suggestions'),
        url_action_view_all=language.get_translate_url(state='all'),
        # check_categories=get_qualitycheck_schema(language),
        translation_states=get_translation_states(language),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        checks=checks,
        stats=stats)
    sidebar = get_sidebar_announcements_context(
        request, (language, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 16
0
def _test_browse_view(project, request, response, kwargs):
    assert (request.user.is_anonymous
            or "announcements/projects/%s" % project.code in request.session)
    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"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(
            Directory.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(
            Store.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)

    stats = obj.data_tool.get_stats(user=request.user)

    if request.user.is_superuser or kwargs.get("language_code"):
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    User = get_user_model()
    top_scorers = User.top_scorers(project=project.code, limit=10)
    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=url_action_continue,
        url_action_fixcritical=url_action_fixcritical,
        url_action_review=url_action_review,
        url_action_view_all=url_action_view_all,
        translation_states=get_translation_states(obj),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        checks=checks,
        stats=stats)
    sidebar = get_sidebar_announcements_context(
        request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 17
0
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"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(
            Directory.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)
    else:
        obj = 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 obj.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}

    if request.user.is_superuser or kwargs.get("language_code"):
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4

    User = get_user_model()
    top_scorers = User.top_scorers(project=project.code, limit=10)
    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=url_action_continue,
        url_action_fixcritical=url_action_fixcritical,
        url_action_review=url_action_review,
        url_action_view_all=url_action_view_all,
        translation_states=get_translation_states(obj),
        checks=get_qualitycheck_list(obj),
        table=table,
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        stats=obj.data_tool.get_stats(user=request.user),
    )
    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)
Ejemplo n.º 18
0
def _test_browse_view(tp, request, response, kwargs):
    if SIDEBAR_COOKIE_NAME in response.cookies:
        cookie_data = json.loads(
            unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
        assert cookie_data["foo"] == "bar"
    assert "announcements/projects/%s" % tp.project.code in request.session
    assert "announcements/%s" % tp.language.code in request.session
    assert (
        "announcements/%s/%s"
        % (tp.language.code, tp.project.code)
        in request.session)
    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")):
        obj = tp.directory
    elif not kwargs.get("filename"):
        obj = Directory.objects.get(
            pootle_path=pootle_path)
    else:
        obj = Store.objects.get(
            pootle_path=pootle_path)
    if obj.tp_path == "/":
        data_obj = obj.tp
    else:
        data_obj = obj
    stats = StatsDisplay(
        data_obj,
        stats=data_obj.data_tool.get_stats(user=request.user)).stats
    if not kwargs.get("filename"):
        vfolders = True
    else:
        vfolders = None
    filters = {}
    if vfolders:
        filters['sort'] = 'priority'
    checks = ChecksDisplay(obj).checks_by_category
    del stats["children"]

    User = get_user_model()
    top_scorers = User.top_scorers(language=tp.language.code,
                                   project=tp.project.code, limit=11)
    assertions = dict(
        page="browse",
        object=obj,
        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(obj),
        checks=checks,
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        url_action_continue=obj.get_translate_url(
            state='incomplete', **filters),
        url_action_fixcritical=obj.get_critical_url(**filters),
        url_action_review=obj.get_translate_url(
            state='suggestions', **filters),
        url_action_view_all=obj.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(obj))
    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)
    assert (('display_download' in ctx and ctx['display_download']) ==
            (request.user.is_authenticated
             and check_permission('translate', request)))
Ejemplo n.º 19
0
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)))
Ejemplo n.º 20
0
Archivo: tp.py Proyecto: phlax/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")):
        obj = tp.directory
    elif not kwargs.get("filename"):
        obj = Directory.objects.get(
            pootle_path=pootle_path)
    else:
        obj = Store.objects.get(
            pootle_path=pootle_path)
    if not kwargs.get("filename"):
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        stats = vf_view.stats
        vfolders = stats["vfolders"]
        stats.update(obj.data_tool.get_stats(user=request.user))
    else:
        stats = obj.data_tool.get_stats(user=request.user)
        vfolders = None

    filters = {}
    if vfolders:
        filters['sort'] = 'priority'
    dirs_with_vfolders = set(
        split_pootle_path(path)[2].split("/")[0]
        for path
        in tp.stores.filter(
            vfolders__isnull=False).values_list(
            "pootle_path", flat=True))
    directories = [
        make_directory_item(
            child,
            **(dict(sort="priority")
               if child.name in dirs_with_vfolders
               else {}))
        for child in obj.get_children()
        if isinstance(child, Directory)]
    stores = [
        make_store_item(child)
        for child in obj.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

    User = get_user_model()
    top_scorers = User.top_scorers(language=tp.language.code,
                                   project=tp.project.code, limit=11)
    assertions = dict(
        page="browse",
        object=obj,
        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(obj),
        checks=get_qualitycheck_list(obj),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        url_action_continue=obj.get_translate_url(
            state='incomplete', **filters),
        url_action_fixcritical=obj.get_critical_url(**filters),
        url_action_review=obj.get_translate_url(
            state='suggestions', **filters),
        url_action_view_all=obj.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(obj))
    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"] == vf_view.table_items

    assert (('display_download' in ctx and ctx['display_download']) ==
            (request.user.is_authenticated()
             and check_permission('translate', request)))
Ejemplo n.º 21
0
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)))
Ejemplo n.º 22
0
def _test_browse_view(tp, request, response, kwargs):
    assert (request.user.is_anonymous or
            "announcements/projects/%s" % tp.project.code in request.session)
    assert (request.user.is_anonymous
            or "announcements/%s" % tp.language.code in request.session)
    assert (request.user.is_anonymous or "announcements/%s/%s" %
            (tp.language.code, tp.project.code) in request.session)
    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")):
        obj = tp.directory
    elif not kwargs.get("filename"):
        obj = Directory.objects.get(pootle_path=pootle_path)
    else:
        obj = Store.objects.get(pootle_path=pootle_path)
    if obj.tp_path == "/":
        data_obj = obj.tp
    else:
        data_obj = obj
    stats = StatsDisplay(
        data_obj, stats=data_obj.data_tool.get_stats(user=request.user)).stats
    if not kwargs.get("filename"):
        vfolders = True
    else:
        vfolders = None
    filters = {}
    if vfolders:
        filters['sort'] = 'priority'
    checks = ChecksDisplay(obj).checks_by_category
    del stats["children"]

    score_data = scores.get(tp.__class__)(tp)
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
    top_scorers = score_data.top_scorers

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score

    top_scorers = score_data.display(limit=chunk_size,
                                     formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(
        page="browse",
        object=obj,
        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(obj),
        checks=checks,
        top_scorers=top_scorer_data,
        url_action_continue=obj.get_translate_url(state='incomplete',
                                                  **filters),
        url_action_fixcritical=obj.get_critical_url(**filters),
        url_action_review=obj.get_translate_url(state='suggestions',
                                                **filters),
        url_action_view_all=obj.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(obj))
    sidebar = get_sidebar_announcements_context(request,
                                                (tp.project, tp.language, tp))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
    assert (('display_download' in ctx
             and ctx['display_download']) == (request.user.is_authenticated
                                              and check_permission(
                                                  'translate', request)))
Ejemplo n.º 23
0
Archivo: tp.py Proyecto: arky/pootle
def _test_browse_view(tp, request, response, kwargs):
    assert (request.user.is_anonymous
            or "announcements/projects/%s" % tp.project.code in request.session)
    assert (request.user.is_anonymous
            or "announcements/%s" % tp.language.code in request.session)
    assert (request.user.is_anonymous
            or "announcements/%s/%s" % (tp.language.code, tp.project.code)
            in request.session)
    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")):
        obj = tp.directory
    elif not kwargs.get("filename"):
        obj = Directory.objects.get(
            pootle_path=pootle_path)
    else:
        obj = Store.objects.get(
            pootle_path=pootle_path)
    if obj.tp_path == "/":
        data_obj = obj.tp
    else:
        data_obj = obj
    stats = StatsDisplay(
        data_obj,
        stats=data_obj.data_tool.get_stats(user=request.user)).stats
    if not kwargs.get("filename"):
        vfolders = True
    else:
        vfolders = None
    filters = {}
    if vfolders:
        filters['sort'] = 'priority'
    checks = ChecksDisplay(obj).checks_by_category
    del stats["children"]

    score_data = scores.get(tp.__class__)(tp)
    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
    top_scorers = score_data.top_scorers

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score
    top_scorers = score_data.display(
        limit=chunk_size,
        formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    assertions = dict(
        page="browse",
        object=obj,
        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(obj),
        checks=checks,
        top_scorers=top_scorer_data,
        url_action_continue=obj.get_translate_url(
            state='incomplete', **filters),
        url_action_fixcritical=obj.get_critical_url(**filters),
        url_action_review=obj.get_translate_url(
            state='suggestions', **filters),
        url_action_view_all=obj.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(obj))
    sidebar = get_sidebar_announcements_context(
        request, (tp.project, tp.language, tp))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
    assert (('display_download' in ctx and ctx['display_download']) ==
            (request.user.is_authenticated
             and check_permission('translate', request)))
Ejemplo n.º 24
0
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
    }

    if request.user.is_superuser or kwargs.get("language_code"):
        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",
                      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=url_action_continue,
                      url_action_fixcritical=url_action_fixcritical,
                      url_action_review=url_action_review,
                      url_action_view_all=url_action_view_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)
Ejemplo n.º 25
0
def _test_browse_view(project, request, response, kwargs):
    assert (request.user.is_anonymous
            or "announcements/projects/%s" % project.code in request.session)
    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"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(Directory.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(Store.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)

    stats = obj.data_tool.get_stats(user=request.user)

    if request.user.is_superuser or kwargs.get("language_code"):
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue, url_action_fixcritical, url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]

    chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
    score_data = scores.get(Project)(project)

    def scores_to_json(score):
        score["user"] = score["user"].to_dict()
        return score

    top_scorers = score_data.display(limit=chunk_size,
                                     formatter=scores_to_json)
    top_scorer_data = dict(
        items=list(top_scorers),
        has_more_items=len(score_data.top_scorers) > chunk_size)
    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=url_action_continue,
                      url_action_fixcritical=url_action_fixcritical,
                      url_action_review=url_action_review,
                      url_action_view_all=url_action_view_all,
                      translation_states=get_translation_states(obj),
                      top_scorers=top_scorer_data,
                      checks=checks,
                      stats=stats)
    sidebar = get_sidebar_announcements_context(request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 26
0
    def get_context_data(self, *args, **kwargs):
        filters = {}
        can_translate = False
        can_translate_stats = False
        User = get_user_model()
        if self.has_vfolders:
            filters['sort'] = 'priority'

        if self.request.user.is_superuser or self.language:
            can_translate = True
            can_translate_stats = True
            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')
        else:
            if self.project:
                can_translate = True
            url_action_continue = None
            url_action_fixcritical = None
            url_action_review = None
            url_action_view_all = None
        ctx, cookie_data_ = self.sidebar_announcements
        ctx.update(
            super(PootleBrowseView, self).get_context_data(*args, **kwargs))

        lang_code, proj_code = split_pootle_path(self.pootle_path)[:2]
        top_scorers = User.top_scorers(
            project=proj_code,
            language=lang_code,
            limit=TOP_CONTRIBUTORS_CHUNK_SIZE + 1,
        )

        ctx.update({
            'page':
            'browse',
            'stats_refresh_attempts_count':
            settings.POOTLE_STATS_REFRESH_ATTEMPTS_COUNT,
            'stats':
            self.stats,
            'translation_states':
            get_translation_states(self.object),
            'checks':
            get_qualitycheck_list(self.object),
            'can_translate':
            can_translate,
            'can_translate_stats':
            can_translate_stats,
            '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,
            'top_scorers':
            top_scorers,
            'top_scorers_data':
            get_top_scorers_data(top_scorers, TOP_CONTRIBUTORS_CHUNK_SIZE),
            'browser_extends':
            self.template_extends
        })

        return ctx
Ejemplo n.º 27
0
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")):
        obj = tp.directory
    elif not kwargs.get("filename"):
        obj = Directory.objects.get(pootle_path=pootle_path)
    else:
        obj = Store.objects.get(pootle_path=pootle_path)
    if not kwargs.get("filename"):
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        stats = vf_view.stats
        vfolders = stats["vfolders"]
        stats.update(obj.data_tool.get_stats(user=request.user))
    else:
        stats = obj.data_tool.get_stats(user=request.user)
        vfolders = None

    filters = {}
    if vfolders:
        filters['sort'] = 'priority'
    dirs_with_vfolders = set(
        split_pootle_path(path)[2].split("/")[0] for path in tp.stores.filter(
            vfolders__isnull=False).values_list("pootle_path", flat=True))
    directories = [
        make_directory_item(
            child,
            **(dict(
                sort="priority") if child.name in dirs_with_vfolders else {}))
        for child in obj.get_children() if isinstance(child, Directory)
    ]
    stores = [
        make_store_item(child) for child in obj.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

    User = get_user_model()
    top_scorers = User.top_scorers(language=tp.language.code,
                                   project=tp.project.code,
                                   limit=11)
    assertions = dict(
        page="browse",
        object=obj,
        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(obj),
        checks=get_qualitycheck_list(obj),
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        url_action_continue=obj.get_translate_url(state='incomplete',
                                                  **filters),
        url_action_fixcritical=obj.get_critical_url(**filters),
        url_action_review=obj.get_translate_url(state='suggestions',
                                                **filters),
        url_action_view_all=obj.get_translate_url(state='all'),
        stats=stats,
        parent=get_parent(obj))
    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"] == vf_view.table_items

    assert (('display_download' in ctx
             and ctx['display_download']) == (request.user.is_authenticated()
                                              and check_permission(
                                                  'translate', request)))