示例#1
0
def delete(request, table, idP, filtre, page, nbparpage, nomClasser, plusOuMoins, supri):
    supr = False
    table = int(table)
    p = data.table(table).objects.get(id=int(idP))
    if int(supri) == 1:
        obj = data.table(table).objects.filter(id=int(idP))
        obj.delete()
        supr = True
    
    
    return render(request, 'BDD/ADMIN/delete.html', locals())
示例#2
0
    def delete(self):   
    
        response = self.client3.get(reverse('BDD.views.delete',args=[0,10000, 0, 0, 0,0,0,0]))
        self.assertEqual(response.status_code, 302) 
        response = self.client2.get(reverse('BDD.views.delete',args=[0,10000, 0, 0, 0,0,0,0]))
        self.assertEqual(response.status_code, 302) 
        addNote(self.puser, 3, self.puser, self.modules[0], self.puser)
        addNote(self.puser, 3, self.puser, self.modules[0], self.puser)
        noteid=Note.objects.all().last().id
        
        

        
        response = self.client2.get(reverse('BDD.views.delete',args=[6,noteid, 0, 0, 0,0,0,1]))
        self.assertEqual(response.status_code, 302) 
                                
        if self.alll:
            
            for t in range(0,8):
                tabble=table(t) 
                if t==0:
                    minn=3
                else:
                    minn=0
                for obj in tabble.objects.all()[minn:]:
                    
                    response = self.client3.get(reverse('BDD.views.delete',args=[t,obj.id, 0, 0, 0,0,0,1]))
                    self.assertEqual(response.status_code, 200) 
示例#3
0
def areusure(request, table, idP, what, filtre, page, nbparpage, nomClasser, plusOuMoins, nor, which):
    table = int(table)
    
    if int(nor) == 0:
        return render(request, 'BDD/ADMIN/areusure.html', locals())  
    else:
        TABBLE = data.table(table)
        obj = TABBLE.objects.get(id=int(idP))
        l = data.soustable(table)
        for ll in l:
            gr = getattr(obj, ll[3]).get(id=int(what))
            getattr(obj, ll[3]).remove(gr)
        return change(request, table, idP, 0, filtre, page, nbparpage, nomClasser, plusOuMoins,0)
示例#4
0
 def fiche(self):
     response = self.client3.get(reverse('BDD.views.fiche',args=[0,10000, 0, 0, 0,0,0]))
     self.assertEqual(response.status_code, 302) 
     response = self.client2.get(reverse('BDD.views.fiche',args=[0,self.puser.id]))
     self.assertEqual(response.status_code, 302) 
     addNote(self.puser, 3, self.puser, self.modules[0], self.puser)
     addNote(self.puser, 3, self.puser, self.modules[0], self.puser)
     noteid=Note.objects.all().last().id
     response = self.client2.get(reverse('BDD.views.fiche',args=[6,noteid]))
     self.assertEqual(response.status_code, 302) 
                             
     if self.alll:
         
         for t in range(0,8):
             tabble=table(t) 
             for obj in tabble.objects.all():
                 response = self.client3.get(reverse('BDD.views.fiche',args=[t,obj.id]))
                 self.assertEqual(response.status_code, 200) 
示例#5
0
def fiche(request, table, idP, filtre, page, nbparpage, nomClasser, plusOuMoins):
    table = int(table)
    TABBLE = data.table(table)
    obj = TABBLE.objects.get(id=int(idP))
    listeliste = data.listinside(table)
    listetab = data.listTable(table)
    links = data.links(table)
    entier = 0
    soustable = data.soustable(table)
    titrest = []
    for st in soustable:
    
        if st[0] == 0:
            titrest.append([st[0], st[2], getattr(obj, st[3]).all(), st[4]])
        else:
            titrest.append([st[0], st[2], getattr(obj, st[3]).all()])
    
    return render(request, 'BDD/ADMIN/fiche.html', locals())    
