コード例 #1
0
ファイル: import_views.py プロジェクト: prcek/TSReg
def import_school(request,file_id):

    f = FileBlob.get_by_id(int(file_id))

    if f is None:
        raise Http404

    d = cStringIO.StringIO(f.data)
    r = UnicodeReader(d,encoding='utf8', delimiter=',', quotechar='"')
   
    form = None
    course = None 
    
    season = None
    cskey = request.session.get('course_season_key',None)
    if not cskey is None:
        season =  Season.get(str(cskey))
    folder = None
    cfkey = request.session.get('course_folder_key',None)
    if not cfkey is None:
        folder =  Folder.get(str(cfkey))    
    
    logging.info('cfkey %s cskey %s'%(cskey,cfkey))
    logging.info('folder: %s'%folder)
    logging.info('season: %s'%season)
    if folder and season:
        cc = Course.get_COURSE_FILTER_CHOICES(str(season.key()),str(folder.key()))
    else:
        cc = Course.get_COURSE_CHOICES()
    
    
    logging.info('cc:%s'%cc)
    
    if request.method == 'POST':
        logging.info('meth post, filling form')
        form = TargetPickForm2(request.POST,courses = cc)
        if form.is_valid():
            course = Course.get(form.cleaned_data['course_key'])
            if course is None:
                raise Http404
          
    else:
        logging.info('meth get, blank form')
        form = TargetPickForm2(courses = cc)

    selected = None
    info = []
    
    return render_to_response('admin/import_school.html', RequestContext(request, {  'info': info, 'form':form, 'course':course, 'season':season, 'folder':folder}))
コード例 #2
0
ファイル: import_views.py プロジェクト: prcek/TSReg
def index(request):

    if request.method == 'POST':
        logging.info(request.POST)
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            f = request.FILES['file']
            logging.info('filename="%s", size=%d, content_type="%s" '%(f.name,f.size,f.content_type))
            fb = FileBlob()
            fb.init(f.read(),owner=request.auth_info.email, name=f.name, tmp=True)
            fb.save()
            logging.info('file id=%s'%(fb.key().id()))
            return redirect('%d/%s/'%(fb.key().id(),form.cleaned_data['action']))
    else:
        form = UploadFileForm()


    return render_to_response('admin/import_index.html', RequestContext(request, {  'form': form}))
コード例 #3
0
ファイル: import_views.py プロジェクト: prcek/TSReg
def import_students_do(request,file_id, start_line, end_line, course_id):

    course = Course.get_by_id(int(course_id))

    if course is None:
        raise Http404

    f = FileBlob.get_by_id(int(file_id))
    if f is None:
        raise Http404
    d = cStringIO.StringIO(f.data)
    r = UnicodeReader(d, encoding='utf8', delimiter=';', quotechar='"')

    start_line = int(start_line)
    end_line = int(end_line)
    line = 0
    st_list=[]
    for row in r:
        if (line>=end_line):
            break
        if (line>=start_line):
            st = import_student(course,row)
            st_list.append(st)
        line+=1

    if course.group_mode == 'Pair':
        pd = dict()  
        for s in st_list:
            if not s.x_import_no_2 is None:
                p = pd.pop(s.x_import_no_2,None)        
                if p is None:
                    pd[s.x_import_no_2] = s
                else:
                    s.partner_ref_code = p.ref_key
                    p.partner_ref_code = s.ref_key
                    s.save()
                    p.save()

    ###
    taskqueue.add(url='/task/recount_capacity/', params={'course_id':course.key().id()})

    return HttpResponseRedirect('../../../../../')
コード例 #4
0
ファイル: import_views.py プロジェクト: prcek/TSReg
def import_school_do(request,file_id, course_id):

    course = Course.get_by_id(int(course_id))

    if course is None:
        raise Http404

    f = FileBlob.get_by_id(int(file_id))
    if f is None:
        raise Http404
    d = cStringIO.StringIO(f.data)
    r = UnicodeReader(d, encoding='utf8', delimiter=',', quotechar='"')

    st_list=[]
    for row in r:
       st = import_student2(course,row)
       st_list.append(st)


    taskqueue.add(url='/task/recount_capacity/', params={'course_id':course.key().id()})

    return HttpResponseRedirect('../../../../../kurzy/%d/zaci/'%(course.key().id()))
コード例 #5
0
ファイル: import_views.py プロジェクト: prcek/TSReg
def import_students(request,file_id, seq_id=None):

    f = FileBlob.get_by_id(int(file_id))

    if f is None:
        raise Http404

    d = cStringIO.StringIO(f.data)
    r = UnicodeReader(d)
   
    form = None
    course = None 
    
    season = None
    cskey = request.session.get('course_season_key',None)
    if not cskey is None:
        season =  Season.get(str(cskey))
    folder = None
    cfkey = request.session.get('course_folder_key',None)
    if not cfkey is None:
        folder =  Folder.get(str(cfkey))    
    
    logging.info('cfkey %s cskey %s'%(cskey,cfkey))
    logging.info('folder: %s'%folder)
    logging.info('season: %s'%season)
    if folder and season:
        cc = Course.get_COURSE_FILTER_CHOICES(str(season.key()),str(folder.key()))
    else:
        cc = Course.get_COURSE_CHOICES()
    
    
    logging.info('cc:%s'%cc)
    
    if request.method == 'POST':
        form = TargetPickForm(request.POST,courses = cc)
    
    info = []
    seq = 0
    curr = None
    line = 0
    for row in r:
        if len(row)>6 and (row[0].startswith('#export kurz') or row[0].startswith('#zaloha kurz')):
            logging.info(row)
            if not curr is None:
                curr["end_line"]=line
                info.append(curr)
            curr = dict()
            curr["seq"]=seq
            seq+=1
            curr["start_line"]=line+1
            curr["code"]=row[1]
            curr["folder"]=row[2]
            curr["season"]=row[3]
            curr["students"]=0
            curr["info"]=row[6]
        elif len(row)>19 and not row[0].startswith('#'):
            curr["students"]+=1
        line+=1 

    if not curr is None:
        curr["end_line"]=line
        info.append(curr)
    else:
    	### no header detected.
    	curr = dict()
    	curr["seq"]=0
    	curr["start_line"]=0
    	curr["end_line"]=line
    	info.append(curr)
    	
    	

    selected = None
    if not seq_id is None:
        for c in info:
            if c["seq"]==int(seq_id):
                selected = c 
                break
        
        if selected is None:
            raise Http404

        if form is None: 
            form = TargetPickForm(courses = cc, initial={'start_line':selected['start_line'], 'end_line':selected['end_line']})
        else:
            if form.is_valid():
                course = Course.get(form.cleaned_data['course_key'])
                if course is None:
                    raise Http404
                

    return render_to_response('admin/import_students.html', RequestContext(request, {  'info': info, 'form':form, 'selected':selected, 'course':course, 'season':season, 'folder':folder}))