def item_link(request, pk, toid): item = get_object_or_404(Evalitem, pk=pk) if toid == '': to = None childs = Evalitem.get_root_nodes() parents = None print "none" else: to = get_object_or_404(Evalitem, pk=toid) childs = Evalitem.get_descendants_group_count(to) parents = to.get_ancestors() if request.method == "GET": form = EvalitemLinkForm_type() return render(request, "evalitem/item/link.html", {'item': item, 'to': to, 'childs': childs, 'parents': parents, 'form': form}) elif request.method == "POST": form = EvalitemLinkForm_type(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.src = item obj.dest = to obj.save() return HttpResponseRedirect(reverse(item_details, kwargs={'pk': item.pk})) else: return render(request, "evalitem/item/link.html", {'item': item, 'to': to, 'childs': childs, 'parents': parents, 'form': form})
def tree_add_from_parent( request, parentid ): if parentid != None: parent = get_object_or_404( Evalitem, pk=parentid ) else: parent = None if request.method == 'GET': form = EvalitemCreateForm() return render( request, "evalitem/tree/add_from_parent.html", {'parent':parent, 'form': form} ) elif request.method == 'POST': form = EvalitemCreateForm( request.POST, request.FILES ) if form.is_valid(): obj = form.save( False ) if parent == None: Evalitem.add_root( **model_to_dict( obj ) ) return HttpResponseRedirect( reverse( tree_root ) ) else: parent.add_child( **model_to_dict( obj ) ) return HttpResponseRedirect( reverse( tree_from_parent, kwargs={'parentid':parentid} ) ) else: return render( request, "evalitem/tree/add_from_parent.html", {'parent':parent, 'form': form} )
def table_from_parent(request, parentid): if parentid != '': parent = get_object_or_404(Evalitem, pk=parentid) tree = Evalitem.get_annotated_list(parent) else: tree = Evalitem.get_annotated_list() return render(request, "evalitem/table/display.html", {'tree': tree})
def tree_add_root(request): """ Ajout d'un élement d'évaluation (racine) """ if request.method == 'GET': form = EvalitemCreateForm_rootitem() return render(request, "evalitem/tree/add_from_parent.html", {'form': form}) elif request.method == 'POST': form = EvalitemCreateForm_rootitem(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) Evalitem.add_root(**model_to_dict(obj)) return HttpResponseRedirect(reverse(tree_root)) else: return render(request, "evalitem/tree/add_from_parent.html", {'form': form})
def tree_from_parent( request, parentid ): parent = get_object_or_404( Evalitem, pk=parentid ) items = Evalitem.get_descendants_group_count( parent ) return render( request, "evalitem/tree/from_parent.html", {"parents":parent.get_ancestors(), "current":parent, "items":items } )
def tree_from_parent(request, parentid): """ Affichage de la liste des élements d'évaluation (enfants) """ parent = get_object_or_404(Evalitem, pk=parentid) items = Evalitem.get_descendants_group_count(parent) linksfrom = EvalitemLink.objects.filter(src=parent) linksto = EvalitemLink.objects.filter(dest=parent) return render(request, "evalitem/tree/from_parent.html", {"parents": parent.get_ancestors(), "current": parent, "items": items, "linksfrom": linksfrom, "linksto": linksto})
def tree_root(request): """ Affichage de la liste des élément d'évaluation (racine) """ items = Evalitem.get_descendants_group_count() return render(request, "evalitem/tree/root.html", {"items": items})
def tree_root( request ): items = Evalitem.get_descendants_group_count() return render( request, "evalitem/tree/root.html", {"items":items } )
def create_tree_from_csv(f): print "beginning import" dialect = csv.Sniffer().sniff(f.read(2048)) f.seek(0) lines = csv.reader(f, dialect) step = 0 parent = None item = None for sl in lines: l = map(lambda s: s.decode('utf-8'), sl) step += 1 print "Line ", step print l # Skip header if step == 1: continue # Get depth depth = 1 for colnum in range(len(columnmap), len(l)): if l[colnum] != "": break depth += 1 print " - depth: ", depth print " - last item : ", item print " - cur parent : ", parent if parent == None and depth != 1: raise CsvImportException() if parent == None: # make root item code = get_code(l, parent, depth) etype = get_etype(l, parent, depth) tags = get_tags(l, parent, depth) institutionnel = get_tags(l, parent, depth) item = Evalitem.add_root(code=code, etype=etype, tags=tags, institutionnel=institutionnel, titre=l[colnum][:99], description=l[colnum]) parent = item print " - Parent depth: ", parent.depth else: if parent.depth + 2 == depth: # one level down parent = item parent = Evalitem.objects.get(pk=parent.pk) code = get_code(l, parent, depth) etype = get_etype(l, parent, depth) tags = get_tags(l, parent, depth) institutionnel = get_tags(l, parent, depth) item = parent.add_child(code=code, etype=etype, tags=tags, institutionnel=institutionnel, titre=l[colnum][:99], description=l[colnum]) parent = Evalitem.objects.get(pk=parent.pk) # Reload parent elif parent.depth + 1 == depth: # same depth, make child item code = get_code(l, parent, depth) etype = get_etype(l, parent, depth) tags = get_tags(l, parent, depth) institutionnel = get_tags(l, parent, depth) item = parent.add_child(code=code, etype=etype, tags=tags, institutionnel=institutionnel, titre=l[colnum][:99], description=l[colnum]) parent = Evalitem.objects.get(pk=parent.pk) # Reload parent elif depth > parent.depth + 2: # saut trop haut :-) raise CsvImportException("Pas de saut superieur a 1") else: # Rewind in parent tree ancestors = parent.get_ancestors() parent = None for a in ancestors: if a.depth + 1 == depth: parent = a if parent == None: raise CsvImportException("No parent found ? multiple "\ "root not allowed for now") code = get_code(l, parent, depth) etype = get_etype(l, parent, depth) tags = get_tags(l, parent, depth) institutionnel = get_tags(l, parent, depth) item = parent.add_child(code=code, etype=etype, tags=tags, institutionnel=institutionnel, titre=l[colnum][:99], description=l[colnum]) parent = Evalitem.objects.get(pk=parent.pk) # Reload parent print depth, print "DONE"