Esempio n. 1
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())    
Esempio n. 2
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())