def get_data_view( request, data_view_id ): """ Returns a rendered template for the given view. """ # Load the template dv = get_object_or_404(DataView, pk=data_view_id) code_type = dv.data_view_type.code_type template = loader.get_template( "catmaid/" + code_type + ".html" ) # Get project information and pass all to the template context config = json.loads( dv.config ) # Get all the projects that are visible for the current user projects = get_project_qs_for_user(request.user) # If requested, filter projects by tags. Otherwise, get all. if "filter_tags" in config: filter_tags = config["filter_tags"] # Only get projects that have all the filter tags set projects = projects.filter( tags__name__in=filter_tags ).annotate( repeat_count=Count("id") ).filter( repeat_count=len(filter_tags) ) # Build a stack index stacks = list(Stack.objects.all()) stack_index = dict([(s.id, s) for s in stacks]) stacks_of = defaultdict(list) for pid, sid in ProjectStack.objects.filter(project__in=projects) \ .order_by('stack__id').values_list('project_id', 'stack_id'): stacks_of[pid].append(stack_index[sid]) # Extend the project list with additional information like editabilty projects = extend_projects( request.user, projects ) # Sort by default if "sort" not in config or config["sort"] == True: projects = natural_sort( projects, "title" ) # Build project index project_index = dict([(p.id, p) for p in projects]) project_ids = set(project_index.keys()) # Build tag index ct = ContentType.objects.get_for_model(Project) tag_links = TaggedItem.objects.filter(content_type=ct) \ .values_list('object_id', 'tag__name') tag_index = defaultdict(set) for pid, t in tag_links: if pid in project_ids: tag_index[t].add(pid) context = Context({ 'data_view': dv, 'projects': projects, 'config': config, 'settings': settings, 'tag_index': tag_index, 'project_index': project_index, 'stack_index': stack_index, 'stacks_of': stacks_of, }) return HttpResponse( template.render( context ) );
def get_data_view( request, data_view_id ): """ Returns a rendered template for the given view. """ # Load the template dv = get_object_or_404(DataView, pk=data_view_id) code_type = dv.data_view_type.code_type template = loader.get_template( "catmaid/" + code_type + ".html" ) # Get project information and pass all to the template context config = json.loads( dv.config ) # Get all the projects that are visible for the current user projects = get_project_qs_for_user(request.user) # If requested, filter projects by tags. Otherwise, get all. if "filter_tags" in config: filter_tags = config["filter_tags"] # Only get projects that have all the filter tags set projects = projects.filter( tags__name__in=filter_tags ).annotate( repeat_count=Count("id") ).filter( repeat_count=len(filter_tags) ) # Extend the project list with additional information like editabilty projects = extend_projects( request.user, projects ) # Sort by default if "sort" not in config or config["sort"] == True: projects = natural_sort( projects, "title" ) context = Context({ 'data_view': dv, 'projects': projects, 'config': config, 'settings': settings }) return HttpResponse( template.render( context ) );
def get_data_view(request, data_view_id): """ Returns a rendered template for the given view. """ # Load the template dv = get_object_or_404(DataView, pk=data_view_id) code_type = dv.data_view_type.code_type template = loader.get_template("catmaid/" + code_type + ".html") # Get project information and pass all to the template context config = json.loads(dv.config) # Get all the projects that are visible for the current user projects = get_project_qs_for_user(request.user) # If requested, filter projects by tags. Otherwise, get all. if "filter_tags" in config: filter_tags = config["filter_tags"] # Only get projects that have all the filter tags set projects = projects.filter(tags__name__in=filter_tags).annotate( repeat_count=Count("id")).filter(repeat_count=len(filter_tags)) # Extend the project list with additional information like editabilty projects = extend_projects(request.user, projects) # Sort by default if "sort" not in config or config["sort"] == True: projects = natural_sort(projects, "title") context = Context({ 'data_view': dv, 'projects': projects, 'config': config, 'settings': settings }) return HttpResponse(template.render(context))
def get_data_view( request, data_view_id ): """ Returns a rendered template for the given view. """ # Load the template dv = get_object_or_404(DataView, pk=data_view_id) code_type = dv.data_view_type.code_type template = loader.get_template( "catmaid/" + code_type + ".html" ) # Get project information and pass all to the template context config = json.loads( dv.config ) # Get all the projects that are visible for the current user projects = get_project_qs_for_user(request.user) # If requested, filter projects by tags. Otherwise, get all. if "filter_tags" in config: filter_tags = config["filter_tags"] # Only get projects that have all the filter tags set # TODO: Improve performande by not using an IN query (but a temp table # join) over all filter_tags. projects = projects.filter( tags__name__in=filter_tags ).annotate( repeat_count=Count("id") ).filter( repeat_count=len(filter_tags) ) show_stacks = config.get('show_stacks', True) show_stackgroups = config.get('show_stackgroups', True) # Make sure we get all needed stacks in the first query if show_stacks: projects = projects.prefetch_related('stacks') # Build a stack index stack_index = defaultdict(list) stacks_of = defaultdict(list) if show_stacks: for p in projects: for s in p.stacks.all(): stack_index[s.id] = s stacks_of[p.id].append(s) # Build a stack group index, if stack groups should be made available stackgroup_index = defaultdict(list) stackgroups_of = defaultdict(list) if show_stackgroups: # Get all stackgroups = StackGroup.objects.filter(project__in=projects) for sg in stackgroups: stackgroup_index[sg.id] = sg stackgroups_of[sg.project_id].append(sg) # Extend the project list with additional information like editabilty projects = extend_projects( request.user, projects ) # Sort by default if "sort" not in config or config["sort"] == True: projects = natural_sort( projects, "title" ) # Build project index project_index = dict([(p.id, p) for p in projects]) project_ids = set(project_index.keys()) # Build tag index ct = ContentType.objects.get_for_model(Project) tag_links = TaggedItem.objects.filter(content_type=ct) \ .values_list('object_id', 'tag__name') tag_index = defaultdict(set) for pid, t in tag_links: if pid in project_ids: tag_index[t].add(pid) context = { 'data_view': dv, 'projects': projects, 'config': config, 'settings': settings, 'tag_index': tag_index, 'project_index': project_index, 'stack_index': stack_index, 'stacks_of': stacks_of, 'stackgroup_index': stackgroup_index, 'stackgroups_of': stackgroups_of, 'STATIC_URL': settings.STATIC_URL, } return HttpResponse( template.render( context ) )
def get_data_view(request, data_view_id): """ Returns a rendered template for the given view. """ # Load the template dv = get_object_or_404(DataView, pk=data_view_id) code_type = dv.data_view_type.code_type template = loader.get_template("catmaid/" + code_type + ".html") # Get project information and pass all to the template context config = json.loads(dv.config) # Get all the projects that are visible for the current user projects = get_project_qs_for_user(request.user).prefetch_related('stacks') # If requested, filter projects by tags. Otherwise, get all. if "filter_tags" in config: filter_tags = config["filter_tags"] # Only get projects that have all the filter tags set projects = projects.filter(tags__name__in=filter_tags).annotate( repeat_count=Count("id")).filter(repeat_count=len(filter_tags)) # Build a stack index stack_index = defaultdict(list) stacks_of = defaultdict(list) for p in projects: for s in p.stacks.all(): stack_index[s.id] = s stacks_of[p.id].append(s) # Extend the project list with additional information like editabilty projects = extend_projects(request.user, projects) # Sort by default if "sort" not in config or config["sort"] == True: projects = natural_sort(projects, "title") # Build project index project_index = dict([(p.id, p) for p in projects]) project_ids = set(project_index.keys()) # Build tag index ct = ContentType.objects.get_for_model(Project) tag_links = TaggedItem.objects.filter(content_type=ct) \ .values_list('object_id', 'tag__name') tag_index = defaultdict(set) for pid, t in tag_links: if pid in project_ids: tag_index[t].add(pid) context = Context({ 'data_view': dv, 'projects': projects, 'config': config, 'settings': settings, 'tag_index': tag_index, 'project_index': project_index, 'stack_index': stack_index, 'stacks_of': stacks_of, 'STATIC_URL': settings.STATIC_URL, }) return HttpResponse(template.render(context))