def home_teacher(request): content = [' '] # convert_lst_to_dict() st = count_number_os_students() #print('#' * 40) json_st = [] for el in st: json_st.append(el.number) json_st.append(el.first_name + " " + el.second_name) json_st.append(el.latitude) json_st.append(el.longitude) teacher_id = get_teachers_id(str(request.user)) all_groups = groups(teacher_id) st_groups = get_student_groups() for group in st_groups: #print(group) all_groups.append(group) all_subjects = subjects_many(group_ids(teacher_id)) all_groups = list(dict.fromkeys(all_groups)) all_subjects = list(dict.fromkeys(all_subjects)) return render(request, 'home_teacher.html', dict(content=[len(st), ], students=st, json_st=json.dumps(json_st), groups=all_groups, subjects=all_subjects, state=[2]))
def home(request): # var place student_id = get_students_id(str(request.user)) teacher_id = get_teachers_id(str(request.user)) student_or_teacher = 0 if student_id == 0: student_or_teacher = 1 test_date = datetime.now() date_plus20 = test_date date_original = test_date semester = -1 subject = "" _groups = "" _groups, date_original, date_plus20 = get_latest_teachers_date(_groups, date_original, date_plus20) if student_or_teacher == 1: st = count_number_os_students() json_st = [] for el in st: json_st.append(el.number) json_st.append(el.first_name + " " + el.second_name) json_st.append(el.latitude) json_st.append(el.longitude) teacher_id = get_teachers_id(str(request.user)) all_groups = groups(teacher_id) st_groups = get_student_groups() for group in st_groups: ##print(group) all_groups.append(group) all_subjects = subjects_many(group_ids(teacher_id)) all_groups = list(dict.fromkeys(all_groups)) all_subjects = list(dict.fromkeys(all_subjects)) # ##print('-'*400) return render(request, 'home_teacher.html', dict(content=[len(st), ], students=st, json_st=json.dumps(json_st), groups=all_groups, subjects=all_subjects, state=[2])) present = datetime.now() if (present > date_plus20) or if_student_on_the_lecture(student_id, date_original, date_plus20) or test_date + timedelta( minutes=20) == date_plus20 or students_group(str(request.user)) not in _groups: return render(request, 'home.html') return render(request, 'home_student_location.html')
def index(request): """ Функция отображения для домашней страницы сайта. """ teacher_id = get_teachers_id(str(request.user)) all_groups = groups(teacher_id) st_groups = get_student_groups() for group in st_groups: all_groups.append(group) all_subjects = subjects_many(group_ids(teacher_id)) #print("-" * 40) #print(all_subjects) #print("-" * 40) all_groups = list(dict.fromkeys(all_groups)) all_subjects = list(dict.fromkeys(all_subjects)) return render(request, 'add_group.html', dict(groups=all_groups, subjects=all_subjects))
def show_table(request): """ :param request: user -> teachers_id subject -> subject semester -> semester list: groups -> groups :return: html render TODO: --- For Teacher --- general_table: cols : [number, first name, second name, group, date1, ... , dateN] rows : [1, Misha, Vernik, KV-71, -, +, + , + .... , - ] [2, Sasha, Murin, Kv-73, -, +, - , - .... , - ] [3, Alex, Rqet, KV-72, -, +, - , + .... , - ] [4, Sonya, Upaq, KV-74, -, -, + , + .... , - ] 1. Write ajax-script to send POST request to the /show_table/ - subject - semester - groups[] - user 2. Retrieve these data on the server side 3. Get teacher_id 4. Get all teachers dates (lecture dates) 5. Get all students that connected to the groups that has teacher 6. Iterate through lecture_dates 7. Get all students that visited this lecture 8. Mark them in the general table 9. Send general table to the HTML 10. Parse this table in the HTML page code 11. Put this table in the .CSV file --- For Student --- 1. 2 drop dowm lists - semester - subject 2. Button "Show attendance" :returns - table cols: [(date1, +) , (date2, -), ... , (dateN, +)] """ # p.2 # #print('#'*40) # #print(request.user) semester = str(request.POST.get('semester')).split() subject = str(request.POST.get('subject')) lst_tmp = request.POST.getlist('groups[]') # #print(subject) lst_groups = ','.join(lst_tmp) # #print(lst_groups) # p.3 teacher_id = get_teachers_id(str(request.user)) # p.4 from Attendance.get.all_teachers import all_dates_t all_teacher_dates = all_dates_t(teacher_id=teacher_id, subject=subject, semester=semester, groups=lst_groups) # #print('all_teacher_dates : ', all_teacher_dates) # p.5 from Attendance.get.all_students import all_students_s all_students = all_students_s(groups=lst_groups) # #print('all_students : ', all_students) general_table = [] students_table = {} cols = ['Name', 'Group'] # puts all students - that connected to the lst_groups in the students_table for student in all_students: students_table[str(student[1]) + " " + str(student[2])] = [student[3]] current = 1 for lecture in all_teacher_dates: if intersection_between_2_groups_bool(group1=lecture[1], group2=lst_groups): # adds new date to the 'cols' #print('cols:', cols) current_students_on_lecture = students_on_lecture(lecture[0], lecture[1]) groups_2 = intersection_between_2_groups_array(lecture[1], lst_groups) is_changed = False for student in current_students_on_lecture: if groups_2.get(student.group, None) == 1: if len(students_table.get(student.first_name + " " + student.second_name, None)) > 0: students_table[student.first_name + " " + student.second_name].append('+') if not is_changed: is_changed = True current += 1 cols.append(lecture[0]) for student, arr in students_table.items(): if len(arr) != current: arr.append('-') all_groups = groups(teacher_id) # st_groups = get_student_groups() #print('#printing table...') # import csv # response = HttpResponse(content_type='text/csv') # response['Content-Disposition'] = 'attachment; filename="attendance.csv"' # # #with open('innovators.csv', 'w', newline='') as file: # writer = csv.writer(response, delimiter=',') # writer.writerow(cols) # for student, attendance in students_table.items(): # #print(student, attendance) # tmp = attendance # tmp.insert(0, student) # writer.writerow(tmp) # return response all_subjects = subjects_many(group_ids(teacher_id)) return render(request, 'home_teacher.html', dict(students=[], groups=all_groups, subject=all_subjects, cols=cols, rows=students_table, state=[0, 1]))