Exemplo n.º 1
0
    def get(self):
        user = self.get_user_type()     
        if user == user_type.visitor:
            self.response.write('0')
            self.redirect('/')
            return 0
        elif user == user_type.student:
            exam_id = int(self.request.get('exam_id',None))
            exam =  exam_management().find_exam(exam_id)
            


            list_questions = [] 
            for q in exam.questions:
                q=exam_management().find_question(q.id())
                list_questions.append(q)
            
            len_questions = len(list_questions)
            
            
            template_values = {
                "exam":exam,
                "list_questions":list_questions,
                "exam_id":exam_id,
                "len_questions":len_questions,
                "time_init":dt.datetime.utcnow(),
                
            }                                                 
            self.response.write(template.render(template_values))
            
            return 1
        elif user == user_type.tutor:
            id_exam = int(self.request.get('exam_id',None))
            number_question = int(self.request.get('number_question',0))    
            exam =  exam_management().find_exam(id_exam)
            
            list_questions = [] 
            for q in exam.questions:
                q=exam_management().find_question(q.id())
                list_questions.append(q)
            
            len_questions = len(exam.questions)
            
            template_values = {
                "exam":exam,
                "number_question":number_question,
                "len_questions":len_questions,
                "list_questions":list_questions,
                "id_exam":id_exam
            }                                                 
            self.response.write(tutor_template.render(template_values))
            return 2
        else:                       
            
            self.redirect('/')
            return 3
Exemplo n.º 2
0
    def get(self):
        user = self.get_user_type()                    
        if user == user_type.visitor:                    
            self.redirect('/')
            return 0
        elif user == user_type.student:       
            self.redirect('/home')
            return 1

        elif user == user_type.tutor:
            id_exam = int(self.request.get('exam_id',None))
            exam = exam_management().find_exam(id_exam)
            
            name = exam.name
            level = exam.level
            learning_type = exam.learning_type
            unit = exam.unit
            topic = exam.topic

            subject = subject_management().get_subject_by_name('Programacion Orientada a Objetos')
            list_units = unit_management().get_all_units_of_subject(subject.key())
            

            
            
            
            list_questions = [] 
            
            for q in exam.questions:
                q=exam_management().find_question(q.id())
                list_questions.append(q)

            
            len_questions = len(list_questions)

            template_values={'name':name,
                             'level':level,
                             'learning_type':learning_type,
                             'unit':unit,
                             'topic':topic,
                             'list_questions':list_questions,
                             'len_questions':len_questions,
                             'id_exam':id_exam,
                             'list_units':list_units,
                             'upload_url':blobstore.create_upload_url('/upload_exam')
                             }
            
            self.response.write(template.render(template_values))
            return 2                    
        else:                        
            self.redirect('/')  
            return 3
Exemplo n.º 3
0
    def get(self):
        user = self.get_user_type()
        if user == user_type.visitor:
            self.response.write('0')
            self.redirect('/')
            return 0
        elif user == user_type.student:
            exam_id = int(self.request.get('exam_id', None))
            exam = exam_management().find_exam(exam_id)

            list_questions = []
            for q in exam.questions:
                q = exam_management().find_question(q.id())
                list_questions.append(q)

            len_questions = len(list_questions)

            template_values = {
                "exam": exam,
                "list_questions": list_questions,
                "exam_id": exam_id,
                "len_questions": len_questions,
                "time_init": dt.datetime.utcnow(),
            }
            self.response.write(template.render(template_values))

            return 1
        elif user == user_type.tutor:
            id_exam = int(self.request.get('exam_id', None))
            number_question = int(self.request.get('number_question', 0))
            exam = exam_management().find_exam(id_exam)

            list_questions = []
            for q in exam.questions:
                q = exam_management().find_question(q.id())
                list_questions.append(q)

            len_questions = len(exam.questions)

            template_values = {
                "exam": exam,
                "number_question": number_question,
                "len_questions": len_questions,
                "list_questions": list_questions,
                "id_exam": id_exam
            }
            self.response.write(tutor_template.render(template_values))
            return 2
        else:

            self.redirect('/')
            return 3
