コード例 #1
0
def upload_file(request):
    #This function handle upload action
    message = None
    if request.method == 'POST':  # If file fom is  submitted
        form = upload_file_form(request.POST, request.FILES)
        if form.is_valid():  #Cheking form validate
            f = request.FILES['file']
            fileName, fileExtension = os.path.splitext(f.name)
            if fileExtension != ('.xls'):
                message = 'wrong file extension'
            else:
                now = datetime.datetime.now()
                temp = Upload(filestore=str(now.year) + str(now.day) +
                              str(now.month) + str(now.hour) +
                              str(now.minute) + str(now.second) + f.name,
                              filename=f.name,
                              description=request.POST['description'],
                              upload_time=datetime.datetime.now())
                handle_uploaded_file(
                    f, FILE_UPLOAD_PATH,
                    temp.filestore)  #Save file content to uploaded folder
                generator, response = generate(temp.filestore, request)
                if generator != "ok":
                    message = generator
                    c = RequestContext(request)
                    os.remove(FILE_UPLOAD_PATH + '/' + temp.filestore)
                    return render_to_response(UPLOAD, {
                        'form': form,
                        'message': message
                    },
                                              context_instance=c)
                else:
                    temp.save()  #Save file information into database
                    message = "Uploaded successfully. Your uploaded and generated file will be stored shortly. You should download them in the file list page as soon as possible!"
                    c = RequestContext(request)
                    file_list = [temp]
                    return render_to_response(FILE_LIST, {
                        'file_list': file_list,
                        'message': message
                    },
                                              context_instance=c)

        else:
            message = "Error"
            #return HttpResponseRedirect('http://127.0.0.1:8000/admin')
    else:  #if file is not submitted that generate the upload form
        form = upload_file_form()

    c = RequestContext(request)
    return render_to_response(UPLOAD, {
        'form': form,
        'message': message
    },
                              context_instance=c)
コード例 #2
0
ファイル: viewCount.py プロジェクト: tungvx/qlnt
def printNoPass(request,type=None,isExcel=None):
    tt1=time.time()
    
    user = request.user
    if not user.is_authenticated():
        return HttpResponseRedirect( reverse('login'))
    currentYear = get_current_year(request)
    try:
        if in_school(request,currentYear.school_id) == False:
            return HttpResponseRedirect('/school')
    except Exception as e:
        return HttpResponseRedirect(reverse('index'))

    if get_position(request) != 4:
       return HttpResponseRedirect('/school')
    if type==None:
        type=1
    list=[]       
             
    type = int(type)
    blockList = Block.objects.filter(school_id=currentYear.school_id).order_by("number")  
    
    for b in blockList:
        classList = Class.objects.filter(block_id=b,year_id=currentYear.school_id).order_by("id")
        for c in classList:
            if   type==1:
                pupils=TBNam.objects.filter(student_id__classes=c.id,len_lop=False).order_by("student_id__index")
            elif type==2:                        
                pupils=TBNam.objects.filter(student_id__classes=c.id,thi_lai=True).order_by("student_id__index")
            elif type==3:                        
                pupils=TBNam.objects.filter(student_id__classes=c.id,ren_luyen_lai=True).order_by("student_id__index")
            list.append((c.name,pupils))
                
    if isExcel:
        request.session['school_id'] = currentYear.school_id.id
        request.session['year_id'] = currentYear.id
        request.session['type'] = type
        message, response = generate('thong ke khong len lop thi lai ren luyen them.xls', request)
        request.session['school_id'] = None
        request.session['year_id'] = None
        request.session['type'] = None
        return response
#        return printNoPassExcel(list,type,currentYear)
    tt2=time.time()
    print tt2-tt1
    t = loader.get_template(os.path.join('school/report','print_no_pass.html'))
    c = RequestContext(request, {
                                 'list':list,
                                 'type':type,
                                 })
    return HttpResponse(t.render(c))