示例#6
0
 def change(self):
     
     response = self.client2.get(reverse('BDD.views.change',args=[0,10000, 0, 0, 0,0,0,0]))
     self.assertEqual(response.status_code, 302) 
     
                             
     if self.alll:
         
         for t in range(0,8):
             tabble=table(t) 
             for obj in tabble.objects.all():
                 response = self.client3.get(reverse('BDD.views.change',args=[t,obj.id, 0, 0, 0,0,0,0]))
                 self.assertEqual(response.status_code, 200) 
                 response = self.client2.get(reverse('BDD.views.change',args=[t,obj.id, 0, 0, 0,0,0,0]))
                 if t==6:
                     self.assertEqual(response.status_code, 200) 
                 else:
                     self.assertEqual(response.status_code, 302)
                     
                 if t==0:
                     NOM=["","lol"]
                     PRENOM=["","lol"]
                     
                     argggs={'nom': '', 'prenom':'', 'login':'', 'mail':'', 'sexe':'1', 'adresse':'', 'promotion':'', 'typeP':'1', 'dateDeNaissance':'03/07/1901    ', 'lieuDeNaissance':'', 'numeroDeTel':''}
示例#7
0
def watch(request, table, filtre, page=None, nbparpage=None, nomClasser=None, plusOuMoins=None):
    table = int(table)  
    FILTRE = data.filtre(table)
    filtre = int(filtre)
    listAffich = data.listTable(table)
    listeliste = data.listinside(table)
    addmulti = data.mulipleajout(table)
    if page == None:
        page = 1
    else:
        page = int(page)
    if nomClasser == None:
        nomClasser = 100
    if plusOuMoins == None:
        plusOuMoins = 0   
    if nbparpage == None:
        nbparpage = 40
    else:
        nbparpage = int(nbparpage)       
    allP = False
    
    if nbparpage == 10000:
        allP = True 
    nomClasser = int(nomClasser)
    if int(plusOuMoins) == 0:
        plus = ''
    else:
        plus = '-'
    conditions = []
    cond = []
    if filtre > 0:
        if request.method == 'POST':
           
            form = data.form(table, 0, request.POST)
                
            if form.is_valid():
                filtre = 2
                
                for f in FILTRE:
                    clean = form.cleaned_data[f[0]]
                    
                    if f[4] == 1:
                        cleancond = int(clean)
                    else:
                        cleancond = clean
                    if cleancond != f[2]:
                        
                        if f[4] == 2:
                            cleanf = clean.strftime('%Y-%m-%d')
                        else:
                            cleanf = clean
                        
                        conditions.append((f[3], cleanf))
                        cond.append((f[1], 0))
                request.session['conditions'] = conditions
                request.session['cond'] = cond
                
        else:
            form = data.form(table, 0)
    if filtre == 2 and conditions == []:
        try:
            conditions = request.session['conditions']
            cond = request.session['cond']
            
            entier = 0
            for l in conditions:
                if cond[entier][1] == 1:
                    form.fields[cond[entier][0]].initial = (datetime.strptime(l[1], '%Y-%m-%d').date()).strftime('%d/%m/%Y')
                else:   
                    
                    form.fields[cond[entier][0]].initial = l[1]
                entier = entier + 1
        except:
            filtre = 0
    if nomClasser != 100:
        column = data.classer(table, nomClasser)
        if allP:
            if filtre == 2:
                rep = select(data.table(table), plus, column, listFiltre=conditions)
            else:
                rep = select(data.table(table), plus, column)   
        else:
            if filtre == 2:
                rep = select(data.table(table), plus, column, page, nbparpage, listFiltre=conditions)
            else:    
                rep = select(data.table(table), plus, column, page, nbparpage)
    else:    
        if allP:
            if filtre == 2:
                rep = select(data.table(table), listFiltre=conditions)
            else:
                rep = select(data.table(table))
        else :      
            if filtre == 2:     
                rep = select(data.table(table), page=page, nbparpage=nbparpage, listFiltre=conditions)
            else:
                rep = select(data.table(table), page=page, nbparpage=nbparpage)
    reponserecherche = rep[0]
    n = rep[1]    
    pagemax = nbparpage * page >= n
    pagemoins = page - 1
    pageplus = page + 1
    i = 1
    pages = []
    while nbparpage * (i) < n:
        pages.append(i)
        i = i + 1
    pages.append(i)
    return render(request, 'BDD/ADMIN/watch.html', locals())    