Exemplo n.º 4
0
    def get(self):
        user = self.get_user_type()
        if user == user_type.visitor:
            self.redirect('/')
            return 0
        elif user == user_type.student:
            unit_id = int(self.request.get('unit_id', None))
            unit = unit_management().get_unit(unit_id)
            exams = exam_management().get_exams_by_unit(unit)
            len_exams = len(exams)

            if (len_exams > 0):
                exam_selected = random.randint(0, len_exams - 1)
                exam = exams[exam_selected]
                template_values = {'exam_id': exam.key().id()}
                self.response.write(template.render(template_values))
            else:
                self.response.write('There i no exams')
            return 1

        elif user == user_type.tutor:
            self.redirect('/home')
            return 2
        else:
            self.redirect('/')

            return 3
Exemplo n.º 5
0
    def get(self):
        user = self.get_user_type()                    
        if user == user_type.visitor:                    
            self.redirect('/')
            return 0
        elif user == user_type.student:       
            unit_id = int(self.request.get('unit_id',None))
            unit = unit_management().get_unit(unit_id)
            exams = exam_management().get_exams_by_unit(unit)
            len_exams = len(exams)
            
            if(len_exams>0):
                exam_selected  = random.randint(0,len_exams - 1)
                exam = exams[exam_selected]
                template_values={'exam_id':exam.key().id()}
                self.response.write(template.render(template_values))
            else:
                self.response.write('There i no exams')
            return 1

        elif user == user_type.tutor:                          
			self.redirect('/home')  
			return 2                    
        else:                        
            self.redirect('/')  
                                   
            return 3
Exemplo n.º 6
0
    def post(self):
        user = self.get_user_type()     
        if user == user_type.visitor:
            self.response.write('0')
            self.redirect('/')
            return 0
        elif user == user_type.student:
            
            exam_id = int(self.request.get('exam_id',None))
            exam_instance = exam_management().find_exam(exam_id)            
            list_answers = []           
            number_questions = len(exam_instance.questions)
            for i in range(number_questions):
                list_answers.append( int(self.request.get('r['+ str(i) +']')))
            time_init = self.request.get('time_init',None)
            
            

            time_end = dt.datetime.utcnow()
            time = elapsed_time().elapsed_time(time_init,time_end)
            
            session = self.get_user_id()
            student = student_management().find_key(session)            
            test_id = test_management().add(time.time(),student.key(),exam_instance.key(),list_answers)
            test_id = int(test_id.id())
            test = test_management().find_test(test_id)
            feedback_message = test_evaluation().feedback_message(test_id)
            #self.response.write(feedback_message)          
            test_score = test_evaluation().test_score(test_id)
            #self.response.write(test_score)
            count_correct_answers = test_evaluation().count_correct_answers(test_id)
            #self.response.write(count_correct_answers)
            count_questions = test_evaluation().count_question(test_id)
            #self.response.write(count_questions)
            if feedback_message != feedback_msg.insuficient:
                test.approved = True
                test.put()
                                                
            template_values = {
                "user":"******",
                "feedback_message":feedback_message,
                "test_score":test_score,
                "count_correct_answers":count_correct_answers,
                "count_questions":count_questions,
                
            }
            self.response.write(finished_template.render(template_values))
            return 1
        elif user == user_type.tutor:                               
            self.redirect('/home')             
            return 2
            
        else:
            
            self.redirect('/home')
            return 3
Exemplo n.º 7
0
    def get(self):
        user = self.get_user_type()                    
        if user == user_type.visitor:                    
            self.redirect('/')
            return 0
        elif user == user_type.student:
            self.redirect('/home') 
            return 1

        elif user == user_type.tutor:
            
            id_exam = int(self.request.get('id_exam',None)) 
            exam_management().find_exam(id_exam).delete()
            self.redirect('menu_exam?page=1')
            return 2                    
        else:                        
            self.redirect('/')  
                                   
            return 3
Exemplo n.º 8
0
    def post(self):
        user = self.get_user_type()
        if user == user_type.visitor:
            self.response.write('0')
            self.redirect('/')
            return 0
        elif user == user_type.student:

            exam_id = int(self.request.get('exam_id', None))
            exam_instance = exam_management().find_exam(exam_id)
            list_answers = []
            number_questions = len(exam_instance.questions)
            for i in range(number_questions):
                list_answers.append(int(self.request.get('r[' + str(i) + ']')))
            time_init = self.request.get('time_init', None)

            time_end = dt.datetime.utcnow()
            time = elapsed_time().elapsed_time(time_init, time_end)

            session = self.get_user_id()
            student = student_management().find_key(session)
            test_id = test_management().add(time.time(), student.key(),
                                            exam_instance.key(), list_answers)
            test_id = int(test_id.id())
            test = test_management().find_test(test_id)
            feedback_message = test_evaluation().feedback_message(test_id)
            #self.response.write(feedback_message)
            test_score = test_evaluation().test_score(test_id)
            #self.response.write(test_score)
            count_correct_answers = test_evaluation().count_correct_answers(
                test_id)
            #self.response.write(count_correct_answers)
            count_questions = test_evaluation().count_question(test_id)
            #self.response.write(count_questions)
            if feedback_message != feedback_msg.insuficient:
                test.approved = True
                test.put()

            template_values = {
                "user": "******",
                "feedback_message": feedback_message,
                "test_score": test_score,
                "count_correct_answers": count_correct_answers,
                "count_questions": count_questions,
            }
            self.response.write(finished_template.render(template_values))
            return 1
        elif user == user_type.tutor:
            self.redirect('/home')
            return 2

        else:

            self.redirect('/home')
            return 3
