Esempio n. 1
0
def _test_export_view(tp, request, response, kwargs, settings):
    ctx = response.context
    filter_name, filter_extra = get_filter_name(request.GET)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(
        form_data, user=request.user)
    assert search_form.is_valid()
    total, start, end, units_qs = search_backend.get(Unit)(
        request.user, **search_form.cleaned_data).search()
    units_qs = units_qs.select_related('store')
    assertions = {}
    if total > settings.POOTLE_EXPORT_VIEW_LIMIT:
        units_qs = units_qs[:settings.POOTLE_EXPORT_VIEW_LIMIT]
        assertions.update(
            {'unit_total_count': total,
             'displayed_unit_count': settings.POOTLE_EXPORT_VIEW_LIMIT})
    unit_groups = [
        (path, list(units))
        for path, units
        in groupby(
            units_qs,
            lambda x: x.store.pootle_path)]
    assertions.update(
        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))
    view_context_test(ctx, **assertions)
Esempio n. 2
0
def _test_export_view(tp, request, response, kwargs):
    ctx = response.context
    filter_name, filter_extra = get_filter_name(request.GET)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(
        form_data, user=request.user)
    assert search_form.is_valid()
    total, start, end, units_qs = search_backend.get(Unit)(
        request.user, **search_form.cleaned_data).search()
    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))
Esempio n. 3
0
def _test_export_view(project, request, response, kwargs, settings):
    ctx = response.context
    kwargs["project_code"] = project.code
    filter_name, filter_extra = get_filter_name(request.GET)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(form_data, user=request.user)
    assert search_form.is_valid()
    total, start, end, units_qs = search_backend.get(Unit)(
        request.user, **search_form.cleaned_data).search()
    units_qs = units_qs.select_related('store')
    assertions = {}
    if total > settings.POOTLE_EXPORT_VIEW_LIMIT:
        units_qs = units_qs[:settings.POOTLE_EXPORT_VIEW_LIMIT]
        assertions.update({
            'unit_total_count':
            total,
            'displayed_unit_count':
            settings.POOTLE_EXPORT_VIEW_LIMIT
        })
    unit_groups = [
        (path, list(units))
        for path, units in groupby(units_qs, lambda x: x.store.pootle_path)
    ]
    assertions.update(
        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)
Esempio n. 4
0
def test_view_projects_export(client):
    response = client.get(reverse("pootle-projects-export"))
    ctx = response.context
    request = response.wsgi_request
    filter_name, filter_extra = get_filter_name(request.GET)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(
        form_data, user=request.user)
    assert search_form.is_valid()
    total, start, end, units_qs = search_backend.get(Unit)(
        request.user, **search_form.cleaned_data).search()
    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)
Esempio n. 5
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)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(
        form_data, user=request.user)
    assert search_form.is_valid()
    uid_list, units_qs = get_search_backend()(
        request.user, **search_form.cleaned_data).search()
    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))
Esempio n. 6
0
def test_view_projects_export(client):
    response = client.get(reverse("pootle-projects-export"))
    ctx = response.context
    request = response.wsgi_request
    filter_name, filter_extra = get_filter_name(request.GET)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(
        form_data, user=request.user)
    assert search_form.is_valid()
    total, start, end, units_qs = search_backend.get(Unit)(
        request.user, **search_form.cleaned_data).search()
    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)
Esempio n. 7
0
    def get_context_data(self, *args, **kwargs):
        ctx = {}
        filter_name, filter_extra = get_filter_name(self.request.GET)

        form_data = self.request.GET.copy()
        form_data["path"] = self.path

        search_form = UnitExportForm(form_data, user=self.request.user)

        if not search_form.is_valid():
            raise Http404(ValidationError(search_form.errors).messages)

        total, start, end, units_qs = search_backend.get(Unit)(
            self.request.user, **search_form.cleaned_data).search()

        units_qs = units_qs.select_related('store')

        if total > settings.POOTLE_EXPORT_VIEW_LIMIT:
            units_qs = units_qs[:settings.POOTLE_EXPORT_VIEW_LIMIT]
            ctx.update({
                'unit_total_count':
                total,
                'displayed_unit_count':
                settings.POOTLE_EXPORT_VIEW_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
Esempio n. 8
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)
    form_data = request.GET.copy()
    form_data["path"] = request.path.replace("export-view/", "")
    search_form = UnitExportForm(form_data, user=request.user)
    assert search_form.is_valid()
    uid_list, units_qs = get_search_backend()(
        request.user, **search_form.cleaned_data).search()
    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)
Esempio n. 9
0
    def get_context_data(self, *args, **kwargs):
        ctx = {}
        filter_name, filter_extra = get_filter_name(self.request.GET)

        form_data = self.request.GET.copy()
        form_data["path"] = self.path
        form_data["include_disabled"] = "all" in self.request.GET

        search_form = UnitExportForm(form_data, user=self.request.user)

        if not search_form.is_valid():
            raise Http404(ValidationError(search_form.errors).messages)

        total, start_, end_, units_qs = DBSearchBackend(
            self.request.user,
            **search_form.cleaned_data).search(limit=UNITS_LIMIT)

        units_qs = units_qs.select_related("store")

        if total > UNITS_LIMIT:
            ctx.update({
                "unit_total_count": total,
                "displayed_unit_count": UNITS_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
Esempio n. 10
0
    def get_context_data(self, *args, **kwargs):
        ctx = {}
        filter_name, filter_extra = get_filter_name(self.request.GET)

        form_data = self.request.GET.copy()
        form_data["path"] = self.path

        search_form = UnitExportForm(
            form_data, user=self.request.user)

        if not search_form.is_valid():
            raise Http404(
                ValidationError(search_form.errors).messages)

        total, start, end, units_qs = search_backend.get(Unit)(
            self.request.user, **search_form.cleaned_data).search()

        units_qs = units_qs.select_related('store')

        if total > settings.POOTLE_EXPORT_VIEW_LIMIT:
            units_qs = units_qs[:settings.POOTLE_EXPORT_VIEW_LIMIT]
            ctx.update(
                {'unit_total_count': total,
                 'displayed_unit_count': settings.POOTLE_EXPORT_VIEW_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