示例#8
0
def change(request, table, idP, what, filtre, page, nbparpage, nomClasser, plusOuMoins, nbajout, first=True):
    table = int(table)
    soustable = data.soustable(table)
    TABBLE = data.table(table)
    obj = TABBLE.objects.get(id=int(idP))
    links = data.links(table)
    titrest = []
    ii = 0
    changed = False
    if (first and request.method == 'POST'  and int(nbajout) == 0):
        
        nbajoutf = nbAjout(request.POST)
    
        if nbajoutf.is_valid():
            nbajout = int(nbajoutf.cleaned_data['nb'])
            first=False
            
            
            
    else:
        nbajoutf = nbAjout()
    
    if (first and request.method == 'POST' and int(what) > 0 and int(nbajout) > 0):
        
        stforms = data.formsoustable(table, request.POST, int(what))
        
        for frm in stforms:
            llll=[o.id for o in getattr(obj, frm[5]).all()]
            frm[0].fields[frm[3]].queryset = frm[4].objects.all().exclude(id__in=llll)
        for frm in stforms:
            
            if frm[0].is_valid():
                frm[0].save(obj)
                changed = True
                return http.HttpResponseRedirect('')
    else:
        
        stforms = data.formsoustable(table)
        
        
        for frm in stforms:
            llll=[o.id for o in getattr(obj, frm[5]).all()]
            frm[0].fields[frm[3]].queryset = frm[4].objects.all().exclude(id__in=llll)
            Formset = formset_factory(frm[0], int(nbajout))
            
    
    if (first and request.method == 'POST' and int(what) == 0 and int(nbajout) > 0):
        
        form = data.form(table, 0, request.POST) 
        if form.is_valid():
            form.modif(idP)    
            changed = True
            
            
    else:
       
        cond = []
        conditions = []
        
        form = data.form(table, 0)
        
        data.changecond(table, cond, conditions, obj)
         
        entier = 0
        for l in conditions:
            if cond[entier][1] == 1:
                form.fields[cond[entier][0]].initial = l.strftime('%d/%m/%Y')
            else:   
                form.fields[cond[entier][0]].initial = l
            entier = entier + 1 
    
    for st in soustable:
        
        if st[0] == 0:
            titrest.append([stforms[ii], st[0], st[2], [getattr(obj, st[3]).all(), st[4]], st[1]])
        else:
            titrest.append([stforms[ii], st[0], st[2], [getattr(obj, st[3], st[1]).all()], st[1]])
            
        ii = ii + 1  
    return render(request, 'BDD/ADMIN/change.html', locals())       
示例#9
0
def supr_salles(table, idP, p):
    """
        Delete objects in the database
        
    :param table: it represent which kind of data it is (exemple: a groupe)
    :type table: int 
    :param idP: id of the object to delete
    :type idP: int
    :param p: user who deletes the object
    :type p: Personne
    
    :Exemple:
    
    >> supr_salles(1, 3, request.user.personne)
    it delete the group (because table=1, the first argument) which the id = 3.
    
    """
    
    txt = "vous avez supprimé "
    obj = data.table(table).objects.filter(id=int(idP))
    if len(obj)>0:
        obj=obj[0]
        obj.isvisible=False
        obj.save()
        if table == 5:
            ST = SALLESTATUT
            txt = txt + "la salle " + obj.nom
        elif table == 0:
            ST = PERSONNESTATUT
            txt = txt + "la personne " + obj.user.first_name + " " + obj.user.last_name
        elif table == 1:
            ST = GROUPESTATUT
            txt = txt + "le groupe " + obj.nom
            for p in obj.personnes.all():
                n = models.News()
                n.txt = "Votre groupe " + obj.nom + " a ete supprimé"
                n.typeG = SUPRIMER
                n.type = GROUPESTATUT
                n.uploadDate = timezone.now()   
                n.save()
                n.personne.add(p)   
        elif table == 2:
            ST = UVSTATUT
            txt = txt + "l\'UV " + obj.nom
        elif table == 3:
            ST = MODULESTATUT
            txt = txt + "le module " + obj.nom
        elif table == 4:
            ST = CALENDRIERSTATUT
            txt = txt + "un cour de " + obj.typeCour.nom
        elif table == 6:
            ST = NOTESTATUT
            txt = txt + "une note de " + obj.personne.filter
        else :
            ST = COURTYPESTATUT
            txt = txt + "un cour de " + obj.nom
        n = models.News()
        n.txt = txt
        n.typeG = SUPRIMER
        n.type = ST
        n.uploadDate = timezone.now()   
        n.save()
        n.personne.add(p)  