Exemplo n.º 9
0
	def post(self):
		user = self.get_user_type()                    
		if user == user_type.visitor:                    
			return 0
		elif user == user_type.student:                   
			return 1
		elif user == user_type.tutor:
			available = self.request.get('available',None)  
			delete = self.request.get('delete',None)
			page = self.request.get('vm_page',None)
			if available:
				em_id = self.request.get('em_id',None)                
				exam_management().make_available(int(em_id))                        
			if delete:
				em_id = self.request.get('em_id',None)
				exam = exam_management().find_exam(int(em_id))
				exam_management().remove(exam.key())
				sleep(0.1)
			return 2
		else:
			return 3
Exemplo n.º 10
0
 def post(self):
     user = self.get_user_type()
     if user == user_type.visitor:
         return 0
     elif user == user_type.student:
         return 1
     elif user == user_type.tutor:
         available = self.request.get('available', None)
         delete = self.request.get('delete', None)
         page = self.request.get('vm_page', None)
         if available:
             em_id = self.request.get('em_id', None)
             exam_management().make_available(int(em_id))
         if delete:
             em_id = self.request.get('em_id', None)
             exam = exam_management().find_exam(int(em_id))
             exam_management().remove(exam.key())
             sleep(0.1)
         return 2
     else:
         return 3
Exemplo n.º 11
0
    def find_test_exam_available(self,student_instance):    
        '''        
        Function that retrieve all the exams that hasn't been approved and
        are available for the student
        The algorithm user three nested loops
        First loop: to access each tutor
        Second loop: to access each exam of a tutor
        Third loop: to compare the tests solved and look for the ones
        that has been approved to remove them from the list to send to
        the view            

        Args:
            student_instance (Student): a student user instance
        Return:
            A list of exams to solve for the student
        '''            
        #tutor_list = student_management().find_all_tutors(student_instance.email)        
        tutor_list = student_instance.tutors    
        tutors_exam = self.list_tutors_exams(tutor_list)                
        copy_tutors_exam = self.list_tutors_exams(tutor_list)                
        student_id = student_instance.key()        
        test_list = self.find_all_tests(student_id)                    
        
        passed = False    
        data = False
        
        i=0
        while i < len(tutors_exam):                
            j=0
            while j < len(tutors_exam[i]):                    
                passed = False
                k = 0
                while k < len(test_list):                                        
                    exam = exam_management().find_exam(test_list[k].exam.key().id())                                                
                    if self.is_passed(tutors_exam[i][j],exam,test_list[k]):                
                        passed = True
                        break
                    k=k+1
                
                if passed:                    
                    copy_tutors_exam[i][j] = None
                j=j+1                
            i = i+1

          
        return copy_tutors_exam
Exemplo n.º 12
0
    def find_test_exam_available(self, student_instance):
        '''        
        Function that retrieve all the exams that hasn't been approved and
        are available for the student
        The algorithm user three nested loops
        First loop: to access each tutor
        Second loop: to access each exam of a tutor
        Third loop: to compare the tests solved and look for the ones
        that has been approved to remove them from the list to send to
        the view            

        Args:
            student_instance (Student): a student user instance
        Return:
            A list of exams to solve for the student
        '''
        #tutor_list = student_management().find_all_tutors(student_instance.email)
        tutor_list = student_instance.tutors
        tutors_exam = self.list_tutors_exams(tutor_list)
        copy_tutors_exam = self.list_tutors_exams(tutor_list)
        student_id = student_instance.key()
        test_list = self.find_all_tests(student_id)

        passed = False
        data = False

        i = 0
        while i < len(tutors_exam):
            j = 0
            while j < len(tutors_exam[i]):
                passed = False
                k = 0
                while k < len(test_list):
                    exam = exam_management().find_exam(
                        test_list[k].exam.key().id())
                    if self.is_passed(tutors_exam[i][j], exam, test_list[k]):
                        passed = True
                        break
                    k = k + 1

                if passed:
                    copy_tutors_exam[i][j] = None
                j = j + 1
            i = i + 1

        return copy_tutors_exam
