def poblar_students(session): # Open the workbook and select the first worksheet wb = xlrd.open_workbook('1MT-2016.xlsx') sh = wb.sheet_by_index(0) # List to hold dictionaries students_list = [] # Iterate through each row in worksheet and fetch values into dict for rownum in range(1, sh.nrows): student = OrderedDict() row_values = sh.row_values(rownum) student['name'] = row_values[0] student['points'] = int(row_values[11]) student['class'] = row_values[12] student['kaid'] = row_values[13][28:] new_student = Student(kaid_student=row_values[13][28:], name=row_values[0], email=row_values[0], points=int(row_values[11]), phone=0) new_student.save() new_student_class = Student_Class(id_class_id=8, kaid_student_id=row_values[13][28:]) new_student_class.save() students_list.append(student) logging.debug(students_list[rownum - 1]['points']) # Serialize the list of dicts to JSON j = json.dumps(students_list)
def poblar_students(session): # Open the workbook and select the first worksheet wb = xlrd.open_workbook('6BA-2016-Alabama.xlsx') sh = wb.sheet_by_index(0) # List to hold dictionaries students_list = [] # Iterate through each row in worksheet and fetch values into dict for rownum in range(1, sh.nrows): student = OrderedDict() row_values = sh.row_values(rownum) student['name'] = row_values[0] student['points'] = int(row_values[11]) student['class'] = row_values[12] student['kaid'] = row_values[13][28:] new_student = Student(kaid_student=row_values[13][28:],name=row_values[0],email=row_values[0],points=int(row_values[11]),phone=0) new_student.save() new_student_class = Student_Class(id_class_id=12,kaid_student_id=row_values[13][28:]) new_student_class.save() students_list.append(student) #logging.debug(students_list[rownum-1]['points']) # Serialize the list of dicts to JSON j = json.dumps(students_list)
def saveExcelClass(request): if request.method == 'POST': newClass = request.POST level = int(newClass['excelClassJson[level]']) letter = newClass["excelClassJson[letter]"] year = newClass["excelClassJson[year]"] additional = newClass["excelClassJson[additional]"] if additional == "": additional = None #teacher = newClass["teacher"] teacher = Teacher.objects.get(name=newClass["excelClassJson[teacher]"]) kaid_teacher = teacher.kaid_teacher students = newClass.getlist("excelClassJson[students][]") kaid = newClass.getlist("excelClassJson[kaid][]") inst = Institution.objects.get(id_institution=Teacher.objects.filter( kaid_teacher=request.user.user_profile.kaid).values( 'id_institution_id')) id_institution = int(inst.id_institution) #print "antes del for" for student in students: estudiante = student.encode('utf-8', errors='replace') indice = students.index(student) #print estudiante #print indice #print kaid[indice] try: aux = Student.objects.filter(nickname=student) if not aux: newStudent = Student(kaid_student=kaid[indice], name=estudiante, nickname=estudiante, id_institution_id=id_institution, new_student=True) newStudent.save() else: continue #print "else" except Exception as e: print e #if e=="Student matching query does not exist.": # print "entro al try" # newStudent=Student(kaid=kaid[indice], name=estudiante, nickname=estudiante, id_institution_id=id_institution) # print "new student ok" # newStudent.save() # print "guardo newstudent" # return HttpResponse("Estudiantes nuevos creados") #if aux.id_institution_id!=id_institution: # return HttpResponse("Estudiantes no corresponden a esta institución") #curso = Class.objects.get(level=level,letter=letter,id_institution_id=id_institution, additional=additional, year=year) #print curso.id_class #student_class = Student_Class.objects.filter(id_class_id=curso.id_class) #print len(students) #print len(student_class) try: curso = Class.objects.get(level=level, letter=letter, id_institution_id=id_institution, additional=additional, year=year) student_class = Student_Class.objects.filter( id_class_id=curso.id_class) #print student_class #print len(students) #print len(student_class) try: if len(students) != len(student_class): #print "try" student_class.delete() #print "delete" for k in kaid: try: aux = Student.objects.get(kaid_student=k) if not aux: aux = Student.objects.get(kaid_student=k) student_class = Student_Class.objects.create( id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create( id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except Exception as e: print e ''' for student in students: estudiante= student.encode('utf-8', errors='replace') print estudiante try: aux = Student.objects.get(name=estudiante) if not aux: aux = Student.objects.get(nickname=estudiante) student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except: continue ''' return HttpResponse("Curso editado correctamente.") else: return HttpResponse("Ya existe el curso.") except Exception as e: print e except: curso = Class.objects.create(level=level, letter=letter, id_institution_id=id_institution, year=year, additional=additional) id_curso = int(curso.id_class) class_subject = Class_Subject.objects.create( id_class_id=id_curso, id_subject_name_id='math', kaid_teacher_id=kaid_teacher) for k in kaid: try: aux = Student.objects.get(kaid_student=k) if not aux: aux = Student.objects.get(kaid_student=k) student_class = Student_Class.objects.create( id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create( id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except Exception as e: print e ''' for student in students: try: aux = Student.objects.get(name=student) if not aux: aux = Student.objects.get(nickname=student) student_class = Student_Class.objects.create(id_class_id=id_curso, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=id_curso, kaid_student_id=aux.kaid_student) except: continue return HttpResponse("Nuevo curso creado") ''' return HttpResponse("Curso creado correctamente")
video_playing.save() except: pass #print "error" #print "listo video_playing" def coach_students(session, id_institution): #ver los estudiantes que tienen como coach a cierto usuario. no entrega info de cursos llamada = "/api/v1/user/students" jason = get_api_resource2(session,llamada,SERVER_URL2) source = unicode(jason, 'ISO-8859-1') data = simplejson.loads(source) for j in range(len(data)): try: <<<<<<< HEAD new_student = Student(kaid_student=data[j]["kaid"],name=data[j]["username"],email=data[j]["username"],points=data[j]["points"],phone=0, id_institution=id_institution) new_student.save() except Exception as e: print e ======= new_student = Student(kaid_student=data[j]["kaid"],name=data[j]["username"],email=data[j]["username"],points=data[j]["points"],phone=0) new_student.save() except: >>>>>>> origin/master logging.debug("error con estudiante "+data[j]["username"]) def poblar_students(session): # Open the workbook and select the first worksheet wb = xlrd.open_workbook('6BA-2016-Alabama.xlsx') sh = wb.sheet_by_index(0) # List to hold dictionaries
def saveExcelClass(request): if request.method == 'POST': newClass = request.POST level = int(newClass['excelClassJson[level]']) letter = newClass["excelClassJson[letter]"] year = newClass["excelClassJson[year]"] additional = newClass["excelClassJson[additional]"] if additional=="": additional = None #teacher = newClass["teacher"] teacher = Teacher.objects.get(name=newClass["excelClassJson[teacher]"]) kaid_teacher = teacher.kaid_teacher students = newClass.getlist("excelClassJson[students][]") kaid = newClass.getlist("excelClassJson[kaid][]") inst = Institution.objects.get(id_institution=Teacher.objects.filter(kaid_teacher=request.user.user_profile.kaid).values('id_institution_id')) id_institution = int(inst.id_institution) #print "antes del for" for student in students: estudiante= student.encode('utf-8', errors='replace') indice = students.index(student) #print estudiante #print indice #print kaid[indice] try: aux = Student.objects.filter(nickname=student) if not aux: newStudent=Student(kaid_student=kaid[indice], name=estudiante, nickname=estudiante, id_institution_id=id_institution, new_student=True) newStudent.save() else: continue #print "else" except Exception as e: print e #if e=="Student matching query does not exist.": # print "entro al try" # newStudent=Student(kaid=kaid[indice], name=estudiante, nickname=estudiante, id_institution_id=id_institution) # print "new student ok" # newStudent.save() # print "guardo newstudent" # return HttpResponse("Estudiantes nuevos creados") #if aux.id_institution_id!=id_institution: # return HttpResponse("Estudiantes no corresponden a esta institución") #curso = Class.objects.get(level=level,letter=letter,id_institution_id=id_institution, additional=additional, year=year) #print curso.id_class #student_class = Student_Class.objects.filter(id_class_id=curso.id_class) #print len(students) #print len(student_class) try: curso = Class.objects.get(level=level,letter=letter,id_institution_id=id_institution, additional=additional, year=year) student_class = Student_Class.objects.filter(id_class_id=curso.id_class) #print student_class #print len(students) #print len(student_class) try: if len(students)!=len(student_class): #print "try" student_class.delete() #print "delete" for k in kaid: try: aux = Student.objects.get(kaid_student=k) if not aux: aux = Student.objects.get(kaid_student=k) student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except Exception as e: print e ''' for student in students: estudiante= student.encode('utf-8', errors='replace') print estudiante try: aux = Student.objects.get(name=estudiante) if not aux: aux = Student.objects.get(nickname=estudiante) student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except: continue ''' return HttpResponse("Curso editado correctamente.") else: return HttpResponse("Ya existe el curso.") except Exception as e: print e except: curso = Class.objects.create(level=level, letter=letter, id_institution_id=id_institution, year=year, additional=additional) id_curso = int(curso.id_class) class_subject = Class_Subject.objects.create(id_class_id=id_curso, id_subject_name_id='math', kaid_teacher_id=kaid_teacher) for k in kaid: try: aux = Student.objects.get(kaid_student=k) if not aux: aux = Student.objects.get(kaid_student=k) student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=curso.id_class, kaid_student_id=aux.kaid_student) except Exception as e: print e ''' for student in students: try: aux = Student.objects.get(name=student) if not aux: aux = Student.objects.get(nickname=student) student_class = Student_Class.objects.create(id_class_id=id_curso, kaid_student_id=aux.kaid_student) else: student_class = Student_Class.objects.create(id_class_id=id_curso, kaid_student_id=aux.kaid_student) except: continue return HttpResponse("Nuevo curso creado") ''' return HttpResponse("Curso creado correctamente")
def coach_students( session, id_institution ): #ver los estudiantes que tienen como coach a cierto usuario. no entrega info de cursos llamada = "/api/v1/user/students" jason = get_api_resource2(session, llamada, SERVER_URL2) source = unicode(jason, 'ISO-8859-1') data = simplejson.loads(source) #with open('data.txt', 'w') as outfile: # json.dump(data, outfile) logging.debug(len(data)) for j in range(len(data)): if data[j]["email"] != None: email = data[j]["email"] else: email = data[j]["username"] try: estd = Student.objects.filter( kaid_student=data[j]["kaid"]).values('kaid_student') if estd[0]['kaid_student'] != None: if data[j]["username"] == "": new_student = Student(kaid_student=estd[0]['kaid_student']) new_student.name = data[j]["nickname"] new_student.email = email new_student.points = data[j]["points"] new_student.id_institution_id = id_institution new_student.nickname = data[j]["nickname"] if estd[0]['last_update'] != None: new_student.new_student = False else: new_student.new_student = True new_student.last_update = datetime.date.today() new_student.save() else: new_student = Student(kaid_student=estd[0]['kaid_student']) new_student.name = data[j]["username"] new_student.email = email new_student.points = data[j]["points"] new_student.id_institution_id = id_institution new_student.nickname = data[j]["nickname"] if estd[0]['last_update'] != None: new_student.new_student = False else: new_student.new_student = True new_student.last_update = datetime.date.today() new_student.save() else: if data[j]["username"] == "": new_student = Student(kaid_student=data[j]["kaid"]) new_student.name = data[j]["nickname"] new_student.email = email new_student.points = data[j]["points"] new_student.id_institution_id = id_institution new_student.nickname = data[j]["nickname"] new_student.last_update = datetime.date.today() new_student.new_student = True new_student.save() else: new_student = Student(kaid_student=data[j]["kaid"]) new_student.name = data[j]["username"] new_student.email = email new_student.points = data[j]["points"] new_student.id_institution_id = id_institution new_student.nickname = data[j]["nickname"] new_student.last_update = datetime.date.today() new_student.new_student = True new_student.save() except Exception as e: logging.warning(e) print e