示例#10
0
def watch(request, table, filtre, page=None, nbparpage=None, nomClasser=None, plusOuMoins=None):
    """
        It defines the variables used in the template watch.html, which print 
        data. You can filter and sort data.
    
    :param request: Class that give many information like POST, GET and user data.
    :type request: Request    
    :param table: define in which model the object is.
    :type table: int   
    :param filtre: if = 1, filter forms are printed. if =2, filter forms are printed
              and the user has filtered the data. Else, forms no printed, no filters.
    :type filtre: int
    :param page: defines which page is printed. If None, it is the first page.
    :type page: int
    :param nbparpage: defines how many object are printed every pages. if None it is 40. 
                      If 10000 its all of them in one page
    :type nbparpage: int 
    :param nomClasser: Which column is sorted. if None or = 100, nothing is sorted.
    :type nomClasser: int
    :param plusOuMoins:  if None or 0, data is sorted in ascending order, else in descending order.
    :type plusOuMoins: int 
    :return: What the user is going to view on his screen 
    :rtype: HttpResponse
    
    :Exemple:
    
    >> watch(request, 1, 0, 1, 30, 1, 0)
    Will return the http response of the first page that print 30 groups per page (table=1),
    sorted by his first atribute (the name) in ascending order
    Filters forms wont be printed because filtre=0
    All the other parameters (after 3) are the previous parameter of the view watch.
    
    
    """
    isProf= request.user.personne.type==PROF_STATUT

    table = int(table)
    if not request.user.is_superuser and table != 6:
        return index(request)
    FILTRE = data.filtre(table)
    filtre = int(filtre)
    listAffich = data.listTable(table)
    listeliste = data.listinside(table)
    
    allllll = 'all'
    if page == None:
        page = 1
    else:
        page = int(page)
    if nomClasser == None:
        nomClasser = 100
    if plusOuMoins == None:
        plusOuMoins = 0   
    if nbparpage == None:
        nbparpage = 20
    else:
        nbparpage = int(nbparpage)       
    allP = False
    
    if nbparpage == 10000:
        allP = True 
    nomClasser = int(nomClasser)
    if int(plusOuMoins) == 0:
        plus = ''
    else:
        plus = '-'
    conditions = []
    cond = []
    #===========================================================================
    # if filters form are printed
    #===========================================================================
    if filtre > 0:
        #=======================================================================
        # if filter form has been validated
        #=======================================================================
        if request.method == 'POST':
           
            form = data.form(request.user, table, 0, request.POST)
                
            if form.is_valid():
                filtre = 2
                
                for f in FILTRE:
                    clean = form.cleaned_data[f[0]]
                    
                    if f[4] == 1:
                        cleancond = int(clean)
                    else:
                        cleancond = clean
                    if cleancond != f[2]:
                        
                        if f[4] == 2:
                            cleanf = clean.strftime('%Y-%m-%d')
                        elif f[4] == 3:
                            cleanf = str(clean)
                        elif f[4] == 4:
                            cleanf = clean.id
                        else:
                            cleanf = clean
                        
                        conditions.append((f[3], cleanf))
                        cond.append((f[1], 0))
                request.session['conditions'] = conditions
                request.session['cond'] = cond
                
        else:
            form = data.form(request.user, table, 0)
    #===========================================================================
    # filter forms are printed and the user has filtered the data
    #===========================================================================
    if filtre == 2 and conditions == []:
        try:
            conditions = request.session['conditions']
            
            cond = request.session['cond']
            if table == 6 and not request.user.is_superuser:
                    conditions.append(("prof", request.user.personne))
                    cond.append(("prof", 0))
            entier = 0
            for l in conditions:
                if cond[entier][1] == 1:
                    form.fields[cond[entier][0]].initial = (datetime.strptime(l[1], '%Y-%m-%d').date()).strftime('%d/%m/%Y')
                else:   
                    
                    form.fields[cond[entier][0]].initial = l[1]
                entier = entier + 1
        except:
            filtre = 0
    #===========================================================================
    # if nothing is sorted
    #===========================================================================
    if nomClasser != 100:
        column = data.classer(table, nomClasser)
        if allP:
            if filtre == 2 and conditions != []:
                rep = select(data.table(table), plus, column, listFiltre=conditions)
            else:
                if table == 6 and not request.user.is_superuser:
                    conditions = []
                    conditions.append(("prof", request.user.personne))
                    rep = select(data.table(table), plus, column, listFiltre=conditions)  
                else:
                    rep = select(data.table(table), plus, column)   
        else:
            if filtre == 2 and conditions != [] :
                rep = select(data.table(table), plus, column, page, nbparpage, listFiltre=conditions)
            else:    
                if table == 6 and not request.user.is_superuser:
                    conditions = []
                    conditions.append(("prof", request.user.personne))
                    rep = select(data.table(table), plus, column, page, nbparpage, listFiltre=conditions)   
                else:
                    rep = select(data.table(table), plus, column, page, nbparpage)
    #===========================================================================
    # something is sorted
    #===========================================================================
    else:    
        if allP:
            if filtre == 2 and conditions != []:
                rep = select(data.table(table), listFiltre=conditions)
            else:
                if table == 6 and not request.user.is_superuser:
                    conditions = []
                    conditions.append(("prof", request.user.personne))
                    rep = select(data.table(table), listFiltre=conditions) 
                else:
                    rep = select(data.table(table))
        else :      
            if filtre == 2 and conditions != []:     
                rep = select(data.table(table), page=page, nbparpage=nbparpage, listFiltre=conditions)
            else:
                if table == 6 and not request.user.is_superuser:
                    conditions = []
                    conditions.append(("prof", request.user.personne))
                    rep = select(data.table(table), page=page, nbparpage=nbparpage, listFiltre=conditions)
                else:
                    rep = select(data.table(table), page=page, nbparpage=nbparpage)
    reponserecherche = rep[0]
    n = rep[1]    
    pagemax = nbparpage * page >= n
    pagemoins = page - 1
    pageplus = page + 1
    i = 1
    pages = []
    while nbparpage * (i) < n:
        pages.append(i)
        i = i + 1
    pages.append(i)
    return render(request, 'BDD/ADMIN/watch.html', locals())    