Exemplo n.º 13
0
	def list_question_value(self,test_id):
		'''
		Function that retrieve all the values of the questions of the exam answered

		Args:
			test_id (Integer): represents the numeric value of a test id
		Returns:
			A list of the values of the questions of the exam
		'''
		test = test_management().find_test(test_id)		
		list_question_value = []
		exam_id = test.exam.key().id()
		exam_instance = exam_management().find_exam(exam_id)					
		for q in range(len(exam_instance.questions)):
			question = question_model().find_question(exam_instance.questions[q].id())
			list_question_value.append(question.value)
		
		return list_question_value
Exemplo n.º 14
0
	def post(self):
		user = self.get_user_type()		
		if user == user_type.visitor:
			self.response.write('0')
			self.redirect('/')
			return 0
		elif user == user_type.student:
			'''
			Retrieve the exam_id from the url and find that exam, 
			receive the start and end time of the exam, the student who 
			answered and the answers of this one.

			Save that instance and later calculate the score to get the 
			results, update the test to know if the student approved or not
			the test and show in the template the results
			'''
			exam_id = int(self.request.get('exam_id',None))
			exam_instance = exam_management().find_exam(exam_id)			
			list_answers = []			
			number_questions = len(exam_instance.questions)
			for index in range(number_questions):
				list_answers.append(int(self.request.get('r[{0}]'.format(index),0)))
			time_init = self.request.get('time_init',None)
			'''
			Cambiar por sesiones o cookies
			'''
			time_end = dt.datetime.utcnow()
			time = elapsed_time().elapsed_time(time_init,time_end)
			
			session = self.get_user_id()
			student = student_management().find_key(session)			
			test_id = test_management().add(time.time(),student.key(),exam_instance.key(),list_answers)
			test_id = int(test_id.id())
			test = test_management().find_test(test_id)
			feedback_message = test_evaluation().feedback_message(test_id)
			#self.response.write(feedback_message)			
			test_score = test_evaluation().test_score(test_id)
			#self.response.write(test_score)
			count_correct_answers = test_evaluation().count_correct_answers(test_id)
			#self.response.write(count_correct_answers)
			count_questions = test_evaluation().count_question(test_id)
			#self.response.write(count_questions)
			if feedback_message != feedback_msg.insuficient:
				test.approved = True
				test.put()
												
			template_values = {
				"user":"******",
				"feedback_message":feedback_message,
				"test_score":test_score,
				"count_correct_answers":count_correct_answers,
				"count_question":count_questions,
				"status":1
			}						
			self.response.write(template.render(template_values))
			return 1
		elif user == user_type.tutor:								
				
			'''
			This is use it to retrieve all the elements of an exam if
			exists one or show the form to create a new one

			delete and available came from a request of ajax and update 
			the exam

			otherwise it will create a new one and retrieve all the data
			from the form
			'''
			available = self.request.get('available',None)
			'''
			to be deleted
			'''
			delete = self.request.get('delete',None)
			if delete:								
				exam_id = int(self.request.get('exam_id',None))					
				exam_instance = exam_management().find_exam(exam_id)
				db.delete(exam_instance)
			if available:
				exam_id = int(self.request.get('exam_id',None))					
				exam_instance = exam_management().find_exam(exam_id)
				if exam_instance.available == True:
					exam_instance.available = False
				else:
					exam_instance.available = True
				exam_instance.put()
			else:
				'''
				This section it's for create the exam with the values that
				came from the server
				'''
				session = self.session['user-id']			
				user = tutor_management().find_key(session)						

				learning_style = self.request.get('learning_style',None)
				level = self.request.get('level',None)			
				unit = self.request.get('unit',None)
				subject = self.request.get('subject',None)
						
				number_questions = 0
				while self.request.get_all('q[{0}]'.format(number_questions),None):
					number_questions = number_questions + 1

				question = []
				question_value = []
				list_answer = []
				list_correct_answer = []						
				list_correct_answer_int = []
				list_list_correct_answer_int = []
				question_value_int = []
				list_list_str_answer = []
				list_str_question = []
				'''
				Retrieve all the inputs from the form and save it in lists
				'''
				for index in range(number_questions):				
					question.append(self.request.get('q[{0}]'.format(index),None))
					question_value.append(self.request.get('v[{0}]'.format(index),None))				
					list_answer.append(self.request.get_all('a[{0}]'.format(index),None))
					list_correct_answer.append(self.request.get_all('r[{0}]'.format(index),None))			

				for index in range(number_questions):
					sub_index = 0
					list_correct_answer_int = []
					while sub_index < len(list_correct_answer[index]):					
						list_correct_answer_int.append(int(list_correct_answer[index][sub_index]))
						sub_index = sub_index + 1
					list_list_correct_answer_int.append(list_correct_answer_int)
				
				for index in range(number_questions):
					question_value_int.append(int(question_value[index]))

				for index in range(number_questions):
					sub_index = 0
					list_str_answer = []
					while sub_index < len(list_answer[index]):
						list_str_answer.append(str(list_answer[index][sub_index]))
						sub_index = sub_index + 1
					list_list_str_answer.append(list_str_answer)

				for index in range(number_questions):							
					list_str_question.append(str(question[index]))
				self.response.write(list_list_correct_answer_int)			
				list_questions = []
				'''
				Put the list in a question model object to store in the database
				'''
				for index in range(number_questions):
					q = question_model()	
					q.text = list_str_question[index]
					q.answers = list_list_str_answer[index]
					q.correct_answers = list_list_correct_answer_int[index]
					q.value = question_value_int[index]				
					#list_questions[index]= q.put()
					list_questions.append(q.put())

				s = subject_model()
				s.name = str(subject)							
				exam_id = self.request.get('exam_id',None)
				'''
				If a exam_id it's retrieved from the url it means that this exam it's been
				modified, so it doesn't need to be created, otherwise it have to and put all
				the data need to store it in the database
				'''
				if exam_id:
					exam_id = int(exam_id)
					exam_instance = exam_management().modify(exam_id,user,int(learning_style),int(level),int(unit),s.put(),list_questions)
					self.redirect('/home')
					#self.response.write('<a href="/home">Home</a>')
					#desplegar mensaje que se ha modificado
				else:
					exam_key = exam_management().add(user,int(learning_style),int(level),int(unit),s.put(),list_questions)								
					self.redirect('/home')
					#self.response.write('<a href="/home">Home</a>')
					#desplegar mensaje que se ha creado
				#self.redirect('/home')			
			return 2
			
		else:
			self.response.write('3')
			self.redirect('/home')
			return 3
