Ejemplo n.º 1
0
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Ejemplo n.º 2
0
def browse(request, language):
    user_tps = language.get_children_for_user(request.user)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_browser_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
        },
        'table': {
            'id': 'language',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'stats':
        jsonify(request.resource_obj.get_stats_for_user(request.user)),
        'browser_extends':
        'languages/base.html',
    })

    response = render(request, 'browser/index.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Ejemplo n.º 3
0
def browse(request, language):
    user_tps = language.get_children_for_user(request.user)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_browser_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
        },
        'table': {
            'id': 'language',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'stats': jsonify(request.resource_obj.get_stats_for_user(request.user)),

        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/index.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Ejemplo n.º 4
0
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Ejemplo n.º 5
0
 def object_children(self):
     items = [
         make_project_item(tp)
         for tp in self.object.get_children_for_user(self.request.user)
     ]
     items = self.add_child_stats(items)
     items.sort(cmp_by_last_activity)
     return items
Ejemplo n.º 6
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.º 7
0
def _test_view_language_children(view, obj):
    request = view.request

    user_tps = obj.get_children_for_user(request.user)
    stats = obj.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"]]
    stats = StatsDisplay(obj, stats=stats).stats
    assert stats == view.stats
    assert view.object_children == items
Ejemplo n.º 8
0
def _test_view_language_children(view, obj):
    request = view.request

    user_tps = obj.get_children_for_user(request.user)
    stats = obj.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"]]
    items.sort(cmp_by_last_activity)
    stats = StatsDisplay(obj, stats=stats).stats
    assert stats == view.stats
    assert view.object_children == items
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_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.º 11
0
def overview(request, language):
    can_edit = check_permission("administrate", request)

    translation_projects = language.get_children().order_by("project__fullname")
    user_tps = filter(lambda x: x.is_accessible_by(request.user), translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_overview_context(request)
    ctx.update(
        {
            "language": {
                "code": language.code,
                "name": tr_lang(language.fullname),
                "description": language.description,
            },
            "feed_path": "%s/" % language.code,
            "can_edit": can_edit,
            "table": table,
            "browser_extends": "languages/base.html",
        }
    )

    if can_edit:
        from pootle_language.forms import DescriptionForm

        ctx.update(
            {
                "form": DescriptionForm(instance=language),
                "form_action": reverse("pootle-language-admin-settings", args=[language.code]),
            }
        )

    response = render_to_response("browser/overview.html", ctx, context_instance=RequestContext(request))
    response.set_cookie("pootle-language", language.code)

    return response
Ejemplo n.º 12
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
            'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,
        'browser_extends': 'languages/base.html',
        'browser_body_id': 'languageoverview',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form':
            DescriptionForm(instance=language),
            'form_action':
            reverse('pootle-language-admin-settings', args=[language.code]),
        })

    return render_to_response("browser/overview.html",
                              ctx,
                              context_instance=RequestContext(request))
Ejemplo n.º 13
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.º 14
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

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

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,

        'browser_extends': 'languages/base.html',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form': DescriptionForm(instance=language),
            'form_action': reverse('pootle-language-admin-settings',
                                   args=[language.code]),
        })

    response = render(request, "browser/overview.html", ctx)
    response.set_cookie('pootle-language', language.code)

    return response
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 object_children(self):
     return self.add_child_stats(
         [make_project_item(tp)
          for tp in self.object.get_children_for_user(self.request.user)])
Ejemplo n.º 17
0
 def items(self):
     return [
         make_project_item(tp)
         for tp in self.object.get_children_for_user(self.request.user)
     ]
Ejemplo n.º 18
0
 def items(self):
     return [
         make_project_item(tp)
         for tp in self.object.get_children_for_user(self.request.user)
     ]
Ejemplo n.º 19
0
Archivo: views.py Proyecto: arky/pootle
 def object_children(self):
     items = [make_project_item(tp)
              for tp in self.object.get_children_for_user(self.request.user)]
     items = self.add_child_stats(items)
     items.sort(cmp_by_last_activity)
     return items