コード例 #3
0
ファイル: views.py プロジェクト: tungvx/reporting
def upload_file(request):
    # This function handle upload action
    message = None
    if request.method == "POST":  # If file fom is  submitted
        form = upload_file_form(request.POST, request.FILES)
        if form.is_valid():  # Cheking form validate
            f = request.FILES["file"]
            fileName, fileExtension = os.path.splitext(f.name)
            if fileExtension != (".xls"):
                message = "wrong file extension"
            else:
                now = datetime.datetime.now()
                temp = Upload(
                    filestore=str(now.year)
                    + str(now.day)
                    + str(now.month)
                    + str(now.hour)
                    + str(now.minute)
                    + str(now.second)
                    + f.name,
                    filename=f.name,
                    description=request.POST["description"],
                    upload_time=datetime.datetime.now(),
                )
                handle_uploaded_file(f, FILE_UPLOAD_PATH, temp.filestore)  # Save file content to uploaded folder
                generator, response = generate(temp.filestore, request)
                if generator != "ok":
                    message = generator
                    c = RequestContext(request)
                    os.remove(FILE_UPLOAD_PATH + "/" + temp.filestore)
                    return render_to_response(UPLOAD, {"form": form, "message": message}, context_instance=c)
                else:
                    temp.save()  # Save file information into database
                    message = "Uploaded successfully. Your uploaded and generated file will be stored shortly. You should download them in the file list page as soon as possible!"
                    c = RequestContext(request)
                    file_list = [temp]
                    return render_to_response(
                        FILE_LIST, {"file_list": file_list, "message": message}, context_instance=c
                    )

        else:
            message = "Error"
            # return HttpResponseRedirect('http://127.0.0.1:8000/admin')
    else:  # if file is not submitted that generate the upload form
        form = upload_file_form()

    c = RequestContext(request)
    return render_to_response(UPLOAD, {"form": form, "message": message}, context_instance=c)
コード例 #4
0
def view_report(request):
    fname = request.GET['filename']
    generator, response = generate(fname, request)
    return response
コード例 #5
0
ファイル: views.py プロジェクト: tungvx/reporting
def view_report(request):
    fname = request.GET["filename"]
    generator, response = generate(fname, request)
    return response
コード例 #6
0
ファイル: viewCount.py プロジェクト: tungvx/qlnt
def printDanhHieu(request,termNumber=None,type=None,isExcel=None):
    tt1=time.time()
    
    user = request.user
    if not user.is_authenticated():
        return HttpResponseRedirect( reverse('login'))
    currentTerm = get_current_term(request)
    try:
        if in_school(request,currentTerm.year_id.school_id) == False:
            return HttpResponseRedirect('/school')
    except Exception as e:
        return HttpResponseRedirect(reverse('index'))

    if get_position(request) != 4:
       return HttpResponseRedirect('/school')

    if termNumber==None:
        termNumber=currentTerm.number    
    list=[]                
    if type!=None:
        print "fff"
        
        termNumber=int(termNumber)
        type = int(type)
        blockList = Block.objects.filter(school_id=currentTerm.year_id.school_id).order_by("number")  
        for b in blockList:
            classList = Class.objects.filter(block_id=b,year_id=currentTerm.year_id.id).order_by("id")
            for c in classList:
                if int(termNumber)<3:
                    if   type==1:
                        danhHieus=TBHocKy.objects.filter(student_id__classes=c.id,term_id__number=termNumber,danh_hieu_hk='G').order_by("student_id__index")
                    elif type==2:                        
                        danhHieus=TBHocKy.objects.filter(student_id__classes=c.id,term_id__number=termNumber,danh_hieu_hk='TT').order_by("student_id__index")
                    elif type==3:                        
                        danhHieus=TBHocKy.objects.filter(student_id__classes=c.id,term_id__number=termNumber,danh_hieu_hk__in=['G','TT']).order_by("danh_hieu_hk","student_id__index")
                else:        
                    if   type==1:
                        danhHieus=TBNam.objects.filter(student_id__classes=c.id,danh_hieu_nam='G').order_by("student_id__index")
                    elif type==2:                        
                        danhHieus=TBNam.objects.filter(student_id__classes=c.id,danh_hieu_nam='TT').order_by("student_id__index")
                    elif type==3:                        
                        danhHieus=TBNam.objects.filter(student_id__classes=c.id,danh_hieu_nam__in=['G','TT']).order_by("danh_hieu_nam","student_id__index")
                list.append((c.name,danhHieus))    
    if isExcel:
        request.session['term_number'] = termNumber
        request.session['type'] = type
        request.session['school_id'] = currentTerm.year_id.school_id.id
        request.session['year_id'] = currentTerm.year_id.id
        message, response = generate('thong ke danh hieu.xls', request)
        print message
        request.session['term_number'] = None
        request.session['type'] = None
        request.session['school_id'] = None
        request.session['year_id'] = None
        return response
