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))
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 = 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=None, language=None, source_language="en", filter_name=filter_name, filter_extra=filter_extra, unit_groups=unit_groups) view_context_test(ctx, **assertions)
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() 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=tp.project, language=tp.language, source_language=tp.project.source_language, filter_name=filter_name, filter_extra=filter_extra, unit_groups=unit_groups))
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 = get_search_backend()( self.request.user, **search_form.cleaned_data).search() units_qs = units_qs.select_related('store') if total > search_form.cleaned_data["count"]: ctx.update({ 'unit_total_count': total, 'displayed_unit_count': search_form.cleaned_data["count"] }) 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
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() 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=None, language=None, source_language="en", filter_name=filter_name, filter_extra=filter_extra, unit_groups=unit_groups) view_context_test(ctx, **assertions)
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) uid_list, units_qs = get_search_backend()( self.request.user, **search_form.cleaned_data).search() units_qs = units_qs.select_related('store') if len(uid_list) > search_form.cleaned_data["count"]: ctx.update( {'unit_total_count': len(uid_list), 'displayed_unit_count': search_form.cleaned_data["count"]}) 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