diff --git a/FusionIIIT/applications/academic_information/api/urls.py b/FusionIIIT/applications/academic_information/api/urls.py index 39a89fdb3..dfda1c00d 100644 --- a/FusionIIIT/applications/academic_information/api/urls.py +++ b/FusionIIIT/applications/academic_information/api/urls.py @@ -14,7 +14,8 @@ # url(r'^meeting',views.meeting_api,name='meeting-get-api'), - # url(r'^calendar',views.calendar_api,name='calendar-get-api'), + url(r'^calendar',views.ListCalendarView.as_view(),name='calendar-get-api'), + url(r'^update-calendar',views.update_calendar,name='calendar-update-api'), # url(r'^holiday',views.holiday_api,name='holiday-get-api'), diff --git a/FusionIIIT/applications/academic_information/api/views.py b/FusionIIIT/applications/academic_information/api/views.py index bbe6aebef..4ed4d13ee 100644 --- a/FusionIIIT/applications/academic_information/api/views.py +++ b/FusionIIIT/applications/academic_information/api/views.py @@ -12,6 +12,7 @@ from applications.globals.models import User,ExtraInfo from applications.academic_information.models import Student, Course, Curriculum, Curriculum_Instructor, Student_attendance, Meeting, Calendar, Holiday, Grades, Spi, Timetable, Exam_timetable from . import serializers +from rest_framework.generics import ListCreateAPIView @api_view(['GET']) @permission_classes([IsAuthenticated]) @@ -82,7 +83,26 @@ def calendar_api(request): 'calendar' :calendar_serialized, } return Response(data=resp,status=status.HTTP_200_OK) - + +class ListCalendarView(ListCreateAPIView): + permission_classes = [IsAuthenticated] + authentication_classes=[TokenAuthentication] + serializer_class = serializers.CalendarSerializers + queryset = Calendar.objects.all() + +@api_view(['PUT']) +@permission_classes([IsAuthenticated]) +@authentication_classes([TokenAuthentication]) +def update_calendar(request): + if request.method == "PUT": + id = request.data.get("id") + instance = Calendar.objects.get(pk = id) + instance.from_date = request.data.get("from_date") + instance.to_date = request.data.get("to_date") + instance.description = request.data.get("description") + instance.save() + + return Response({"message": "Updated successfully!"}) @api_view(['GET']) @permission_classes([IsAuthenticated]) diff --git a/FusionIIIT/applications/academic_procedures/api/serializers.py b/FusionIIIT/applications/academic_procedures/api/serializers.py index ee3d46743..e210d8586 100644 --- a/FusionIIIT/applications/academic_procedures/api/serializers.py +++ b/FusionIIIT/applications/academic_procedures/api/serializers.py @@ -3,7 +3,9 @@ from applications.academic_procedures.models import (ThesisTopicProcess, InitialRegistrations,InitialRegistration, FinalRegistration, FinalRegistrations, SemesterMarks, - BranchChange , StudentRegistrationChecks, Semester, backlog_course , CourseSlot , FeePayments , Course, course_registration) + BranchChange , StudentRegistrationChecks, Semester, backlog_course , CourseSlot , FeePayments , course_registration) + +from applications.programme_curriculum.models import Course from applications.academic_information.api.serializers import (CurriculumInstructorSerializer, CurriculumSerializer , CourseSerializer , StudentSerializers ) @@ -73,7 +75,10 @@ class Meta: model = CourseSlot fields = ('__all__') + class CourseSerializer(serializers.ModelSerializer): + class Meta: model = Course - fields = ('__all__') \ No newline at end of file + fields = ['id','code','name','credit'] + \ No newline at end of file diff --git a/FusionIIIT/applications/academic_procedures/api/urls.py b/FusionIIIT/applications/academic_procedures/api/urls.py index 1f46e8d4d..786c12760 100644 --- a/FusionIIIT/applications/academic_procedures/api/urls.py +++ b/FusionIIIT/applications/academic_procedures/api/urls.py @@ -18,6 +18,7 @@ url(r'^acad/view_registrations' , views.acad_view_reigstrations , name='acad_view_registrations'), url(r'^acad/verify_registration' , views.verify_registration , name='verify_registration'), + url(r'^acad/verify_course' , views.verify_course , name='verify_course'), url(r'^acad/get_course_list' , views.get_course_list , name = 'get_course_list' ), url(r'^acad/get_all_courses' , views.get_all_courses , name = 'get_all_courses' ), url(r'^acad/gen_roll_list' , views.gen_roll_list , name = 'gen_roll_list' ), diff --git a/FusionIIIT/applications/academic_procedures/api/views.py b/FusionIIIT/applications/academic_procedures/api/views.py index 167ec6c84..bd3f2dc13 100644 --- a/FusionIIIT/applications/academic_procedures/api/views.py +++ b/FusionIIIT/applications/academic_procedures/api/views.py @@ -14,9 +14,9 @@ from applications.globals.models import HoldsDesignation, Designation, ExtraInfo from applications.programme_curriculum.models import ( CourseSlot, Course as Courses, Batch, Semester) +# from applications.programme_curriculum.models import Course - -from applications.academic_procedures.models import (Course, Student, Curriculum , ThesisTopicProcess, InitialRegistrations, +from applications.academic_procedures.models import ( Student, Curriculum , ThesisTopicProcess, InitialRegistrations, FinalRegistration, SemesterMarks,backlog_course, BranchChange , StudentRegistrationChecks, Semester , FeePayments , course_registration) @@ -33,7 +33,7 @@ get_detailed_sem_courses, InitialRegistration) -from applications.academic_procedures.views import get_sem_courses, get_student_registrtion_check, get_cpi, academics_module_notif +from applications.academic_procedures.views import get_sem_courses, get_student_registrtion_check, get_cpi, academics_module_notif, get_final_registration_choices, get_currently_registered_course, get_add_course_options, get_drop_course_options, get_replace_course_options from . import serializers @@ -129,6 +129,7 @@ def academic_procedures_student(request): currently_registered_courses = get_currently_registered_courses(user_details.id, user_sem) currently_registered_courses_data = serializers.CurriculumSerializer(currently_registered_courses, many=True).data + try: pre_registered_courses = obj.initialregistrations_set.all().filter(semester = user_sem) pre_registered_courses_show = obj.initialregistrations_set.all().filter(semester = user_sem+1) @@ -139,36 +140,7 @@ def academic_procedures_student(request): final_registered_courses = obj.finalregistrations_set.all().filter(semester = user_sem) except: final_registered_courses = None - - try: - pre_registered_courses = InitialRegistration.objects.all().filter(student_id = user_details.id,semester_id = next_sem_id) - pre_registered_course_show = {} - pre_registration_timestamp=None - for pre_registered_course in pre_registered_courses: - pre_registration_timestamp=pre_registered_course.timestamp - if(pre_registered_course.course_slot_id.name not in pre_registered_course_show): - pre_registered_course_show[pre_registered_course.course_slot_id.name] = [{"course_code":pre_registered_course.course_id.code,"course_name":pre_registered_course.course_id.name,"course_credit":pre_registered_course.course_id.credit,"priority":pre_registered_course.priority}] - else: - pre_registered_course_show[pre_registered_course.course_slot_id.name].append({"course_code":pre_registered_course.course_id.code,"course_name":pre_registered_course.course_id.name,"course_credit":pre_registered_course.course_id.credit,"priority":pre_registered_course.priority}) - pre_registration_timestamp=str(pre_registration_timestamp) - except Exception as e: - pre_registered_courses = None - pre_registered_course_show = None - - try: - final_registered_courses = FinalRegistration.objects.all().filter(student_id = user_details.id,semester_id = next_sem_id) - final_registered_course_show=[] - for final_registered_course in final_registered_courses: - final_registered_course_show.append({"course_code":final_registered_course.course_id.code,"course_name":final_registered_course.course_id.name,"course_credit":final_registered_course.course_id.credit}) - # add_courses_options = get_add_course_options(current_sem_branch_course, currently_registered_course, batch.year) - # drop_courses_options = get_drop_course_options(currently_registered_course) - # replace_courses_options = get_replace_course_options(currently_registered_course, batch.year) - except Exception as e: - final_registered_courses = None - final_registered_course_show = None - # drop_courses_options = None - add_courses_options = None - replace_courses_options = None + # pre_registered_courses_data = serializers.InitialRegistrationsSerializer(pre_registered_courses, many=True).data # pre_registered_courses_show_data = serializers.InitialRegistrationsSerializer(pre_registered_courses_show, many=True).data @@ -229,8 +201,7 @@ def academic_procedures_student(request): user_sem = get_user_semester(request.user, ug_flag, masters_flag, phd_flag) next_sem_id = curr_sem_id - student_registration_check_pre = get_student_registrtion_check(obj,next_sem_id) - student_registration_check_final = get_student_registrtion_check(obj,next_sem_id) + # student_registration_check_final = get_student_registrtion_check(obj,next_sem_id) cpi = get_cpi(user_details.id) @@ -246,21 +217,27 @@ def academic_procedures_student(request): courselist.append({'course_id': course.id, 'name': course.name, 'credit': course.credit, 'course_code': course.code}); next_sem_courses.append({'slot_id': course_slot.id,'slot_name':course_slot.name, 'slot_type': course_slot.type, 'semester': course_slot.semester.semester_no, 'slot_info': course_slot.course_slot_info, 'courses': courselist }) - print(next_sem_courses) + # print(next_sem_courses) print(current_date, user_sem, year) pre_registration_date_flag, prd_start_date= get_pre_registration_eligibility(current_date, user_sem, year) final_registration_date_flag = get_final_registration_eligibility(current_date) add_or_drop_course_date_flag = get_add_or_drop_course_date_eligibility(current_date) - student_registration_check_pre = obj.studentregistrationcheck_set.all().filter(semester=user_sem+1) - student_registration_check_final = obj.studentregistrationcheck_set.all().filter(semester=user_sem) + # student_registration_check_pre = obj.studentregistrationcheck_set.all().filter(semester=user_sem+1) + # student_registration_check_final = obj.studentregistrationcheck_set.all().filter(semester=user_sem) + + print("nextsem",next_sem_id.semester_no) + student_registration_check = get_student_registrtion_check(obj,next_sem_id.id) + print("adf",student_registration_check) + pre_registration_flag = False final_registration_flag = False - if(student_registration_check_pre): - pre_registration_flag = student_registration_check_pre.pre_registration_flag - if(student_registration_check_final): - final_registration_flag = student_registration_check_final.final_registration_flag + + if(student_registration_check): + pre_registration_flag = student_registration_check.pre_registration_flag + final_registration_flag = student_registration_check.final_registration_flag + # if(student_registration_check): teaching_credit_registration_course = None if phd_flag: @@ -268,6 +245,81 @@ def academic_procedures_student(request): teaching_credit_registration_course_data = serializers.CurriculumSerializer(teaching_credit_registration_course, many=True).data + try: + pre_registered_courses = InitialRegistration.objects.all().filter(student_id = user_details.id,semester_id = next_sem_id) + pre_registered_course_show = [] + pre_registration_timestamp=None + for pre_registered_course in pre_registered_courses: + pre_registration_timestamp=pre_registered_course.timestamp + if(pre_registered_course.course_slot_id.name not in pre_registered_course_show): + pre_registered_course_show.append({"slot_name": pre_registered_course.course_slot_id.name ,"course_code":pre_registered_course.course_id.code,"course_name":pre_registered_course.course_id.name,"course_credit":pre_registered_course.course_id.credit,"priority":pre_registered_course.priority}) + else: + pre_registered_course_show[pre_registered_course.course_slot_id.name].append({"course_code":pre_registered_course.course_id.code,"course_name":pre_registered_course.course_id.name,"course_credit":pre_registered_course.course_id.credit,"priority":pre_registered_course.priority}) + pre_registration_timestamp=str(pre_registration_timestamp) + except Exception as e: + pre_registered_courses = None + pre_registered_course_show = None + + next_sem_branch_course = get_sem_courses(next_sem_id, batch) + current_sem_branch_course = get_sem_courses(curr_sem_id, batch) + next_sem_registration_courses = get_sem_courses(next_sem_id, batch) + final_registration_choice, unavailable_courses_nextsem = get_final_registration_choices(next_sem_registration_courses,batch.year) + currently_registered_course = get_currently_registered_course(obj,next_sem_id) + + # currently_registered_course_show = [] + # for registered_course in currently_registered_course: + # currently_registered_course_show.append({"course_code":registered_course[1].code,"course_name":registered_course[1].name,"course_credit":registered_course[1].credit}) + + try: + final_registered_courses = FinalRegistration.objects.all().filter(student_id = user_details.id,semester_id = next_sem_id) + final_registered_course_show=[] + for final_registered_course in final_registered_courses: + final_registered_course_show.append({"course_code":final_registered_course.course_id.code,"course_name":final_registered_course.course_id.name,"course_credit":final_registered_course.course_id.credit}) + + + except Exception as e: + final_registered_courses = None + final_registered_course_show = None + + drop_courses_options = None + add_courses_options = None + replace_courses_options = None + + add_courses_options = get_add_course_options(current_sem_branch_course, currently_registered_course, batch.year) + + add_courses_options_show = [] + for course_option in add_courses_options: + course_slot = course_option[0] + courses = course_option[1] + courselist = [] + for course in courses: + courselist.append({'course_id': course.id, 'name': course.name, 'credit': course.credit, 'course_code': course.code}); + add_courses_options_show.append({'slot_id': course_slot.id,'slot_name':course_slot.name, 'slot_type': course_slot.type, 'semester': course_slot.semester.semester_no, 'slot_info': course_slot.course_slot_info, 'courses': courselist }) + + + drop_courses_options = get_drop_course_options(currently_registered_course) + drop_courses_options_show = [] + + for course in drop_courses_options: + drop_courses_options_show.append({'course_id': course.id, 'name': course.name, 'credit': course.credit, 'course_code': course.code}) + + replace_courses_options = get_replace_course_options(currently_registered_course, batch.year) + print("replace",replace_courses_options) + + backlogCourseList = [] + auto_backlog_courses = list(SemesterMarks.objects.filter(student_id = obj , grade = 'F')) + auto_backlog_courses_list = [] + for i in auto_backlog_courses: + if not i.curr_id.courseslots.filter(type__contains="Optional").exists(): + auto_backlog_courses_list.append({'course_name':i.curr_id.name, 'course_code': i.curr_id.code, 'course_version': i.curr_id.version, 'course_credit': i.curr_id.credit ,'course_grade': i.grade}) + + backlogCourses = backlog_course.objects.select_related('course_id' , 'student_id' , 'semester_id' ).filter(student_id=obj) + for i in backlogCourses: + summer_course = "Yes" if i.is_summer_course else "No" + course_details = i.course_id.course_details if i.course_id.course_details else "N/A" + + backlogCourseList.append([i.course_id.course_name, course_details , i.semester_id.semester_no , summer_course]) + registers = obj.register_set.all() course_list = [] for i in registers: @@ -298,10 +350,11 @@ def academic_procedures_student(request): resp = { 'details': details, - 'currently_registered': currently_registered_courses_data, - 'pre_registered_courses' : pre_registered_courses, + 'user_sem' : user_sem, + # 'currently_registered_course': currently_registered_course, + # 'pre_registered_courses' : pre_registered_courses, 'pre_registered_courses_show' : pre_registered_course_show, - 'final_registered_course' : final_registered_courses, + # 'final_registered_courses' : final_registered_courses, 'final_registered_course_show' : final_registered_course_show, 'current_credits' : current_credits, 'courses_list': next_sem_branch_courses_data, @@ -309,9 +362,8 @@ def academic_procedures_student(request): 'next_sem_registration_courses': next_sem_courses, 'next_sem_branch_registration_courses' : next_sem_branch_registration_courses_data, 'final_registration_choices' : final_registration_choices_data, - 'final_registration_flag': final_registration_flag, - - + 'backlogCourseList': auto_backlog_courses_list, + 'student_flag' : student_flag, 'ug_flag' : ug_flag, 'masters_flag' : masters_flag, @@ -324,12 +376,15 @@ def academic_procedures_student(request): 'frd': final_registration_date_flag, 'adc_date_flag': add_or_drop_course_date_flag, - 'drop_courses_options' : currently_registered_courses_data, + 'add_courses_options': add_courses_options_show, + 'drop_courses_options' : drop_courses_options_show, + # 'replace_courses_options' : replace_courses_options, + 'pre_registration_date_flag': pre_registration_date_flag, 'final_registration_date_flag': final_registration_date_flag, 'add_or_drop_course_date_flag': add_or_drop_course_date_flag, - 'pre_registration_flag' : pre_registration_flag, 'final_registration_flag': final_registration_flag, + 'pre_registration_flag': pre_registration_flag, 'teaching_credit_registration_course' : teaching_credit_registration_course_data, 'attendance': attendance_data, @@ -340,8 +395,9 @@ def academic_procedures_student(request): @api_view(['GET']) def get_all_courses(request): try: - obj = Course.objects.all() + obj = Courses.objects.all() serializer = serializers.CourseSerializer(obj, many=True).data + return Response(serializer, status=status.HTTP_200_OK) except Exception as e: return Response(data = str(e) , status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -393,6 +449,7 @@ def add_course(request): print(courseslot_id_instance.max_registration_limit) if course_registration.objects.filter(working_year = current_user.batch_id.year, course_id = course_id_instance).count() < courseslot_id_instance.max_registration_limit and (course_registration.objects.filter(course_id=course_id_instance, student_id=current_user).count() == 0): + print("space left = True") p = course_registration( course_id=course_id_instance, student_id=current_user, @@ -414,6 +471,7 @@ def add_course(request): res = {'message' : 'Courses successfully added' , "courses_added" : course_registration_data } return Response(data = res , status = status.HTTP_200_OK) except Exception as e: + print(e) return Response(data = str(e) , status= status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -608,8 +666,6 @@ def final_registration(request): obj.save() try: - semester = Semester.objects.get(id = request.data.get('semester')) - student = StudentRegistrationChecks.objects.filter(student_id = current_user, semester_id = semester).update(final_registration_flag = True) return JsonResponse({'message': 'Final Registration Successfull'}) except Exception as e: return JsonResponse({'message': 'Final Registration Failed '}, status=500) @@ -667,7 +723,7 @@ def student_final_registration(request): ) obj.save() try: - registration_status = StudentRegistrationChecks.objects.filter(student_id = current_user["id"], semester_id = sem_id).update(final_registration_flag = True) + registration_status = StudentRegistrationChecks.objects.filter(student_id = current_user_instance, semester_id = sem_id).update(final_registration_flag = True) return Response(data = {"message" : "Final Registration Successfull" } , status= status.HTTP_200_OK) except Exception as e: return Response(data = {"message" : "Final Registration Failed " , "error" : str(e)} , status = status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -814,7 +870,7 @@ def add_course_to_slot(request): return JsonResponse({'message': f'Course {course_code} added to slot {course_slot_name} successfully.'}, status=200) except CourseSlot.DoesNotExist: return JsonResponse({'error': 'Course slot does not exist.'}, status=400) - except Course.DoesNotExist: + except Courses.DoesNotExist: return JsonResponse({'error': 'Course does not exist.'}, status=400) # with this api request acad person can remove any course from a specific slot @@ -839,6 +895,8 @@ def remove_course_from_slot(request): # with this api faculty can know what are the courses assigned to him @api_view(['GET']) def faculty_assigned_courses(request): + + try: current_user = request.user curriculum_ids = Curriculum_Instructor.objects.filter(instructor_id=current_user.id).values_list('curriculum_id', flat=True) @@ -979,7 +1037,91 @@ def verify_registration(request): return JsonResponse({'status': 'error', 'message': 'Error in processing'}) - +@api_view(['POST']) +def verify_course(request): + current_user = get_object_or_404(User, username=request.user.username) + user_details = ExtraInfo.objects.all().select_related( + 'user', 'department').filter(user=current_user).first() + desig_id = Designation.objects.all().filter(name='adminstrator').first() + temp = HoldsDesignation.objects.all().select_related().filter( + designation=desig_id).first() + # acadadmin = temp.working + k = str(user_details).split() + final_user = k[2] + + # if (str(acadadmin) != str(final_user)): + # return Response() + + roll_no = request.data["rollno"] + obj = ExtraInfo.objects.all().select_related( + 'user', 'department').filter(id=roll_no).first() + firstname = obj.user.first_name + lastname = obj.user.last_name + dict2 = {'roll_no': roll_no, + 'firstname': firstname, 'lastname': lastname} + obj2 = Student.objects.all().select_related( + 'id', 'id__user', 'id__department').filter(id=roll_no).first() + + batch = obj2.batch_id + curr_id = batch.curriculum + curr_sem_id = Semester.objects.get(curriculum = curr_id, semester_no = obj2.curr_semester_no) + # curr_sem_id = obj2.curr_semester_no + details = [] + + current_sem_courses = get_currently_registered_course( + roll_no, curr_sem_id) + + idd = obj2 + for z in current_sem_courses: + z = z[1] + print(z) + course_code = z.code + course_name = z.name + # course_code, course_name = str(z).split(" - ") + k = {} + # reg_ig has course registration id appended with the the roll number + # so that when we have removed the registration we can be redirected to this view + k['reg_id'] = roll_no+" - "+course_code + k['rid'] = roll_no+" - "+course_code + # Name ID Confusion here , be carefull + courseobj2 = Courses.objects.all().filter(code=course_code) + # if(str(z.student_id) == str(idd)): + for p in courseobj2: + k['course_id'] = course_code + k['course_name'] = course_name + k['sem'] = curr_sem_id.semester_no + k['credits'] = p.credit + details.append(k) + + year = demo_date.year + month = demo_date.month + yearr = str(year) + "-" + str(year+1) + semflag = 0 + if(month >= 7): + semflag = 1 + else: + semflag = 2 + # TO DO Bdes + date = {'year': yearr, 'semflag': semflag} + course_list = Courses.objects.all() + semester_list = Semester.objects.all() + semester_no_list=[] + for i in semester_list: + semester_no_list.append(int(i.semester_no)) + # return JsonResponse( + # {'details': details, + # # 'dict2': dict2, + # 'course_list': serializers.CourseSerializer(course_list, many=True).data, + # # 'semester_list': semester_list, + # 'date': date} + # ) + + return JsonResponse({ + 'details': details, + 'course_list': serializers.CourseSerializer(course_list, many=True).data, + 'semester_list': serializers.SemesterSerializer(semester_list, many=True).data, + 'date': date + }) # These apis were implemented before but now don't use them they have some errors diff --git a/FusionIIIT/applications/academic_procedures/models.py b/FusionIIIT/applications/academic_procedures/models.py index 6a3d5dcc7..2015a1ee8 100644 --- a/FusionIIIT/applications/academic_procedures/models.py +++ b/FusionIIIT/applications/academic_procedures/models.py @@ -686,7 +686,7 @@ class course_registration(models.Model): # grade = models.CharField(max_length=10) #course_registration_year = models.IntegerField() def __str__(self): - return self.semester_id + return str(self.semester_id.semester_no) class Meta: db_table = 'course_registration'