示例#11
0
def change(request, table, idP, what, filtre, page, nbparpage, nomClasser, plusOuMoins, first=True):
    """
        It defines the variables used in the template change.html, which print 
        forms to change an object.
    
    :param request: Class that give many information like POST, GET and user data.
    :type request: Request    
    :param table: define in which model the object is.
    :type table: int
    :param idP: id of the object to change 
    :type idP: int
    :param what: if >0 the user want to change a manytomany relation.  
    :type what: int
    :param first: Is it the first time change() has been call ?
    :type first: boolean
            
            the variable bellow are there so when the user press the buttom back
            he has the same specification as before in the view watch.
            
    :param filtre: if = 1, filter forms are printed. if =2, filter forms are printed
                    and the user has filtered the data. Else, forms no printed, no filters.
    :type filtre: int
    :param page: defines which page is printed. If None, it is the first page.
    :type page: int
    :param nbparpage: defines how many object are printed every pages. if None it is 40. 
                      If 10000 its all of them in one page
    :type nbparpage: int 
    :param nomClasser: Which column is sorted. if None or = 100, nothing is sorted.
    :type nomClasser: int
    :param plusOuMoins:  if None or 0, data is sorted in ascending order, else in descending order.
    :type plusOuMoins: int 
    :return: What the user is going to view on his screen 
    :rtype: HttpResponse
    
    :Exemple:
    
    >> change(request, 1, 3, 0, 1, 0, 10, 1, 0)
    Will return the http response of the page that change the group (because table=1) and the id =3.
    what=0 so no many to many relations involved (yet).
    All the other parameters (after 3) are the previous parameter of the view watch.
    
    .. warnings:: admin or teacher in a specific view can change ids in the url.
    
    """
    isProf= request.user.personne.type==PROF_STATUT

    table = int(table)
    if not data.table(table).objects.filter(id=int(idP)).count() > 0 or table > 7:
        return http.HttpResponseRedirect('/')
    if not request.user.is_superuser and table != 6:
        return http.HttpResponseRedirect('/')
    soustable = data.soustable(table)
    TABBLE = data.table(table)
    obj = TABBLE.objects.get(id=int(idP))
    MODEL=data.table(table)()
    if hasattr(MODEL,'links'):
        links = MODEL.links()
    titrest = []
    formseti = None
    ii = 0
    changed = False
    stforms = data.formsoustable(table)
    #===========================================================================
    #  if user wants to change manytomany relations
    #===========================================================================
    if (first and request.method == 'POST' and int(what) > 0):
        for frm in stforms:
            instance = TABBLE.objects.get(id=int(idP))
            frm[0] = frm[0](request.POST, instance=instance)
        j = 1  
        for frm in stforms:
            
            if j == int(what) and frm[0].is_valid():
                frm[0].savePerso(int(idP), request.user.personne)
                changed = True
            j += 1
        return http.HttpResponseRedirect('')
    #===========================================================================
    # no post for manytyomany
    #===========================================================================
    else:
        
        stforms = data.formsoustable(table)
        for frm in stforms:
            instance = TABBLE.objects.get(id=int(idP))
            frm[0] = frm[0](instance=instance)
            
            
    #===========================================================================
    #  if user wants to change value
    #===========================================================================        
    if (first and request.method == 'POST' and int(what) == 0):
        
        form = data.form(request.user, table, 2, request.POST) 
        if form.is_valid():
            form.modif(idP, request.user.personne)    
            changed = True
    #===========================================================================
    #  No POST for value
    #===========================================================================          
    else:
       
        cond = []
        conditions = []
        
        form = data.form(request.user, table, 2)
        
        data.changecond(table, cond, conditions, obj)
         
        entier = 0
        for l in conditions:
            if cond[entier][1] == 1:
                form.fields[cond[entier][0]].initial = l.strftime('%d/%m/%Y')
            else:   
                form.fields[cond[entier][0]].initial = l
            entier = entier + 1 
    taille = len(stforms)
  
    for st in soustable:
        
        if ii < taille:
            
            if st[0] == 0:
                
                titrest.append([stforms[ii], st[0], st[2], [getattr(obj, st[3][0]).all(), st[3][1]], st[1]])
            else:
                
                titrest.append([stforms[ii], st[0], st[2], [getattr(obj, st[3][0], st[1]).all()], st[1]])
        else:
            break        
        ii = ii + 1  
    return render(request, 'BDD/ADMIN/change.html', locals())   