#        return printHanhKiemExcel(list,termNumber,type,currentTerm)
    tt2=time.time()
    print tt2-tt1
    t = loader.get_template(os.path.join('school/report','print_danh_hieu.html'))
    c = RequestContext(request, {
                                 'list':list,
                                 'type':type,
                                 'termNumber':termNumber,                                 
                                 })
    return HttpResponse(t.render(c))
コード例 #7
0
ファイル: viewCount.py プロジェクト: tungvx/qlnt
def count2(request,type=None,modeView=None,year_id=None,number=None,index=-1,isExcel=None):
    tt1=time.time()
    user = request.user
    if not user.is_authenticated():
        return HttpResponseRedirect( reverse('login'))

    currentTerm=get_current_term(request)    
    try:
        if in_school(request,currentTerm.year_id.school_id) == False:
            return HttpResponseRedirect('/school')
    except Exception as e:
        return HttpResponseRedirect(reverse('index'))

    if get_position(request) != 4:
       return HttpResponseRedirect('/school')
    
    selectedTerm =get_current_term(request)
    currentNumber=selectedTerm.number
    if year_id==None:
        
        selectedYear =get_current_year(request)
        year_id   = selectedTerm.year_id.id
        if selectedTerm.number==3:            
            term_id = Term.objects.get(year_id=selectedYear.id,number=2).id
            number=2
        else:
            term_id = selectedTerm.id   
            number = selectedTerm.number 
    else:
        selectedYear=Year.objects.get(id=year_id)
        if int(number)<3:
            term_id = Term.objects.get(year_id=selectedYear.id,number=number).id
    subjectList=listSubject(year_id)
    number=int(number)
    type=int(type)
    modeView=int(modeView)
    sumsumsum=0
    allList=[]
    list=[]
    subjectName=[]        
    if index!=-1:
        subjectName = subjectList[int(index)-1]
        level =[11,7.995,6.495,4.995,3.495,-1]
        sumsumsum=0
        allSlList=[0,0,0,0,0]
        allPtList=[0,0,0,0,0]
        list=[]        
        if modeView==1:
            blockList = Block.objects.filter(school_id=selectedYear.school_id)  
            for b in blockList:
                classList = Class.objects.filter(block_id=b,year_id=selectedYear.id)
                totalSlList=[0,0,0,0,0]
                totalPtList=[0,0,0,0,0]  
                sumsum=0
                list1=[]
                for c in classList:
                    slList=[0,0,0,0,0]
                    ptList=[0,0,0,0,0]
                    
                    selectedSubjectList = Subject.objects.filter(name=subjectName,class_id=c.id)
                    if len(selectedSubjectList)==0: continue
                    else: selectedSubject=selectedSubjectList[0]
                    
                    if type==1:
                        if number<3:
                            for i in range(5):
                                slList[i]=Mark.objects.filter(term_id=term_id,subject_id=selectedSubject.id,tb__lt=level[i],tb__gt=level[i+1],current=True).count()
                        else:
                            for i in range(5):
                                slList[i]=TKMon.objects.filter(subject_id=selectedSubject.id,tb_nam__lt=level[i],tb_nam__gt=level[i+1],current=True).count()
                    elif type==2:            
                        for i in range(5):
                            slList[i]=Mark.objects.filter(term_id=term_id,subject_id=selectedSubject.id,ck__lt=level[i],ck__gt=level[i+1],current=True).count()
                                
                    sum=Pupil.objects.filter(classes=c.id,attend__is_member=True).count()                    
                    for i in range(5):
                        if sum!=0:
                            ptList[i]=float(slList[i])/sum*100
                        totalSlList[i]+=slList[i]
                        allSlList[i]+=slList[i]
                    if sum!=0:    
                        print sum,slList,ptList
                    
                    if selectedSubject.teacher_id:    
                        teacherName=selectedSubject.teacher_id.last_name+' '+selectedSubject.teacher_id.first_name
                        list1.append([c.name,sum,teacherName,zip(slList,ptList)])
                    else:                            
                        list1.append([c.name,sum,' ',zip(slList,ptList)])
                    sumsum+=sum
                    sumsumsum+=sum
                        
                if sumsum!=0:  
					for i in range(5):
						totalPtList[i]=float(totalSlList[i])/sumsum *100                
                list.append(['Khối '+str(b.number),sumsum,zip(totalSlList,totalPtList),list1])
                    
       #######################################################################        
        elif modeView==2:            
            selectedSubjectList =Subject.objects.filter(name=subjectName,class_id__year_id=year_id,teacher_id__isnull=False).order_by('teacher_id__first_name','teacher_id__last_name')
            length=len(selectedSubjectList)
            previousTeacher=None
            print selectedSubjectList
            for (ii,s) in enumerate(selectedSubjectList):
                ok=False
                slList=[0,0,0,0,0]
                ptList=[0,0,0,0,0]
                teacherName = s.teacher_id.last_name+' '+s.teacher_id.first_name                        
                if  s.teacher_id !=previousTeacher:
                    if ii!=0:
                        if sumsum!=0:  
                            for i in range(5):
                                totalPtList[i]=float(totalSlList[i])/sumsum *100
                        list.append(['Tổng',sumsum,zip(totalSlList,totalPtList),list1])
                    
                    totalSlList=[0,0,0,0,0]
                    totalPtList=[0,0,0,0,0]
                    sumsum=0
                    list1=[]
                if ii==length-1:
                    ok=True
                previousTeacher=s.teacher_id        
                if type==1:
                    if number<3:
                        for i in range(5):
                            slList[i]=Mark.objects.filter(term_id=term_id,subject_id=s.id,tb__lt=level[i],tb__gt=level[i+1],current=True).count()
                    else:
                        for i in range(5):
                            slList[i]=TKMon.objects.filter(subject_id=s.id,tb_nam__lt=level[i],tb_nam__gt=level[i+1],current=True).count()
                elif type==2:            
                    for i in range(5):
                        slList[i]=Mark.objects.filter(term_id=term_id,subject_id=s.id,ck__lt=level[i],ck__gt=level[i+1],current=True).count()
  
                sum=Pupil.objects.filter(classes=s.class_id.id,attend__is_member=True).count()                    
                for i in range(5):
                    if sum!=0:
                        ptList[i]=float(slList[i])/sum*100
                    totalSlList[i]+=slList[i]
                    allSlList[i]+=slList[i]
                    
                list1.append([s.class_id.name,sum,teacherName,zip(slList,ptList)])
                sumsum+=sum
                sumsumsum+=sum
                if ok:    
                    if sumsum!=0:  
                        for i in range(5):
                            totalPtList[i]=float(totalSlList[i])/sumsum *100                
                    list.append(['Tổng',sumsum,zip(totalSlList,totalPtList),list1])
                    
        if sumsumsum!=0:    
           for i in range(5):
               allPtList[i]=float(allSlList[i])/sumsumsum *100
        allList=zip(allSlList,allPtList)
        if isExcel=='1':
            clear_session(request)
            request.session['year_id'] = year_id
            request.session['additional_keys'].append('year_id')
            request.session['subject_name'] = subjectName
            request.session['additional_keys'].append('subject_name')
            request.session['term_number'] = number
            request.session['additional_keys'].append('term_number')
            request.session['type'] = type
            request.session['additional_keys'].append('type')
            request.session['mode_view'] = modeView
            request.session['additional_keys'].append('mode_view')
            try:
                request.session['term_id'] = term_id
                request.session['additional_keys'].append('term_id')
            except :
                ''
            if modeView == 1:
                message, response = generate('tong ket diem theo lop.xls', request)
            else:
                message, response = generate('tong ket diem theo giao vien.xls', request)
            print message
            clear_session(request)
            return response
#            return count2Excel(year_id,number,subjectName,type,modeView,list,allList,sumsumsum)
             
    tt2=time.time()
    print tt2-tt1
    t = loader.get_template(os.path.join('school/report','count2.html'))
    c = RequestContext(request, {
                                 'type':type,
                                 'subjectList':subjectList,
                                 'year_id':year_id,
                                 'number':number,
                                 'index':index,
                                 'list':list,
                                 'allList':allList,
                                 'sumsumsum':sumsumsum,
                                 'subjectName':subjectName,
                                 'currentNumber':currentNumber,
                                 'modeView':modeView,
                                 })
    return HttpResponse(t.render(c))