def get_context_dict(self, request, user_profile, input_data, **kwargs): """ Return the main template args with page hierarchy """ action = kwargs.get('action') if request.path_info.endswith('.json'): request_path = request.path_info[:-len('.json')] else: request_path = request.path_info if request_path.endswith(action+'/'): request_path = request_path[:-len(action)-1] elif request_path.endswith(action): request_path = request_path[:-len(action)] # check for pagination pattern in end of path # my-slug-[1,2,3 ... # my-slug-[A,B,C,D ... template_args = super(ContentView, self).get_context_dict(request, user_profile, input_data, **kwargs) item_path = Item.objects.get_clean_path(request_path) # remove action from path if item_path and item_path.endswith(action): item_path = item_path[:-len(action)-1] try: re_uuid = re.compile("[0-F]{8}-[0-F]{4}-[0-F]{4}-[0-F]{4}-[0-F]{12}", re.I) item_parts = Item.objects.get_clean_path(item_path).split('/') if len(item_parts) == 2 and re_uuid.findall(item_parts[1]): page = Item.objects.get(id=item_parts[1]) else: page = Item.objects.get_at_url(request_path, exact=True) except ObjectDoesNotExist: # acces objects by uuid ? # remove first slash and check if request path is uid # http://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex try: page = Item.objects.get_at_url(item_path, exact=False) if not action in ('directory', ): raise Http404 except ObjectDoesNotExist: # this means the root item haven't been created yet # ensure we have a root page corresponding # so we create it as long as the system could not work otherwise if len(item_path.split('/')) == 1: root_slug = item_path.split('/')[0] page = Item(slug=root_slug, label=root_slug, title=root_slug, username=user_profile.username, email=user_profile.email, akey=kwargs['pipe']['akey'], action=kwargs['pipe']['action'], path=kwargs['pipe']['path'], locale=kwargs['pipe']['locale'], status='added') page.related_id = page.id page.save() else: print root_slug raise Http404 # Check for permission if page: rootNode = page.get_root() roots = rootNode.get_children().filter(visible=True).order_by('order') if page.parent: parentNodes = page.parent.get_children().filter(visible=True) else: parentNodes = rootNode.get_children().filter(visible=True) nodes = page.get_children() nodes = nodes.order_by('order') #i = 0 #for n in nodes: # if n.order != i: # n.order = i # n.save() # i+=1 #nodes = nodes[:100] else: raise Http404 # Check for language template_args.update({'currentNode':page, 'parentNodes':parentNodes, 'rootNode':rootNode, 'roots':roots, 'nodes':nodes,}) return template_args