Beispiel #1
0
def supprime_graphe(request):
    if 'id' in request.POST:
        test=Graphe_competences.objects.filter(competence__id=request.POST['id']).aggregate(graphe=Max('graphe'))
        graphe=test['graphe']
        if graphe is not None:
            Graphe_competences.delete_graphe(graphe)
            return {'success':True,'msg':u'Graphe N° %s supprimé' % graphe}
        else:
            return {'success':False,'msg':u'Pas de graphe lié à la compétence n° %s' % request.POST['id']}
    return {'success':False,'msg':'Clé manquante'}
Beispiel #2
0
def initialise_graphe(request):
    if not request.user.has_perm('application.est_admin'):
        return {'success':False,'msg':'Droits insuffisants'}
    if 'graphe' in request.POST and request.POST['graphe']!='':
        ok=Graphe_competences.init_graphe_sql(graphe=request.POST['graphe'],
                                              niveau=request.POST['niveau'], 
                                              competence_id=request.POST['id'])
    else:
        ok=Graphe_competences.init_graphe_sql(niveau=request.POST['niveau'], 
                                              competence_id=request.POST['id'])
    if ok:
        msg=u'Graphe initialisé'
    else:
        msg=u'Erreur d\'initialisation du graphe'
    return {'success':ok,'msg':msg}
Beispiel #3
0
def modif_liens(request):
    try:
        cible=Graphe_competences.objects.get(id=request.POST['cible'])
    except:
        return {'success':False,'msg':u'Compétence liée inexistante'}
    cibles=Graphe_competences.objects.filter(competence__id=cible.competence_id,graphe__lte=cible.graphe)
    #on charge le queryset et on calcule le nombre de cibles
    nb_cibles=len(cibles)   
    #origine=Graphe_competences.objects.get(competence=request.POST['origine_id'],graphe=request.POST['origine_graphe'])
    origines=Graphe_competences.objects.filter(competence=request.POST['origine_id'],graphe__lte=request.POST['origine_graphe'])
    
    #recherche si des liens existent déjà
    lien=False
    for c in cibles:
        for o in origines:
            if o.is_child_of(c):
                lien=True
                break
    if lien:
        return {'success':False,'msg':u'Lien entre compétence %s et %s déjà existant' %(cible.competence_id,request.POST['origine_id'])}
    orig_temp=origines.filter(graphe=request.POST['origine_graphe'])
    if len(orig_temp)==0:
        return {'success':False,'msg':u'Compétence inexistante'}
    else: 
        origine=orig_temp[0]
    if request.POST['type']=='append':
        type_lien='E'
    else:
        type_lien='D'
    nb=0
    for cible in cibles:
        nb+=1
        # on prépare les liens avec un lien temporaire pour les retrouver
        Graphe_competences.creer_lien(cible,origine, 'TMP')
    # on met à jour les liens en rajoutant l'utilisateur
    Graphe_competences.objects.filter(type_lien='TMP').update(user=request.user,type_lien=type_lien)
    return {'success':(nb==nb_cibles),'msg':u'%s liens créés sur %s' % (nb,nb_cibles)}
