Exemple #1
0
def get_export_view_context(request):
    """Returns a common context for export views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    res = {}
    filter_name, filter_extra = get_filter_name(request.GET)

    units_qs = Unit.objects.get_for_path(request.pootle_path,
                                         request.profile)
    units = get_step_query(request, units_qs)
    unit_total_count = units.count()

    units = units.select_related('store')
    if unit_total_count > EXPORT_VIEW_QUERY_LIMIT:
        units = units[:EXPORT_VIEW_QUERY_LIMIT]
        res.update({
            'unit_total_count': unit_total_count,
            'displayed_unit_count': EXPORT_VIEW_QUERY_LIMIT,
        })

    unit_groups = [(path, list(units)) for path, units in
                   groupby(units, lambda x: x.store.pootle_path)]

    res.update({
        'unit_groups': unit_groups,
        'filter_name': filter_name,
        'filter_extra': filter_extra,
    })

    return res
Exemple #2
0
def get_export_view_context(request):
    """Returns a common context for export views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    res = {}
    filter_name, filter_extra = get_filter_name(request.GET)

    units_qs = Unit.objects.get_for_path(request.pootle_path, request.profile)
    units = get_step_query(request, units_qs)
    unit_total_count = units.count()

    units = units.select_related('store')
    if unit_total_count > EXPORT_VIEW_QUERY_LIMIT:
        units = units[:EXPORT_VIEW_QUERY_LIMIT]
        res.update({
            'unit_total_count': unit_total_count,
            'displayed_unit_count': EXPORT_VIEW_QUERY_LIMIT,
        })

    unit_groups = [
        (path, list(units))
        for path, units in groupby(units, lambda x: x.store.pootle_path)
    ]

    res.update({
        'unit_groups': unit_groups,
        'filter_name': filter_name,
        'filter_extra': filter_extra,
    })

    return res
Exemple #3
0
    def get_context_data(self, *args, **kwargs):
        ctx = {}
        filter_name, filter_extra = get_filter_name(self.request.GET)

        units_qs = Unit.objects.get_translatable(
            self.request.profile,
            **self.kwargs)

        units_qs = get_step_query(self.request, units_qs)
        unit_total_count = units_qs.count()
        units_qs = units_qs.select_related('store')
        if unit_total_count > EXPORT_VIEW_QUERY_LIMIT:
            units_qs = units_qs[:EXPORT_VIEW_QUERY_LIMIT]
            ctx.update(
                {'unit_total_count': unit_total_count,
                 'displayed_unit_count': EXPORT_VIEW_QUERY_LIMIT})

        unit_groups = [
            (path, list(units))
            for path, units
            in groupby(units_qs, lambda x: x.store.pootle_path)]

        ctx.update(
            {'unit_groups': unit_groups,
             'filter_name': filter_name,
             'filter_extra': filter_extra,
             'source_language': self.source_language,
             'language': self.language,
             'project': self.project})
        return ctx
Exemple #4
0
def _test_export_view(project, request, response, kwargs):
    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,
        )

    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_for_path(ob.pootle_path, request.profile)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related("store")
    unit_groups = [(path, list(units)) for path, units in groupby(units_qs, lambda x: x.store.pootle_path)]
    assertions = dict(
        project=project,
        language=None,
        source_language="en",
        filter_name=filter_name,
        filter_extra=filter_extra,
        unit_groups=unit_groups,
    )
    view_context_test(ctx, **assertions)
Exemple #5
0
def export_view(request, translation_project, dir_path, filename=None):
    """Displays a list of units with filters applied."""
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        units_qs = store.units
    else:
        store = None
        units_qs = translation_project.units.filter(
            store__pootle_path__startswith=current_path, )

    filter_name, filter_extra = get_filter_name(request.GET)

    units = get_step_query(request, units_qs)
    unit_groups = [(path, list(units))
                   for path, units in groupby(units, lambda x: x.store.path)]

    ctx = {
        'source_language': translation_project.project.source_language,
        'language': translation_project.language,
        'project': translation_project.project,
        'unit_groups': unit_groups,
        'filter_name': filter_name,
        'filter_extra': filter_extra,
        'goal': request.GET.get('goal', ''),
    }

    return render_to_response('translation_projects/export_view.html',
                              ctx,
                              context_instance=RequestContext(request))
