Exemplo n.º 1
0
 def vfolders(self):
     vftis = self.object.vf_treeitems
     if not self.is_admin:
         vftis = vftis.filter(vfolder__is_public=True)
     return [
         make_vfolder_treeitem_dict(vfolder_treeitem) for vfolder_treeitem
         in vftis.order_by('-vfolder__priority').select_related("vfolder")
         if (self.is_admin or vfolder_treeitem.is_visible)
     ]
Exemplo n.º 2
0
 def vfolders(self):
     vftis = self.object.vf_treeitems
     if not self.is_admin:
         vftis = vftis.filter(vfolder__is_public=True)
     return [
         make_vfolder_treeitem_dict(vfolder_treeitem)
         for vfolder_treeitem
         in vftis.order_by('-vfolder__priority').select_related("vfolder")
         if (self.is_admin
             or vfolder_treeitem.is_visible)]
Exemplo n.º 3
0
 def vfolders(self):
     from virtualfolder.helpers import make_vfolder_treeitem_dict
     vftis = self.object.vf_treeitems
     if not self.has_admin_access:
         vftis = vftis.filter(vfolder__is_public=True)
     return [
         make_vfolder_treeitem_dict(vfolder_treeitem) for vfolder_treeitem
         in vftis.order_by('-vfolder__priority').select_related("vfolder")
         if (self.has_admin_access or vfolder_treeitem.is_visible)
     ]
Exemplo n.º 4
0
 def vfolders(self):
     from virtualfolder.helpers import make_vfolder_treeitem_dict
     vftis = self.object.vf_treeitems
     if not self.has_admin_access:
         vftis = vftis.filter(vfolder__is_public=True)
     return [
         make_vfolder_treeitem_dict(vfolder_treeitem)
         for vfolder_treeitem
         in vftis.order_by('-vfolder__priority').select_related("vfolder")
         if (self.has_admin_access
             or vfolder_treeitem.is_visible)]
Exemplo n.º 5
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)))
Exemplo n.º 6
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)))
Exemplo n.º 7
0
Arquivo: tp.py Projeto: haf/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=False,
        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"] is False
        assert ctx["vfolders"]["items"] == vfolders