示例#12
0
def delete(request, table, idP, filtre, page, nbparpage, nomClasser, plusOuMoins, supri):
    """
        It defines the variables used in the template delete.html, which print 
        forms to delete an objects.
    
    :param request: Class that give many information like POST, GET and user data.
    :type request: Request    
    :param table: define in which model the object is.
    :type table: int
    :param idP: Is it the id of the object to delete
    :type idP: int
    :param supri: if 1, the obeject has been deleted or delete it, else not
    :type supri: int
            
            the variable bellow are there so when the user press the buttom back
            he has the same specification as before in the view watch.
            
    :param filtre: if = 1, filter forms are printed. if =2, filter forms are printed
                    and the user has filtered the data. Else, forms no printed, no filters.
    :type filtre: int
    :param page: defines which page is printed. If None, it is the first page.
    :type page: int
    :param nbparpage: defines how many object are printed every pages. if None it is 40. 
                      If 10000 its all of them in one page
    :type nbparpage: int 
    :param nomClasser: Which column is sorted. if None or = 100, nothing is sorted.
    :type nomClasser: int
    :param plusOuMoins:  if None or 0, data is sorted in ascending order, else in descending order.
    :type plusOuMoins: int 
    :return: What the user is going to view on his screen 
    :rtype: HttpResponse
    
    :Exemple:
    
    >> delete(request, 1, 3, 0, 1, 1, 2, 0, 0)
    Will return the http response of the page that ask if the user is sure if he wants to delete
    the object that the id=3 and a group in the database (table = 1 represents group database).
    The last parameter is 0 that is why it is an 'are you sure' page.
    All the other parameters (after 3) but the last one are the previous parameter of the view watch.
    
    >> delete(request, 1, 3, 0, 1, 1, 2, 0, 1)
    On the other hand, it will return the http response of the page that print that the 
    the user has deleted the object successfully
    
    
    .. warnings:: the id is in the url but if the user is a teacher and not an admin, 
    he can delete only his own adds. Only an admin has to care about using urls.
    
    
    """

    isProf= request.user.personne.type==PROF_STATUT
    supr = False
    table = int(table)
    if not request.user.is_superuser and table != 6:
        return http.HttpResponseRedirect('/')
    if not data.table(table).objects.filter(id=int(idP)).count() > 0:
        return http.HttpResponseRedirect('/')
    p = data.table(table).objects.get(id=int(idP))
    #===========================================================================
    # if 1, delete
    #===========================================================================
    if int(supri) == 1:
        
        obj = data.table(table).objects.get(id=int(idP))
        if not request.user.is_superuser and table == 6:
            if request.user.personne.id != obj.personne.id:
                return http.HttpResponseRedirect('/')
        supr_salles(table, idP, request.user.personne)
        
        
       
        supr = True
    
    
    return render(request, 'BDD/ADMIN/delete.html', locals())