Exemplo n.º 15
0
    def get(self):
        user = self.get_user_type()
        if user == user_type.visitor:
            self.redirect('/')
            return 0
        elif user == user_type.student:
            tutor_id = self.session['user-id']
            student_instance = student_management().get_student(
                int(self.session['user-id']))
            tutor = tutor_management().get_tutor(5066549580791808)
            subject = subject_management().get_subject_by_name(
                'Programacion Orientada a Objetos')
            page = self.request.get('page', 0)
            unit_id = self.request.get('unit_id', None)
            if unit_id:
                unit_id = int(unit_id)
            else:
                ##id de 1era unidad
                unit_id = 5750892489867264
            page = self.request.get('page', 0)
            try:
                int(page)
                page = int(page) - 1
            except ValueError:
                page = 0
            if page < 1:
                page = 0
            index = 0
            unit = unit_management().get_unit(unit_id)
            list_list_text_info = []
            countent = {}
            list_counter = []
            list_content = []
            list_all_exams = exam_management().get_all_unit_available_exams(
                unit.key())
            list_em = exam_management().get_unit_available_exams(
                unit.key(), page)

            list_exams = []
            if list_em:
                #total_text = text_material_management().get_all_texts_material(tutor_key,self.list_list_tm[index][0].subject.key(),page)
                for index in range(len(list_em)):
                    em = list_em[index]
                    exam_instance = exam_management().find_exam(em.key().id())
                    einfo = {}
                    einfo['id'] = em.key().id()
                    einfo['able'] = em.available
                    einfo['tutor'] = (tutor_management().get_tutor(
                        em.user.key().id())).first
                    einfo['topic'] = em.topic
                    #einfo['content'] = exam_instance.content
                    #einfo['number_views'] = exam_instance.number_views
                    #einfo['description'] = 	exam_instance.description
                    list_exams.append(einfo)
                    index = index + 1
            html = ''
            pages = int(ceil(len(list_all_exams) / 10.))
            if pages < 1:
                pages = 1
            list_page = [None] * pages
            template_values = {
                "user": "******",
                "header_welcome": "",
                "header_tutor": "",
                "total_pages": len(list_page),
                "current_page": (page + 1),
                "list_exams": list_exams,
                "pages": list_page,
                #Agregado
                "unit_id": unit_id,
                "Titulo": "Gestion de Textos",
                "counter": list_counter,
                "html": html,
                "subject": subject.name,
                "student_name": student_instance.first
            }
            self.response.write(admin_exam_template.render(template_values))

            return 1

        elif user == user_type.tutor:
            tutor_id = self.session['user-id']
            tutor_key = tutor_management().get_tutor(tutor_id).key()
            tutor_instance = tutor_management().get_tutor(tutor_id)
            subject = subject_management().get_subject_by_name(
                'Programacion Orientada a Objetos')
            page = self.request.get('page', 0)
            try:
                int(page)
                page = int(page) - 1
            except ValueError:
                page = 0
            if page < 1:
                page = 0
            index = 0
            list_list_text_info = []
            countent = {}
            list_counter = []
            list_content = []
            listi = tutor_management().find_all_exams_subject(
                tutor_key, subject.key())
            #self.list_list_tm = text_material_management().get_list_text_material_of_subject(tutor_key,page)
            list_em = tutor_management().find_all_exams(
                tutor_key, subject.key(), page)

            c = 0
            list_exams = []
            total_em = 0
            if list_em:
                #total_text = text_material_management().get_all_texts_material(tutor_key,self.list_list_tm[index][0].subject.key(),page)
                for index in range(len(list_em)):
                    em = list_em[index]
                    exam_instance = exam_management().find_exam(em.key().id())
                    einfo = {}
                    einfo['id'] = em.key().id()
                    einfo['able'] = em.available
                    einfo['tutor'] = (tutor_management().get_tutor(
                        em.user.key().id())).first
                    einfo['topic'] = em.topic
                    '''
					einfo['content'] = exam_instance.content                    
					einfo['number_views'] = exam_instance.number_views
					einfo['description'] = 	exam_instance.description					
					'''
                    list_exams.append(einfo)
                    index = index + 1
            html = ''

            pages = int(ceil(len(listi) / 10.))
            if pages < 1:
                pages = 1
            list_page = [None] * pages
            template_values = {
                "user": "******",
                "header_welcome": "",
                "header_tutor": "",
                "total_pages": len(list_page),
                "current_page": (page + 1),
                "list_exams": list_exams,
                "subject": subject.name,
                "pages": list_page,
                "Titulo": "Gestion de Examenes",
                "counter": list_counter,
                "tutor_name": tutor_instance.first
            }

            self.response.write(admin_exam_template.render(template_values))

            return 2
        else:
            return 3