Beispiel #4
0
def change_user(request):
    '''
        change l'utilisateur assoié à une compétence et ses sous-compétences
        note : si mis à 'aucun' (NULL) les utilisateurs ont libre accès (sauf suppression)
            (utile pour donner un accès temporaire pour modfier les liens/arbres)
        sinon seul le propriétaire ou l'administrateur peut agir, 
        y compris pour la création de liens
        TODO : créer une procédure pour mettre à jour les liens lors du changement d'utilisateur
        (recherche des cibles de même compétence et m^utilisateurs, maj du user sur le nouvel utilisateur)
        hmmm a voir.... 
    ''' 
    admin=request.user.has_perm('application.est_admin')
    if not admin:
        return {'success':False,'msg':u'Vous n\'avez pas les permissions nécessaires.'}
    if not('id' in request.POST and 'prof' in request.POST):
        return {'success':False,'msg':u'Clés manquantes.'}
    try:
        comp=Competence.objects.get(id=request.POST['id'])        
    except:
        return {'success':False,'msg':u'Compétence (%s) inexistante' % request.POST['id']}
    user_id=request.POST['prof']
    if user_id=='-':
        user=None
        user_name='Aucun'
    elif user_id=='admin':
        user=request.user
        user_name='Administrateur'
    else:
        try:
            user=Prof.objects.get(id=user_id).user
            user_name=user.first_name
        except:
            return {'success':False,'msg':u'Utilisateur (%s) inexistant' % user_id}
    comp.user=user
    comp.save()
    nbcomps=comp.get_descendants().update(user=user)
    #maj des liens A TESTER
    liste_id=[comp.id]+list(comp.get_descendants().values_list('id',flat=True))
    cible=Graphe_competences.get_graphe(comp.id)
    if (cible is not None):
        cibles=Graphe_competences.objects.filter(type_lien__isnull=False,graphe__lt=cible.graphe).extra(where=['competence_id in %s'],params=[liste_id])
        nbliens=cibles.update(user=user)
    else:
        nbliens=0
    nom=comp.nom
    return {'success':True,'msg':u'Compétence %s et ses %s descendants ont pour nouvel utilisateur %s ( %s liens)'
            % (nom,nbcomps,user_name,nbliens)}
Beispiel #5
0
def init_test():
    Graphe_competences.delete_graphe(0)
    Graphe_competences.delete_graphe(1)
    Graphe_competences.delete_graphe(2)
    Graphe_competences.delete_graphe(3)
    Graphe_competences.init_graphe_sql(niveau=0, competence_id=917, graphe=0)
    Graphe_competences.init_graphe_sql(niveau=1, competence_id=927, graphe=1)
    Graphe_competences.init_graphe_sql(niveau=2, competence_id=941, graphe=2)
    Graphe_competences.init_graphe_sql(niveau=2, competence_id=949, graphe=3)