示例#13
0
def ajouter(request, table, nbajout, filtre, page, nbparpage, nomClasser, plusOuMoins, first=True):
    """
        It defines the variables used in the template ajouter.html, which print 
        forms to add one or mutltiple objects.
    
    :param request: Class that give many information like POST, GET and user data.
    :type request: Request    
    :param table: define in which model the object is.
    :type table: int
    :param first: Is it the first time ajouter() has been call ?
    :type first: boolean
    :param nbajout: if 0, print forms to know how many object the user want to add.
                    if 100, add object for a manyto many relation ex: notes for a group
                    if >100, the objcts are added in a session after =100
                    if not, it adds nbajout forms to add nbajout objects.
    :type nbajout: int
            
            the variable bellow are there so when the user press the buttom back
            he has the same specification as before in the view watch.
            
    :param filtre: if = 1, filter forms are printed. if =2, filter forms are printed
                    and the user has filtered the data. Else, forms no printed, no filters.
    :type filtre: int
    :param page: defines which page is printed. If None, it is the first page.
    :type page: int
    :param nbparpage: defines how many object are printed every pages. if None it is 40. 
                      If 10000 its all of them in one page
    :type nbparpage: int 
    :param nomClasser: Which column is sorted. if None or = 100, nothing is sorted.
    :type nomClasser: int
    :param plusOuMoins:  if None or 0, data is sorted in ascending order, else in descending order.
    :type plusOuMoins: int 
    :return: What the user is going to view on his screen 
    :rtype: HttpResponse
    
    :Exemple:
    
    >> ajouter(request, 1, 3, 0, 1, 12, 0, 0)
    Will return the http response of the page that print 3 forms to add 3
    groups in the database (table = 1 represents group database).
    All the other parameters (after 3) are the previous parameter of the view watch.
    
    .. warnings:: if the user play with nbajout in the url, he will be redirected to index.hmlt
    if he doesn't do it correctly (so no errors occurs)
    
    """
    
    isProf= request.user.personne.type==PROF_STATUT
    nbajout = int(nbajout)
    table = int(table)
    MODEL=data.table(table)()
    if hasattr(MODEL,'ajouterPlusieurs'):
       
       
        AJJ=MODEL.ajouterPlusieurs()
        
    else:
        AJJ=None
    if not request.user.is_superuser and table != 6:  # case of teacher
        return http.HttpResponseRedirect('/')
    #ajj = data.ajouterA(table)
    ficheAfter = False
    if nbajout > 0 and nbajout != 100:
        
        listeform = range(0, nbajout)
        if hasattr(MODEL,'quiery'):
            lquery = MODEL.quiery()
        else:
            lquery =[]
        table = int(table)
        envoi = False
        #===========================================================================
        #      Nb ajout normal. No many to many relations
        #===========================================================================
        if nbajout < 100:
            
            if data.form(request.user, table, 3) == None:
                Formset = formset_factory(data.form(request.user, table, 1), extra=nbajout)
            else:
                
                Formset = formset_factory(data.form(request.user, table, 1), extra=nbajout, formset=data.form(request.user, table, 3))
            if request.method == 'POST' and first:
             
                formset = Formset(request.POST, request.FILES)
                if formset.is_valid():
                    
                    nbajout = 0  
                    envoi = True
                    
                    
                    for form in formset:
                        
                        idP = form.save(request.user.personne)
                        
                    
                form = nbAjout()
                           
            else:
                formset = Formset() 
        #===========================================================================
        #      Many to many relations, the user has already write the forms
        #      to know which many to many relations exactly
        #===========================================================================
        else:
            if 'stock' not in request.session:
                return http.HttpResponseRedirect('/')
            stock = request.session['stock']
            solo = []
            multi = []
            i = 0
            
            if AJJ!=None:
                
                for x in AJJ.listFieldForm:
                    if i==0:
                        kwargs = {
                            AJJ.QCode: stock[i]
                        }
                        a = AJJ.listModel[i].objects.filter(**kwargs)
                        nb = a.count()
                        Formset = formset_factory(AJJ.form, extra=nb, formset=AJJ.baseForm)
                        
                        if request.method == 'POST' and first:
                           
                            formset = Formset(request.POST, request.FILES)
                        
                                
                        else:
                            formset = Formset()
                        b = []
                        ii = 0
                        for aa in a:
                            b.append([aa, formset[ii]])
                            ii += 1
                            
                        multi.append(b)
                        
                        
                    else:
                        solo.append(AJJ.listModel[i].objects.get(id=stock[i]))
                    i += 1
                    
            if request.method == 'POST' and first:
                if formset.is_valid():
                    jj = 0
                    for f in formset:
                        if table == 6:
                            f.save(request.user.personne, solo, [x[jj] for x in multi], request.user.personne)
                        else:
                            f.save(request.user.personne, solo, [x[jj] for x in multi])
                        jj += 1
                    nbajout = 0  
                    return http.HttpResponseRedirect('/watch/' + str(table) + '/' + str(filtre))
            
    else:
        if request.method == 'POST':
            #===========================================================================
            #      Normal nb ajout. no many to many relations. 
            #      print forms to know how much
            #===========================================================================
            if AJJ == None or nbajout < 100:
                
                form = nbAjout(request.POST)
                
                if form.is_valid():
                    nb = form.cleaned_data['nb']
                    
                    return ajouter(request, table, nb, filtre, page, nbparpage, nomClasser, plusOuMoins, False)
                else:
                    if AJJ != None:
                        formAjj = AJJ.formInit()
            #===========================================================================
            #      Many to many relations,print the forms
            #      to know which many to many relations 
            #===========================================================================
            else:
                formAjj = AJJ.formInit(request.POST)
                stock = []
                if formAjj.is_valid():
                    i=0
                    for x in AJJ.listFieldForm:
                        if i == 0:
                            stock.append(formAjj.cleaned_data[x])
                        else:
                            stock.append(formAjj.cleaned_data[x].id)
                        i=i+1
                    request.session['stock'] = stock
                    return ajouter(request, table, 101, filtre, page, nbparpage, nomClasser, plusOuMoins, False)
        else:
            if AJJ != None:
                
                formAjj = AJJ.formInit()
            form = nbAjout() 
            
            
    return render(request, 'BDD/ADMIN/ajouter.html', locals())