Exemplo n.º 16
0
    def post(self):
        user = self.get_user_type()
        if user == user_type.visitor:
            self.redirect('/')
            return 0
        elif user == user_type.student:
            self.redirect('/home')
            return 1

        elif user == user_type.tutor:

            id_exam = self.request.get('id_exam', None)

            list_questions_aux = []
            if (id_exam):
                id_exam = int(id_exam)
                exam = exam_management().find_exam(id_exam)
                for q in exam.questions:
                    q = exam_management().find_question(q.id())
                    list_questions_aux.append(q)

            self.response.write(len(list_questions_aux))

            tutor_id = self.session['user-id']
            tutor_key = tutor_management().get_tutor(tutor_id)

            id_unit = int(self.request.get('unit_exam', None))
            unit = unit_management().get_unit(id_unit)

            name_exam = self.request.get('name_exam', None)
            topic_exam = self.request.get('topic_exam', None)

            learning_type = int(self.request.get('learning_type', None))
            level = int(self.request.get('level', None))

            subject = subject_management().get_subject_by_name(
                'Programacion Orientada a Objetos')

            count_questions = int(self.request.get('count_questions', None))

            answers = []
            list_questions = []
            correct_answers = []
            cout_images = 0

            for i in range(count_questions):
                q = Question()
                q.text = self.request.get('Q_' + str(i + 1), None)
                q.value = int(self.request.get('PossPtsQ_' + str(i + 1), None))

                answers.append(
                    self.request.get('Q_' + str(i + 1) + '_A_' + '1', None))
                answers.append(
                    self.request.get('Q_' + str(i + 1) + '_A_' + '2', None))
                answers.append(
                    self.request.get('Q_' + str(i + 1) + '_A_' + '3', None))
                answers.append(
                    self.request.get('Q_' + str(i + 1) + '_A_' + '4', None))
                q.answers = answers

                if (self.request.get('Q_' + str(i + 1) + '_ChkBox_' + '1')):
                    correct_answers.append(1)
                if (self.request.get('Q_' + str(i + 1) + '_ChkBox_' + '2')):
                    correct_answers.append(2)
                if (self.request.get('Q_' + str(i + 1) + '_ChkBox_' + '3')):
                    correct_answers.append(3)
                if (self.request.get('Q_' + str(i + 1) + '_ChkBox_' + '4')):
                    correct_answers.append(4)
                q.correct_answers = correct_answers

                if (id_exam and i < len(list_questions_aux)):
                    q.image = list_questions_aux[i].image

                if (self.request.get('Q_I' + str(i + 1))):
                    q.image = self.get_uploads()[cout_images]
                    cout_images = cout_images + 1

                q = q.put()

                list_questions.append(q)

            if (id_exam):
                exam.delete()
            exam_management().add(name_exam, tutor_key, learning_type, level,
                                  unit, topic_exam, list_questions, subject)
            self.redirect('/admin_exam')

            return 2
        else:
            self.redirect('/')

            return 3