Exemple #6
0
def export_view(request, translation_project, dir_path, filename=None):
    """Displays a list of units with filters applied."""
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        units_qs = store.units
    else:
        store = None
        units_qs = translation_project.units.filter(
            store__pootle_path__startswith=current_path,
        )

    filter_name, filter_extra = get_filter_name(request.GET)

    units = get_step_query(request, units_qs)
    unit_groups = [(path, list(units)) for path, units in
                   groupby(units, lambda x: x.store.path)]

    ctx = {
        'source_language': translation_project.project.source_language,
        'language': translation_project.language,
        'project': translation_project.project,
        'unit_groups': unit_groups,
        'filter_name': filter_name,
        'filter_extra': filter_extra,
        'goal': request.GET.get('goal', ''),
    }

    return render_to_response('translation_projects/export_view.html', ctx,
                              context_instance=RequestContext(request))
Exemple #7
0
def _test_export_view(tp, request, response, kwargs):
    ctx = response.context
    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)
    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_for_path(
        ob.pootle_path, request.profile)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related('store')
    unit_groups = [
        (path, list(units))
        for path, units
        in groupby(
            units_qs,
            lambda x: x.store.pootle_path)]
    view_context_test(
        ctx,
        **dict(
            project=tp.project,
            language=tp.language,
            source_language=tp.project.source_language,
            filter_name=filter_name,
            filter_extra=filter_extra,
            unit_groups=unit_groups))
Exemple #8
0
def get_export_view_context(request):
    """Returns a common context for export views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    filter_name, filter_extra = get_filter_name(request.GET)

    units_qs = Unit.objects.get_for_path(request.pootle_path, request.profile)
    units = get_step_query(request, units_qs)
    unit_groups = [(path, list(units))
                   for path, units in groupby(units, lambda x: x.store.path)]
    return {
        'unit_groups': unit_groups,
        'filter_name': filter_name,
        'filter_extra': filter_extra
    }
Exemple #9
0
def get_export_view_context(request):
    """Returns a common context for export views.

    :param request: a :cls:`django.http.HttpRequest` object.
    """
    filter_name, filter_extra = get_filter_name(request.GET)

    units_qs = Unit.objects.get_for_path(request.pootle_path, request.user)
    units = get_step_query(request, units_qs)
    unit_groups = [(path, list(units)) for path, units in
                   groupby(units, lambda x: x.store.pootle_path)]
    return {
        'unit_groups': unit_groups,

        'filter_name': filter_name,
        'filter_extra': filter_extra
    }
Exemple #10
0
def test_view_projects_export(site_permissions, site_matrix_with_vfolders, client, nobody, default):
    response = client.get(reverse("pootle-projects-export"))
    ctx = response.context
    request = response.wsgi_request
    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_for_path("/projects/", request.profile)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related("store")
    unit_groups = [(path, list(units)) for path, units in groupby(units_qs, lambda x: x.store.pootle_path)]
    assertions = dict(
        project=None,
        language=None,
        source_language="en",
        filter_name=filter_name,
        filter_extra=filter_extra,
        unit_groups=unit_groups,
    )
    view_context_test(ctx, **assertions)
Exemple #11
0
Fichier : tp.py Projet : haf/pootle
def _test_export_view(tp, request, response, kwargs):
    ctx = response.context
    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_translatable(request.profile, **kwargs)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related("store")
    unit_groups = [(path, list(units)) for path, units in groupby(units_qs, lambda x: x.store.pootle_path)]
    view_context_test(
        ctx,
        **dict(
            project=tp.project,
            language=tp.language,
            source_language=tp.project.source_language,
            filter_name=filter_name,
            filter_extra=filter_extra,
            unit_groups=unit_groups,
        )
    )
Exemple #12
0
def _test_export_view(language, request, response, kwargs):
    # TODO: export views should be parsed in a form
    ctx = response.context
    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_translatable(request.profile, **kwargs)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related('store')
    unit_groups = [
        (path, list(units))
        for path, units in groupby(units_qs, lambda x: x.store.pootle_path)
    ]
    view_context_test(
        ctx,
        **dict(
            project=None,
            language=language,
            source_language="en",
            filter_name=filter_name,
            filter_extra=filter_extra,
            unit_groups=unit_groups))
Exemple #13
0
def _test_export_view(project, request, response, kwargs):
    ctx = response.context
    kwargs["project_code"] = project.code
    filter_name, filter_extra = get_filter_name(request.GET)
    units_qs = Unit.objects.get_translatable(
        request.profile, **kwargs)
    units_qs = get_step_query(request, units_qs)
    units_qs = units_qs.select_related('store')
    unit_groups = [
        (path, list(units))
        for path, units
        in groupby(
            units_qs,
            lambda x: x.store.pootle_path)]
    assertions = dict(
        project=project,
        language=None,
        source_language="en",
        filter_name=filter_name,
        filter_extra=filter_extra,
        unit_groups=unit_groups)
    view_context_test(ctx, **assertions)