def post(self, request, *args, **kwargs): teacher_manage_module_form = self.form_class(request.POST, request.FILES) cid = self.kwargs['class_id'] classid = int(decryptData(cid)) if teacher_manage_module_form.is_valid(): student_list_file = request.FILES["student_list_file_upload"] if student_list_file is None: raise ValueError("No Upload for Student List File") student_list_file_lines = student_list_file.read().splitlines() try: with transaction.atomic(): ClassStudentAttends.objects.filter( classid_id=classid).delete() for student in student_list_file_lines: row = ClassStudentAttends(classid_id=classid, student_email=student) row.save() except ValueError as err: raise err return HttpResponseRedirect("../teachermanagemodule/") else: raise ValueError(teacher_manage_module_form.errors)
def get(self, request, *args, **kwargs): test_id = self.kwargs['test_id'] tid = int(decryptData(test_id)) test = TestForClass.objects.get(tid=tid) full_name = User.objects.get(email=request.user.email).full_name data_tables = QuestionDataUsedByTest.objects.filter(tid_id=tid) data_table_names = [] for table in data_tables: data_table_names.append({ 'name': table.data_tbl_name, 'visibility': table.student_visibility }) form = EditTestForm(instance=test, dynamic_field_names=data_table_names) test.tid = test_id return render( request, self.template_name, { 'form': form, 'test': test, 'full_name': full_name, 'data_tables': data_tables })
def get(self, request, *args, **kwargs): full_name = User.objects.get(email=request.user.email).full_name cid = self.kwargs['class_id'] classid = int(decryptData(cid)) module_name = Class.objects.get(classid=classid).class_name student_list = ClassStudentAttends.objects.filter( classid_id=classid).values('student_email') student_email_signedup = [] student_email_notsignedup = [] student_name_signedup = [] student_name_notsignedup = [] for studentobj in student_list: email = str(studentobj['student_email']) stu_exist = User.objects.filter(email=email).count() == 1 if stu_exist: student_email_signedup.append(email) student_name_signedup.append( User.objects.get(email=email).full_name.upper) else: student_email_notsignedup.append(email) student_name_notsignedup.append('') student_signedup = zip(student_email_signedup, student_name_signedup) student_notsignedup = zip(student_email_notsignedup, student_name_notsignedup) return self.render_to_response( self.get_context_data(full_name=full_name, module_name=module_name, student_signedup=student_signedup, student_notsignedup=student_notsignedup))
def get(self, request, *args, **kwargs): cid = self.kwargs['class_id'] classid = int(decryptData(cid)) module_name = Class.objects.get(classid=classid).class_name create_module_form = InstructorTestForm tests = TestForClass.objects.filter( classid_id=classid).order_by('test_name') student_list = ClassStudentAttends.objects.filter( classid_id=classid).values('student_email') attempts = [] can_take_test = [] number_of_students = len(student_list) number_of_students_attempted = [] for tobj in tests: curr_attempt = StudentAttemptsTest.objects.filter( tid_id=tobj.tid, student_email_id=request.user.email).count() attempts.append(curr_attempt) current_time = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') end_time = datetime.datetime.strftime(tobj.end_time, '%Y-%m-%d %H:%M:%S') if curr_attempt < tobj.max_attempt and current_time <= end_time: can_take_test.append(True) else: can_take_test.append(False) student_attempt_count = 0 for student in student_list: email = student['student_email'] curr_student_attempt = StudentAttemptsTest.objects.filter( tid_id=tobj.tid, student_email_id=email).count() if curr_student_attempt > 0: student_attempt_count += 1 number_of_students_attempted.append( str(student_attempt_count) + ' / ' + str(number_of_students)) tobj.tid = encryptData(tobj.tid) user_role = UserRole.objects.get(email_id=request.user.email).role full_name = User.objects.get(email=request.user.email).full_name test_list = zip(tests, can_take_test, number_of_students_attempted, attempts) return self.render_to_response( self.get_context_data( full_name=full_name, user_role=user_role, classid=cid, test_list=test_list, module_name=module_name, create_module_form=create_module_form, ))
def post(self, request, *args, **kwargs): create_test_form = self.form_class(request.POST, request.FILES) create_test_form.clean() cid = self.kwargs['class_id'] classid = int(decryptData(cid)) if create_test_form.is_valid(): start_time = request.POST['start_time'] end_time = request.POST['end_time'] max_attempt = request.POST['max_attempt'] test_name = request.POST['test_name'] q_a_file = request.FILES['q_a_file_upload'] data_file = request.FILES['data_file_upload'] if q_a_file is None or data_file is None: raise ValueError("No Upload for Q&A file or Data Files") q_a_file_lines = q_a_file.read().splitlines() data_file_lines = data_file.read().splitlines() try: connection = get_db_connection() with transaction.atomic(): test_for_class_row = TestForClass(classid_id=classid, max_attempt=max_attempt, test_name=test_name, start_time=start_time, end_time=end_time) test_for_class_row.save() tid = test_for_class_row.tid validate_q_a_file(q_a_file.name, q_a_file_lines) cursor = connection.cursor() processed_data_file_lines = append_to_relations( tid, data_file_lines) run_sql(cursor, processed_data_file_lines) create_test_name_table( cursor, test_name_table_format(tid, test_name), q_a_file_lines) connection.commit() data_tbl_name_list = get_tbl_names(data_file_lines) for name in data_tbl_name_list: question_data_used_by_test_row = QuestionDataUsedByTest( tid_id=tid, data_tbl_name=name) question_data_used_by_test_row.save() except ValueError as err: raise err finally: connection.close() return HttpResponseRedirect("../test") else: raise ValueError(create_test_form.errors)
def get(self, request, *args, **kwargs): cid = self.kwargs['class_id'] class_id = int(decryptData(cid)) module = Class.objects.get(classid=class_id) form = EditModuleForm(instance=module) full_name = User.objects.get(email=request.user.email).full_name return render(request, self.template_name, {'form': form, 'module': module, 'full_name': full_name})
def get(self, request, *args, **kwargs): tid = self.kwargs['test_id'] testid = int(decryptData(tid)) test_attempt_list = list( reversed( StudentAttemptsTest.objects.filter( tid_id=testid, student_email_id=request.user.email))) test_name = TestForClass.objects.get(tid=testid).test_name user_role = UserRole.objects.get(email_id=request.user.email).role full_name = User.objects.get(email=request.user.email).full_name marks = [] is_full_marks = [] table_name = [] for tobj in test_attempt_list: with connection.cursor() as cursor: # Get table name student_test_name = student_attempt_table_format( testid, request.user.email, tobj.attempt_no) instructor_test_name = test_name_table_format( testid, test_name) # Get total marks from instructor table cursor.execute('SELECT SUM(marks) FROM ' + instructor_test_name) total_marks = cursor.fetchone()[0] # Get total marks from student table cursor.execute('SELECT SUM(marks) FROM ' + student_test_name) student_marks = cursor.fetchone()[0] marks.append(str(student_marks) + ' / ' + str(total_marks)) curr_name = encryptUrl( str(instructor_test_name + '-' + student_test_name)) table_name.append(curr_name) if student_marks == total_marks: is_full_marks.append(True) else: is_full_marks.append(False) tobj.tid_id = encryptData(tobj.tid_id) test_attempt_list = zip(test_attempt_list, marks, is_full_marks, table_name) return self.render_to_response( self.get_context_data(full_name=full_name, user_role=user_role, testid=tid, test_name=test_name, test_attempt_list=test_attempt_list))
def post(self, request, *args, **kwargs): test_id = self.kwargs['test_id'] tid = int(decryptData(test_id)) class_id = encryptData(TestForClass.objects.get(tid=tid).classid_id) start_time = request.POST['start_time'] end_time = request.POST['end_time'] max_attempt = request.POST['max_attempt'] data_tables = QuestionDataUsedByTest.objects.filter(tid_id=tid) current_time = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') if end_time > current_time and start_time < end_time: try: connection = get_db_connection() with transaction.atomic(): test = TestForClass.objects.get(tid=tid) queryset_test = TestForClass.objects.filter(tid=tid) fields = ['start_time', 'end_time', 'max_attempt'] updatedValues = [start_time, end_time, max_attempt] for field, updatedValue in zip(fields, updatedValues): if getattr(test, field) != updatedValue: queryset_test.update(**{field: updatedValue}) for table in data_tables: result = request.POST.getlist(table.data_tbl_name) with transaction.atomic(): is_visible = False result = ''.join(result) if result == 'on': is_visible = True QuestionDataUsedByTest.objects.filter( tid_id=tid, data_tbl_name=table.data_tbl_name).update( student_visibility=is_visible) connection.commit() except ValueError as err: connection.close() raise err return HttpResponseRedirect("../../" + str(class_id) + "/test") else: raise ValueError( 'Date cannot be in the past or start date cannot be before end date.' )
def execute_query(request, *args, **kwargs): if request.method == 'GET': query = request.GET.get('query') test_id = kwargs['test_id'] tid = int(decryptData(test_id)) fq = grader.format_select_query(tid, query) result = grader.execute_formatted_query(fq) data = {"result": result} return HttpResponse(json.dumps(data), content_type="application/json") else: return HttpResponse(json.dumps( {"nothing to see": "this isn't happening"}), content_type="application/json")
def get(self, request, *args, **kwargs): cid = self.kwargs['class_id'] class_id = int(decryptData(cid)) try: connection = get_db_connection() with transaction.atomic(): module = Class.objects.get(classid=class_id) module.delete() connection.commit() except ValueError as err: connection.close() raise err return HttpResponseRedirect("../../module")
def get(self, request, *args, **kwargs): test_id = self.kwargs['test_id'] tid = int(decryptData(test_id)) class_id = encryptData(TestForClass.objects.get(tid=tid).classid_id) try: connection = get_db_connection() with transaction.atomic(): test = TestForClass.objects.get(tid=tid) test.delete() connection.commit() except ValueError as err: connection.close() raise err return HttpResponseRedirect("../../" + str(class_id) + "/test")
def get(self, request, *args, **kwargs): test_id = self.kwargs['test_id'] tid = int(decryptData(test_id)) take_test_form = TakeTestForm test_name = TestForClass.objects.get(tid=tid).test_name test_name_table = test_name_table_format(tid, test_name) qst_data = QuestionAnswer.objects.raw('SELECT * FROM ' + test_name_table) # Retrieve all tables used by current test table_names = QuestionDataUsedByTest.objects.filter( tid_id=tid, student_visibility='t') tables = [] for table in table_names: with connection.cursor() as cursor: # Get table name table_name = 'tid' + str(tid) + '_' + table.data_tbl_name # Retrieve column names cursor.execute( 'SELECT column_name FROM information_schema.columns WHERE table_name=\'' + table_name + '\'') curr_table_columns = [ tuple(i[0] for i in it.chain(cursor.fetchall())) ] # Retrieve current table data cursor.execute('SELECT * FROM ' + table_name + ' LIMIT 5') curr_table_rows = cursor.fetchall() # Remove tid from table name table_name = table_name.split("_", 1)[1] name = [table_name] tables.append(curr_table_columns + curr_table_rows + name) return self.render_to_response( self.get_context_data( tables=tables, take_test_form=take_test_form, test_name=test_name, qst_data=qst_data, test_id=test_id, ))
def post(self, request, *args, **kwargs): submit_answer_form = self.form_class(request.POST) test_id = self.kwargs['test_id'] tid = int(decryptData(test_id)) class_id = encryptData(TestForClass.objects.get(tid=tid).classid_id) if submit_answer_form.is_valid(): student_answer_list = request.POST.getlist('student_answer') student_email = request.user.email attempt_no = StudentAttemptsTest.objects.filter( tid_id=tid, student_email_id=student_email).count() + 1 try: connection = get_db_connection() with transaction.atomic(): row, created = StudentAttemptsTest.objects.get_or_create( attempt_no=attempt_no, student_email_id=student_email, tid_id=tid) cursor = connection.cursor() create_student_attempt_table( cursor, student_attempt_table_format(tid, student_email, attempt_no), tid, student_answer_list) connection.commit() except ValueError as err: raise err finally: connection.close() return HttpResponseRedirect("../../" + str(class_id) + "/test") else: raise ValueError(submit_answer_form.errors)
def get(self, request, *args, **kwargs): tid = self.kwargs['test_id'] testid = int(decryptData(tid)) test_name = TestForClass.objects.get(tid=testid).test_name max_attempt = TestForClass.objects.get(tid=testid).max_attempt classid = TestForClass.objects.get(tid=testid).classid_id curr_full_name = User.objects.get(email=request.user.email).full_name teacher_list = ClassTeacherTeaches.objects.filter( classid_id=classid).values('teacher_email_id') student_list = ClassStudentAttends.objects.filter( classid_id=classid).values('student_email') user_name = [] highest_marks = [] is_highest_marks_full = [] number_of_attempts = [] attempt_list = [] email_list = [] for teacher in teacher_list: email_list.append(teacher['teacher_email_id']) for student in student_list: email_list.append(student['student_email']) user_id = list(range(0, len(email_list))) try: with connection.cursor() as cursor: instructor_test_name = test_name_table_format( testid, test_name) cursor.execute('SELECT SUM(marks) FROM ' + instructor_test_name) total_marks = cursor.fetchone()[0] for email in email_list: user_exist = User.objects.filter(email=email).count() == 1 if user_exist: user_name.append( User.objects.get(email=email).full_name.upper) test_attempt_list = list( reversed( StudentAttemptsTest.objects.filter( tid_id=testid, student_email_id=email))) curr_number_of_attempts = len(test_attempt_list) curr_highest_mark = 0 marks = [] is_full_marks = [] table_name = [] for tobj in test_attempt_list: student_test_name = student_attempt_table_format( testid, email, tobj.attempt_no) cursor.execute('SELECT SUM(marks) FROM ' + student_test_name) student_marks = cursor.fetchone()[0] marks.append( str(student_marks) + ' / ' + str(total_marks)) if student_marks == total_marks: is_full_marks.append(True) else: is_full_marks.append(False) # Check for highest mark for current student if student_marks > curr_highest_mark: curr_highest_mark = student_marks curr_name = encryptUrl( str(instructor_test_name + '-' + student_test_name)) table_name.append(curr_name) tobj.tid_id = encryptData(tobj.tid_id) if curr_highest_mark == total_marks: is_highest_marks_full.append(True) else: is_highest_marks_full.append(False) highest_marks.append(str(curr_highest_mark)) number_of_attempts.append( str(curr_number_of_attempts) + ' / ' + str(max_attempt)) test_attempt_list = zip(test_attempt_list, marks, table_name, is_full_marks) attempt_list.append(test_attempt_list) except ValueError as err: raise err finally: connection.close() user_list = zip(user_id, user_name, attempt_list, highest_marks, is_highest_marks_full, number_of_attempts) return self.render_to_response( self.get_context_data(testid=tid, test_name=test_name, full_name=curr_full_name, user_list=user_list, total_marks=total_marks))