Exemplo n.º 17
0
	def get(self):
		user = self.get_user_type()               
		if user == user_type.visitor:                    
			self.redirect('/')
			return 0
		elif user == user_type.student:
			tutor_id = self.session['user-id']
			student_instance = student_management().get_student(int(self.session['user-id']))
			tutor = tutor_management().get_tutor(5066549580791808)
			subject = subject_management().get_subject_by_name('Programacion Orientada a Objetos')
			page = self.request.get('page',0)   
			unit_id = self.request.get('unit_id',None)
			if unit_id:
				unit_id = int(unit_id)
			else:
				##id de 1era unidad
				unit_id = 5750892489867264
			page = self.request.get('page',0)
			try:
				int(page)
				page = int(page)-1
			except ValueError:
				page = 0
			if page < 1:
				page = 0
			index = 0
			unit = unit_management().get_unit(unit_id)
			list_list_text_info = []            
			countent = {}
			list_counter = []   
			list_content = []  
			list_all_exams = exam_management().get_all_unit_available_exams(unit.key())  
			list_em = exam_management().get_unit_available_exams(unit.key(),page)
			
			list_exams = []
			if list_em:				
				#total_text = text_material_management().get_all_texts_material(tutor_key,self.list_list_tm[index][0].subject.key(),page)
				for index in range(len(list_em)):
					em = list_em[index]
					exam_instance = exam_management().find_exam(em.key().id())
					einfo = {}        
					einfo['id'] = em.key().id()          
					einfo['able'] = em.available
					einfo['tutor'] = (tutor_management().get_tutor(em.user.key().id())).first
					einfo['topic'] = em.topic                    
					#einfo['content'] = exam_instance.content                    
					#einfo['number_views'] = exam_instance.number_views
					#einfo['description'] = 	exam_instance.description					
					list_exams.append(einfo)
					index = index + 1
			html = ''
			pages = int(ceil(len(list_all_exams)/10.))
			if pages < 1:
				pages = 1
			list_page = [None] * pages              
			template_values={
				"user":"******",
				"header_welcome":"",
				"header_tutor":"",
                "total_pages":len(list_page),
                "current_page":(page+1),
				"list_exams": list_exams,                
				"pages":list_page,
				#Agregado
				"unit_id":unit_id,
				"Titulo":"Gestion de Textos",
				"counter":list_counter,
				"html":html,
				"subject":subject.name,
				"student_name": student_instance.first
			} 	
			self.response.write(admin_exam_template.render(template_values))
			
			return 1		

		elif user == user_type.tutor:
			tutor_id = self.session['user-id']
			tutor_key = tutor_management().get_tutor(tutor_id).key()
			tutor_instance = tutor_management().get_tutor(tutor_id)
			subject = subject_management().get_subject_by_name('Programacion Orientada a Objetos')
			page = self.request.get('page',0)
			try:
				int(page)
				page = int(page)-1
			except ValueError:
				page = 0
			if page < 1:
				page = 0
			index = 0
			list_list_text_info = []            
			countent = {}
			list_counter = []   
			list_content = []  
			listi = tutor_management().find_all_exams_subject(tutor_key,subject.key())      
			#self.list_list_tm = text_material_management().get_list_text_material_of_subject(tutor_key,page)
			list_em = tutor_management().find_all_exams(tutor_key,subject.key(),page)
			
			c=0                        
			list_exams = []
			total_em = 0
			if list_em:				
				#total_text = text_material_management().get_all_texts_material(tutor_key,self.list_list_tm[index][0].subject.key(),page)
				for index in range(len(list_em)):
					em = list_em[index]
					exam_instance = exam_management().find_exam(em.key().id())
					einfo = {}        
					einfo['id'] = em.key().id()          
					einfo['able'] = em.available
					einfo['tutor'] = (tutor_management().get_tutor(em.user.key().id())).first
					einfo['topic'] = em.topic                    
					'''
					einfo['content'] = exam_instance.content                    
					einfo['number_views'] = exam_instance.number_views
					einfo['description'] = 	exam_instance.description					
					'''
					list_exams.append(einfo)
					index = index + 1								
			html = ''
			
			pages = int(ceil(len(listi)/10.))
			if pages < 1:
				pages = 1
			list_page = [None] * pages              
			template_values={
				"user":"******",
				"header_welcome":"",
				"header_tutor":"",
                "total_pages":len(list_page),
                "current_page":(page+1),
				"list_exams": list_exams,
				"subject":subject.name,
				"pages":list_page,
				"Titulo":"Gestion de Examenes",                
				"counter":list_counter,
				"tutor_name": tutor_instance.first
			}  
            
			self.response.write(admin_exam_template.render(template_values))
			
			return 2                                      
		else: 
			return 3
