def get_overview_context(request): """Return a common context for overview browser pages. :param request: a :cls:`django.http.HttpRequest` object. """ resource_obj = request.resource_obj resource_path = getattr(request, 'resource_path', '') url_action_continue = resource_obj.get_translate_url(state='incomplete') url_action_fixcritical = resource_obj.get_critical_url() url_action_review = resource_obj.get_translate_url(state='suggestions') url_action_view_all = resource_obj.get_translate_url(state='all') url_action_next_goal = resource_obj.get_next_goal_url() return { 'page': 'overview', 'pootle_path': request.pootle_path, 'resource_obj': resource_obj, 'resource_path': resource_path, 'resource_path_parts': get_path_parts(resource_path), 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), 'url_action_continue': url_action_continue, 'url_action_fixcritical': url_action_fixcritical, 'url_action_review': url_action_review, 'url_action_view_all': url_action_view_all, 'url_action_next_goal': url_action_next_goal, }
def get_overview_context(request): """Returns a common context for overview browser pages. :param request: a :cls:`django.http.HttpRequest` object. """ resource_obj = request.resource_obj resource_path = getattr(request, 'resource_path', '') filters = {} if (not isinstance(resource_obj, Store) and VirtualFolder.get_matching_for(request.pootle_path).count()): filters['sort'] = 'priority' url_action_continue = resource_obj.get_translate_url(state='incomplete', **filters) url_action_fixcritical = resource_obj.get_critical_url(**filters) url_action_review = resource_obj.get_translate_url(state='suggestions', **filters) url_action_view_all = resource_obj.get_translate_url(state='all') return { 'page': 'overview', 'pootle_path': request.pootle_path, 'resource_obj': resource_obj, 'resource_path': resource_path, 'resource_path_parts': get_path_parts(resource_path), 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), 'url_action_continue': url_action_continue, 'url_action_fixcritical': url_action_fixcritical, 'url_action_review': url_action_review, 'url_action_view_all': url_action_view_all, }
def get_context_data(self, *args, **kwargs): filters = {} if self.has_vfolders: filters['sort'] = 'priority' url_action_continue = self.object.get_translate_url( state='incomplete', **filters) url_action_fixcritical = self.object.get_critical_url( **filters) url_action_review = self.object.get_translate_url( state='suggestions', **filters) url_action_view_all = self.object.get_translate_url(state='all') ctx, cookie_data = self.sidebar_announcements ctx.update( super(PootleBrowseView, self).get_context_data(*args, **kwargs)) ctx.update( {'page': 'browse', 'stats': jsonify(self.stats), 'translation_states': get_translation_states(self.object), 'check_categories': get_qualitycheck_schema(self.object), 'url_action_continue': url_action_continue, 'url_action_fixcritical': url_action_fixcritical, 'url_action_review': url_action_review, 'url_action_view_all': url_action_view_all, 'table': self.table, 'is_store': self.is_store, 'browser_extends': self.template_extends}) return ctx
def get_browser_context(request): """Returns a common context for browser pages. :param request: a :cls:`django.http.HttpRequest` object. """ resource_obj = request.resource_obj resource_path = getattr(request, 'resource_path', '') filters = {} if ((isinstance(resource_obj, Directory) and resource_obj.has_vfolders) or (isinstance(resource_obj, TranslationProject) and resource_obj.directory.has_vfolders)): filters['sort'] = 'priority' url_action_continue = resource_obj.get_translate_url(state='incomplete', **filters) url_action_fixcritical = resource_obj.get_critical_url(**filters) url_action_review = resource_obj.get_translate_url(state='suggestions', **filters) url_action_view_all = resource_obj.get_translate_url(state='all') return { 'page': 'browse', 'pootle_path': request.pootle_path, 'resource_obj': resource_obj, 'resource_path': resource_path, 'resource_path_parts': get_path_parts(resource_path), 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), 'url_action_continue': url_action_continue, 'url_action_fixcritical': url_action_fixcritical, 'url_action_review': url_action_review, 'url_action_view_all': url_action_view_all, }
def get_overview_context(request): """Returns a common context for overview browser pages. :param request: a :cls:`django.http.HttpRequest` object. """ resource_obj = request.resource_obj resource_path = getattr(request, 'resource_path', '') url_action_continue = resource_obj.get_translate_url(state='incomplete') url_action_fixcritical = resource_obj.get_critical_url() url_action_review = resource_obj.get_translate_url(state='suggestions') url_action_view_all = resource_obj.get_translate_url(state='all') return { 'page': 'overview', 'pootle_path': request.pootle_path, 'resource_obj': resource_obj, 'resource_path': resource_path, 'resource_path_parts': get_path_parts(resource_path), 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), 'url_action_continue': url_action_continue, 'url_action_fixcritical': url_action_fixcritical, 'url_action_review': url_action_review, 'url_action_view_all': url_action_view_all, }
def _test_browse_view(project, request, response, kwargs): cookie_data = json.loads( unquote(response.cookies[SIDEBAR_COOKIE_NAME].value)) assert cookie_data["foo"] == "bar" assert "announcements_projects_%s" % project.code in cookie_data 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) item_func = (make_xlanguage_item if (kwargs["dir_path"] or kwargs["filename"]) else make_language_item) items = [ item_func(item) for item in ob.get_children_for_user(request.user) ] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) table_fields = [ 'name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'last-updated', 'activity' ] table = { 'id': 'project', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'items': items } assertions = dict( page="browse", project=project, browser_extends="projects/base.html", pootle_path="/projects/%s" % project_path, resource_path=resource_path, resource_path_parts=get_path_parts(resource_path), url_action_continue=ob.get_translate_url(state='incomplete'), url_action_fixcritical=ob.get_critical_url(), url_action_review=ob.get_translate_url(state='suggestions'), url_action_view_all=ob.get_translate_url(state='all'), translation_states=get_translation_states(ob), check_categories=get_qualitycheck_schema(ob), table=table, stats=jsonify(ob.get_stats())) sidebar = get_sidebar_announcements_context(request, (project, )) for k in ["has_sidebar", "is_sidebar_open", "announcements"]: assertions[k] = sidebar[0][k] view_context_test(ctx, **assertions)
def _test_browse_view(project, request, response, kwargs): cookie_data = json.loads(unquote(response.cookies[SIDEBAR_COOKIE_NAME].value)) assert cookie_data["foo"] == "bar" assert "announcements_projects_%s" % project.code in cookie_data 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, ) item_func = make_xlanguage_item if (kwargs["dir_path"] or kwargs["filename"]) else make_language_item items = [item_func(item) for item in ob.get_children_for_user(request.profile)] items.sort(lambda x, y: locale.strcoll(x["title"], y["title"])) table_fields = [ "name", "progress", "total", "need-translation", "suggestions", "critical", "last-updated", "activity", ] table = {"id": "project", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items} assertions = dict( page="browse", project=project, resource_obj=ob, browser_extends="projects/base.html", pootle_path="/projects/%s" % project_path, resource_path=resource_path, resource_path_parts=get_path_parts(resource_path), url_action_continue=ob.get_translate_url(state="incomplete"), url_action_fixcritical=ob.get_critical_url(), url_action_review=ob.get_translate_url(state="suggestions"), url_action_view_all=ob.get_translate_url(state="all"), translation_states=get_translation_states(ob), check_categories=get_qualitycheck_schema(ob), table=table, stats=jsonify(ob.get_stats()), ) sidebar = get_sidebar_announcements_context(request, (project,)) for k in ["has_sidebar", "is_sidebar_open", "announcements"]: assertions[k] = sidebar[0][k] view_context_test(ctx, **assertions)
def test_view_projects_browse(client, request_users): user = request_users["user"] client.login( username=user.username, password=request_users["password"]) response = client.get(reverse("pootle-projects-browse")) assert response.cookies["pootle-language"].value == "projects" ctx = response.context request = response.wsgi_request user_projects = Project.accessible_by_user(request.user) user_projects = ( Project.objects.for_user(request.user) .filter(code__in=user_projects)) ob = ProjectSet(user_projects) items = [ make_project_list_item(project) for project in ob.children] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) table_fields = [ 'name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'last-updated', 'activity'] table = { 'id': 'projects', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'items': items} if request.user.is_superuser: url_action_continue = ob.get_translate_url(state='incomplete') url_action_fixcritical = ob.get_critical_url() url_action_review = ob.get_translate_url(state='suggestions') url_action_view_all = ob.get_translate_url(state='all') else: (url_action_continue, url_action_fixcritical, url_action_review, url_action_view_all) = [None] * 4 assertions = dict( page="browse", pootle_path="/projects/", resource_path="", resource_path_parts=[], object=ob, table=table, browser_extends="projects/all/base.html", stats=jsonify(ob.get_stats()), check_categories=get_qualitycheck_schema(ob), translation_states=get_translation_states(ob), url_action_continue=url_action_continue, url_action_fixcritical=url_action_fixcritical, url_action_review=url_action_review, url_action_view_all=url_action_view_all) view_context_test(ctx, **assertions)
def get_overview_context(request): """Return a common context for overview browser pages. :param request: a :cls:`django.http.HttpRequest` object. """ resource_obj = request.resource_obj return { 'resource_obj': resource_obj, 'resource_path': (request.resource_path if hasattr(request, 'resource_path') else ''), 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), }
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 } 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), stats=jsonify(language.get_stats_for_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)
def test_view_projects_browse(site_permissions, site_matrix_with_vfolders, site_matrix_with_announcements, client, nobody, default): response = client.get(reverse("pootle-projects-browse")) assert response.cookies["pootle-language"].value == "projects" ctx = response.context request = response.wsgi_request user_projects = Project.accessible_by_user(request.user) user_projects = ( Project.objects.for_user(request.user) .filter(code__in=user_projects)) ob = ProjectSet(user_projects) items = [ make_project_list_item(project) for project in ob.children] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) table_fields = [ 'name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'last-updated', 'activity'] table = { 'id': 'projects', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'items': items} assertions = dict( page="browse", pootle_path="/projects/", resource_path="", resource_path_parts=[], object=ob, table=table, browser_extends="projects/all/base.html", stats=jsonify(ob.get_stats()), check_categories=get_qualitycheck_schema(ob), translation_states=get_translation_states(ob), url_action_continue=ob.get_translate_url(state='incomplete'), url_action_fixcritical=ob.get_critical_url(), url_action_review=ob.get_translate_url(state='suggestions'), url_action_view_all=ob.get_translate_url(state='all')) view_context_test(ctx, **assertions)
def test_view_projects_browse( site_permissions, site_matrix_with_vfolders, site_matrix_with_announcements, client, nobody, default ): response = client.get(reverse("pootle-projects-browse")) assert response.cookies["pootle-language"].value == "projects" ctx = response.context request = response.wsgi_request user_projects = Project.accessible_by_user(request.user) user_projects = Project.objects.for_user(request.user).filter(code__in=user_projects) ob = ProjectSet(user_projects) items = [make_project_list_item(project) for project in ob.children] items.sort(lambda x, y: locale.strcoll(x["title"], y["title"])) table_fields = [ "name", "progress", "total", "need-translation", "suggestions", "critical", "last-updated", "activity", ] table = {"id": "projects", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items} assertions = dict( page="browse", pootle_path="/projects/", resource_path="", resource_path_parts=[], resource_obj=ob, table=table, browser_extends="projects/all/base.html", stats=jsonify(ob.get_stats()), check_categories=get_qualitycheck_schema(ob), translation_states=get_translation_states(ob), url_action_continue=ob.get_translate_url(state="incomplete"), url_action_fixcritical=ob.get_critical_url(), url_action_review=ob.get_translate_url(state="suggestions"), url_action_view_all=ob.get_translate_url(state="all"), ) view_context_test(ctx, **assertions)
def overview(request, translation_project, dir_path, filename=None, goal=None, in_goal_overview=False): if filename: ctx = { 'store_tags': request.store.tag_like_objects, } template_name = "translation_projects/store_overview.html" else: ctx = { 'tp_tags': translation_project.tag_like_objects, } template_name = "browser/overview.html" if (check_permission('translate', request) or check_permission('suggest', request) or check_permission('overwrite', request)): ctx.update({ 'upload_form': _handle_upload_form(request, translation_project), }) can_edit = check_permission('administrate', request) project = translation_project.project language = translation_project.language resource_obj = request.store or request.directory #TODO enable again some actions when drilling down a goal. if goal is None: actions = action_groups(request, resource_obj) else: actions = [] action_output = '' running = request.GET.get(EXTDIR, '') #TODO enable the following again when drilling down a goal. if running and goal is None: if request.store: act = StoreAction else: act = TranslationProjectAction try: action = act.lookup(running) except KeyError: messages.error(request, _("Unable to find '%(action)s' in '%(extdir)s'") % {'action': act, 'extdir': running}) else: if not getattr(action, 'nosync', False): (request.store or translation_project).sync() if action.is_active(request): vcs_dir = settings.VCS_DIRECTORY po_dir = settings.PODIRECTORY tp_dir = request.directory.get_real_path() store_fn = '*' if request.store: tp_dir_slash = add_trailing_slash(tp_dir) if request.store.file.name.startswith(tp_dir_slash): # Note: store_f used below in reverse() call. store_f = request.store.file.name[len(tp_dir_slash):] store_fn = store_f.replace('/', os.sep) # Clear possibly stale output/error (even from other # resource_obj). action.set_output('') action.set_error('') try: action.run(path=resource_obj, root=po_dir, tpdir=tp_dir, project=project.code, language=language.code, store=store_fn, style=translation_project.file_style, vc_root=vcs_dir) except StandardError: err = (_("Error while running '%s' extension action") % action.title) logging.exception(err) if (action.error): messages.error(request, action.error) else: messages.error(request, err) else: if (action.error): messages.warning(request, action.error) action_output = action.output if getattr(action, 'get_download', None): export_path = action.get_download(resource_obj) if export_path: import mimetypes abs_path = absolute_real_path(export_path) filename = os.path.basename(export_path) mimetype, encoding = mimetypes.guess_type(filename) mimetype = mimetype or 'application/octet-stream' with open(abs_path, 'rb') as f: response = HttpResponse(f.read(), mimetype=mimetype) response['Content-Disposition'] = ( 'attachment; filename="%s"' % filename) return response if not action_output: if not request.store: rev_args = [language.code, project.code, ''] overview_url = reverse('pootle-tp-overview', args=rev_args) else: slash = store_f.rfind('/') store_d = '' if slash > 0: store_d = store_f[:slash] store_f = store_f[slash + 1:] elif slash == 0: store_f = store_f[1:] rev_args = [language.code, project.code, store_d, store_f] overview_url = reverse('pootle-tp-overview', args=rev_args) return HttpResponseRedirect(overview_url) if goal is None: description = translation_project.description else: description = goal.description # Build URL for getting more information for the current path url_path_summary_more = reverse('pootle-xhr-summary-more') ctx.update({ 'resource_obj': request.resource_obj, 'translation_project': translation_project, 'description': description, 'project': project, 'language': language, 'resource_obj': resource_obj, 'resource_path': request.resource_path, 'feed_path': request.directory.pootle_path[1:], 'action_groups': actions, 'action_output': action_output, 'can_edit': can_edit, 'url_path_summary_more': url_path_summary_more, 'translation_states': get_translation_states(resource_obj), 'check_categories': get_qualitycheck_schema(resource_obj), 'browser_extends': 'translation_projects/base.html', 'browser_body_id': 'tpoverview', }) tp_pootle_path = translation_project.pootle_path if request.store is None: resource_obj_goals = Goal.get_goals_for_path(resource_obj.pootle_path) resource_obj_has_goals = len(resource_obj_goals) > 0 if in_goal_overview and resource_obj_has_goals: # Then show the goals tab. table_fields = ['name', 'progress', 'priority', 'total', 'need-translation', 'suggestions'] items = [make_goal_item(resource_obj_goal, resource_obj.pootle_path) for resource_obj_goal in resource_obj_goals] ctx.update({ 'table': { 'id': 'tp-goals', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'parent': get_parent(request.directory), 'items': items, }, 'resource_obj_has_goals': True, }) elif goal in resource_obj_goals: # Then show the drill down view for the specified goal. table_fields = ['name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'activity'] ctx.update({ 'table': { 'id': 'tp-goals', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'parent': get_goal_parent(request.directory, goal), 'items': get_goal_children(request.directory, goal), }, 'goal': goal, 'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path), 'resource_obj_has_goals': True, }) else: # Then show the files tab. table_fields = ['name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'activity'] ctx.update({ 'table': { 'id': 'tp-files', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'parent': get_parent(request.directory), 'items': get_children(request.directory), }, 'resource_obj_has_goals': resource_obj_has_goals, }) elif goal is not None: ctx.update({ 'goal': goal, 'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path), }) if can_edit: if request.store is None: url_kwargs = { 'language_code': language.code, 'project_code': project.code, } add_tag_action_url = reverse('pootle-xhr-tag-tp', kwargs=url_kwargs) else: add_tag_action_url = reverse('pootle-xhr-tag-store', args=[resource_obj.pk]) if goal is None: edit_form = DescriptionForm(instance=translation_project) edit_form_action = reverse('pootle-tp-admin-settings', args=[language.code, project.code]) else: edit_form = GoalForm(instance=goal) edit_form_action = reverse('pootle-xhr-edit-goal', args=[goal.slug]) ctx.update({ 'form': edit_form, 'form_action': edit_form_action, 'add_tag_form': TagForm(), 'add_tag_action_url': add_tag_action_url, }) return render_to_response(template_name, ctx, context_instance=RequestContext(request))
def _test_browse_view(project, request, response, kwargs): cookie_data = json.loads( unquote(response.cookies[SIDEBAR_COOKIE_NAME].value)) assert cookie_data["foo"] == "bar" assert "announcements_projects_%s" % project.code in cookie_data 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) item_func = ( make_xlanguage_item if (kwargs["dir_path"] or kwargs["filename"]) else make_language_item) items = [ item_func(item) for item in ob.get_children_for_user(request.user) ] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) table_fields = ['name', 'progress', 'total', 'need-translation', 'suggestions', 'critical', 'last-updated', 'activity'] table = { 'id': 'project', 'fields': table_fields, 'headings': get_table_headings(table_fields), 'items': items} if request.user.is_superuser or kwargs.get("language_code"): url_action_continue = ob.get_translate_url(state='incomplete') url_action_fixcritical = ob.get_critical_url() url_action_review = ob.get_translate_url(state='suggestions') url_action_view_all = ob.get_translate_url(state='all') else: (url_action_continue, url_action_fixcritical, url_action_review, url_action_view_all) = [None] * 4 assertions = dict( page="browse", project=project, browser_extends="projects/base.html", pootle_path="/projects/%s" % project_path, resource_path=resource_path, resource_path_parts=get_path_parts(resource_path), url_action_continue=url_action_continue, url_action_fixcritical=url_action_fixcritical, url_action_review=url_action_review, url_action_view_all=url_action_view_all, translation_states=get_translation_states(ob), check_categories=get_qualitycheck_schema(ob), table=table, stats=jsonify(ob.get_stats())) sidebar = get_sidebar_announcements_context( request, (project, )) for k in ["has_sidebar", "is_sidebar_open", "announcements"]: assertions[k] = sidebar[0][k] view_context_test(ctx, **assertions)
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)))
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)))