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
def get_forms_instances(self, action, user_profile, kwargs): if action in UIView.class_actions: if action in ('translate', 'redirect', 'code', 'rename'): # load a new translation cloning the existing one trans_data = model_to_dict(kwargs['node']) user_data = model_to_dict(user_profile) trans_data.update(user_data) for key in trans_data.keys(): if not key in Item.__localizable__: del trans_data[key] trans_data['locale'] = get_language() trans_data['path'] = kwargs['node'].path trans_data['akey'] = user_profile.akey trans_data['username'] = user_profile.username trans_data['email'] = user_profile.email trans_data['validated'] = user_profile.validated trans_data['related_id'] = kwargs['node'].id trans_data['action'] = kwargs['action'] trans_data['status'] = 'changed' trans_data['subject'] = 'Changed texts' trans_data['message'] = 'Text have been changed' trans_data['visible'] = True translation = Translation(**trans_data) return (translation,) elif action in ('add',): parentNode = kwargs['node'] item = Item() item.parent = parentNode item.locale = get_language() item.get_translation() item.akey=user_profile.akey item.username=user_profile.username item.email=user_profile.email item.validated=user_profile.validated item.action='add' item.status='added' item.subject='Ajout' item.message='Nouvel element ajoute' item.path = parentNode.get_path() item.related_id = item.id return (item,) else: return (kwargs['node'],) #kwargs['node'].get_url() #return (Item.objects.get(id=kwargs['node'].id),) else: return super(UIView, self).get_forms_instances(action, user_profile, kwargs)