Exemplo n.º 18
0
	def get(self):
		user = self.get_user_type()		
		if user == user_type.visitor:
			self.response.write('0')
			self.redirect('/')
			return 0
		elif user == user_type.student:
			exam_id = int(self.request.get('exam_id',None))
			exam_instance = exam_management().find_exam(exam_id)
			'''
			THIS SECTION NEEDS SOME WORK
			This section just retrieve the exam data to show
			in the view for the student to solve
			'''
			exam = {}
			question = exam_instance.questions
			list_questions = []
			exam['id'] = exam_instance.key().id()
			exam['learning_style'] = learning_type().Value_Spanish[exam_instance.learning_type]
			exam['level'] =  level_type().Value_Spanish[exam_instance.level]
			exam['unit'] = exam_instance.unit
			exam['subject'] = subject_model().find_subject(exam_instance.subject.key().id())
			for index in range(len(question)):
				list_questions.append(question_model().find_question(question[index].id()))
			exam['question'] =  list_questions                
			list = []
			var = {}			
			index=0
			while index <len(question):
				var['index'] = index
				list.append(copy.deepcopy(var))  #copy.deepcopy it's a special function, don't deleted
				index = index + 1
			template_values = {
				"user":"******",
				"exam":exam,
				"time_init":dt.datetime.utcnow(),
				"list":list,
				"status":0
			}								                  
			self.response.write(template.render(template_values))
			return 1
		elif user == user_type.tutor:			
			'''
			This section just retrieve the exam_id from the url if one exists
			and depending of it, shows the exam or the form to create a new exam
			'''
			exam_id = self.request.get('exam_id',None)
			exam = {}
			list = []
			var = {}
			if exam_id:
				exam_id = int(exam_id)
				exam_instance = exam_management().find_exam(exam_id)								
				question = exam_instance.questions
				list_questions = []
				exam['id'] = exam_instance.key().id()
				exam['learning_style'] = learning_type().Value_Spanish[exam_instance.learning_type]
				exam['level'] =  level_type().Value_Spanish[exam_instance.level]
				exam['unit'] = exam_instance.unit
				exam['subject'] = subject_model().find_subject(exam_instance.subject.key().id())
				for index in range(len(question)):
					list_questions.append(question_model().find_question(question[index].id()))
				exam['question'] =  list_questions            
				index=0
				while index <len(question):
					var['index'] = index
					list.append(copy.deepcopy(var))
					index = index + 1
			template_values = {
				"user":"******",
				"exam":exam,
				"list":list	
			}
			self.response.write(template.render(template_values))
			return 2
		else:						
			template_values = {}
			#self.response.write(template.render(template_values))
			self.redirect('/')
			return 3