示例#14
0
def fiche(request, table, idP, filtre=None, page=None, nbparpage=None, nomClasser=None, plusOuMoins=None):
    """
        It defines the variables used in the template fiche.html, which show specifications of an object in the database.
    
    :param request: Class that give many information like POST, GET and user data.
    :type request: Request    
    :param table: define in which model the object is.
    :type table: int
    :param idP: Id of the object
    :type idP: int
            
            the variable bellow are there so when the user press the buttom back
            he has the same specification as before in the view watch.
            
    :param filtre: if = 1, filter forms are printed. if =2, filter forms are printed
                    and the user has filtered the data. Else, forms no printed, no filters.
    :type filtre: int
    :param page: defines which page is printed. If None, it is the first page.
    :type page: int
    :param nbparpage: defines how many object are printed every pages. if None it is 40. 
                      If 10000 its all of them in one page
    :type nbparpage: int 
    :param nomClasser: Which column is sorted. if None or = 100, nothing is sorted.
    :type nomClasser: int
    :param plusOuMoins:  if None or 0, data is sorted in ascending order, else in descending order.
    :type plusOuMoins: int 
    :return: What the user is going to view on his screen 
    :rtype: HttpResponse
    
    :Exemple:
    
    >> fiche(request, 1, 3)
    Will return the http response of the page that show specificatin of the object which the id = 3 
    and is in the group database (table = 1 represents group database)
    
    .. warnings:: the id is in the url but the user is an admin or a teacher.
    
    
    """
    table = int(table)
    allllll = 'all'
    isProf= request.user.personne.type==PROF_STATUT
    TABBLE = data.table(table)
    if not TABBLE.objects.filter(id=int(idP)).count() > 0:
        return http.HttpResponseRedirect('/')
    if not request.user.is_superuser and table != 6:
        return http.HttpResponseRedirect('/')
    
    obj = TABBLE.objects.get(id=int(idP))
    if not request.user.is_superuser and table == 6:
        if obj.prof.id!=request.user.personne.id:
            return http.HttpResponseRedirect('/')
    listeliste = data.listinside(table)
    listetab = data.listTable(table)
    MODEL=data.table(table)()
    if hasattr(MODEL,'links'):
        links = MODEL.links()
    else:
        links=[]
    entier = 0
    soustable = data.soustable(table)
    titrest = []
    
    #===========================================================================
    #                      Many to many obects
    #===========================================================================
    for st in soustable:
    
        if st[0] == 0:
            titrest.append([st[0], st[2], getattr(obj, st[3][0]).all(), st[3][1], st[4]])
        elif st[0] == 1:
            titrest.append([st[0], st[2], getattr(obj, st[3][0]).all(), st[4]])
    
    return render(request, 'BDD/ADMIN/fiche.html', locals())