Beispiel #6
0
def retour_branche(request):
    '''revoie la branche de l arbre des compétences définie par GET['node']
    si 'lazy'=false, renvoie la branche en profondeur (tous les descendants)
    '''
    
    def parcours_branche(noeud,iter_noeud):
        ''' parcourt la branche à partir de "noeud", retour json'''
        item={}
        item['id']=noeud.id
        item['text']=noeud.nom
        item['chemin']=noeud.chemin
        item['depth']=noeud.depth
        #item['leaf']=noeud.is_leaf()
        item['leaf']=False
        if not noeud.is_leaf():
            #c'est un noeud avec des fils
            item['children']=[]
            anc_noeud=noeud
            encore=True
            
            # parcours des fils            
            while encore:
                noeud=iter_noeud.next() # inutile de faire un try, "encore" nous suffit
                encore=(noeud.rgt<anc_noeud.rgt-1)
                # noeud.is_child_of(anc_noeud) fait une requête. On remplace
                # par un test direct
                #TODO: modifier la class NS
                # remarque : ici pas besoin de tester lft (parcours gauche à droite)
                if (noeud.rgt<anc_noeud.rgt) and (noeud.depth==anc_noeud.depth+1):
                    item['children'].append(parcours_branche(noeud,iter_noeud))
        return item
    
    envois_graphe=('graphe' in request.GET )
    
    if request.GET['node']=='ux':
        return []
    if request.GET['node']=='src':
        is_root=True
        if 'pos' in request.GET and request.GET['pos']=='gauche':
            est_graphe=True
            #TODO: intégrer le select_related a get_root_nodes (comme pour get_desc)
            comps=Graphe_competences.get_root_nodes().select_related('competence__nom')
            #comps=Graphe_competences.get_root_nodes(select_related='competence__nom')
        else :
            est_graphe=False
            if envois_graphe:
                #select_related ne marche pas sur les ..._set
                #comps=Competence.get_root_nodes().select_related('graphe_competences_set')                
                comps=Competence.get_root_nodes_infos_graphe()
                
            else:
                comps=Competence.get_root_nodes().order_by('tree_id')                
    else:
        is_root=False
        if 'pos' in request.GET and request.GET['pos']=='gauche':
            est_graphe=True
            comps=Graphe_competences.objects.get(id=request.GET['node']).get_children().select_related('competence__nom')
        else:
            est_graphe=False
            if envois_graphe:
                #comps=Competence.objects.get(id=request.GET['node']).get_children().select_related('graphe_competences_set')
                comps=Competence.objects.get(id=request.GET['node']).get_children_infos_graphe()
            else:
                comps=Competence.objects.get(id=request.GET['node']).get_children()
    items=[]
    lazy=True
    if request.GET.has_key('lazy'):
        lazy=request.GET['lazy']!='False'
    if not lazy:
        for c in comps:
            iter_arbre=Competence.get_tree(c).iterator()
            items.append(parcours_branche(iter_arbre.next(),iter_arbre))
    else:
        for c in comps:
            item={}
            item['id']=c.id
            item['is_root']=is_root
            
            if est_graphe:
                item['text']='(%2d) %s '%(c.graphe,c.competence.nom)
                item['nom']=c.competence.nom
                item['competence_id']=c.competence.id
                item['graphe']=c.graphe
                item['niveau']=c.niveau
                item['user']=c.user_id
            else:
                item['text']=c.nom
                item['nom']=c.nom
                item['user']=c.user_id
            #item['leaf']=c.is_leaf()
            item['leaf']=False
            item['feuille']=c.is_leaf()
            if c.is_leaf(): item['expandable']=True
            item['tree']=c.tree_id
            if envois_graphe :
                if c.graphe is not None : 
                    #item['text']='(%2d) %s' %(c.niveau,item['text'])
                    liste_graphes=c.liste_graphes.split(',')
                    if len(liste_graphes)>1:
                        #il y a des liens de créés
                        item['liens']='%s' % (len(liste_graphes)-1)
                        if request.user.has_perm('application.est_admin'):
                            if c.user_id is None:
                                item['iconCls']='icon-group_link'
                            elif c.user_id==request.user.id:
                                item['iconCls']='icon-user_suit'
                            else:
                                item['iconCls']='icon-folder_link'
                        elif c.user_id==request.user.id or c.user_id is None:
                            if c.depth==1:
                                item['iconCls']='icon-user'
                            else:
                                item['iconCls']='icon-folder_link'
                        else:
                            if c.depth==1:
                                item['iconCls']='icon-folder'
                            else:
                                item['iconCls']='icon-folder_link'
                        liste_graphes.remove(str(c.graphe))
                        liste=', '.join(liste_graphes)
                        item['qtip']='Des liens vers d\'autres graphes existent ('+liste+')'
                    else:
                        if request.user.has_perm('application.est_admin'):
                            if c.user_id is None:
                                item['iconCls']='icon-group'
                            elif c.user_id==request.user.id:
                                item['iconCls']='icon-user_suit'
                            else:
                                item['iconCls']='icon-user_green'
                        elif c.user_id==request.user.id or c.user_id is None:
                            item['iconCls']='icon-user'                            
                        else:
                            item['iconCls']='icon-folder'
                        item['qtip']='Aucun lien n\'a encore été créé'
                        item['liens']=None
                else:
                    item['iconCls']='icon-folder_error'
                    item['qtip']='Cette compétence ne fait pas partie d`un graphe'
                    item['qtipTitle']='Attention!'
                    
                item['liens_graphe']=c.liste_graphes
                item['graphe']=c.graphe      
                item['niveau']=c.niveau
            if est_graphe:                
                item['type_lien']=c.type_lien
                item['qtipTitle']='Lien:'
                if c.type_lien == 'E':
                    item['iconCls']='icon-arrow_right'
                    item['qtip']='Equivalencegfh'
                elif c.type_lien=='D':
                    item['iconCls']='icon-arrow_divide'
                    item['qtip']='Décomposition'
                else:
                    item['iconCls']='icon-text_heading_%s' % (operator.mod(c.niveau,6)+1)
                    #item['overCls']='cssGras' -> marche po
                    item['qtip']='pas de lien mais un qtip sur %s' % item['id']
                    item['qtitle']='Truc:'
            if request.GET.has_key('pos'): 
                item['pos']=request.GET['pos']
                #if item['pos']=='droite'and c.tree_id==5: item['iconCls']='icon-application_add' 
            items.append(item)
    return items